API Reference¶
cinterop ¶
c-interop package.
cinterop - helpers for Python-C interop via CFFI
Modules:
-
cffi–Init module. Mostly a legacy from python 2, may be used to expose an API in the future.
-
timeseries–Python representations of multidimensional time series and interop with Python cffi.
cffi ¶
Init module. Mostly a legacy from python 2, may be used to expose an API in the future.
Modules:
-
marshal–Module to marshal data between Python and C via cffi, with a focus on time series data. This includes functions to convert between native C structs and Python representations, as well as utilities to create and manipulate C arrays from Python data structures.
marshal ¶
Module to marshal data between Python and C via cffi, with a focus on time series data. This includes functions to convert between native C structs and Python representations, as well as utilities to create and manipulate C arrays from Python data structures.
Classes:
-
CffiMarshal–A helper class for marshalling data to/from a native library module (i.e. DLL).
-
TimeSeriesGeometry–Simplified representation of the temporal geometry of a time series.
-
TimeSeriesGeometryNative–Wrapper around a cdata pointer to a new C struct
regular_time_series_geometry.
Functions:
-
as_arrayof_bytes–Convert a list of "strings" to a char** like C array.
-
as_bytes–Convert obj to bytes, if it is a type of string.
-
as_c_double_array–Convert a list or array of numeric values to a cffi pointer to a C array of double precision floats.
-
as_character_vector–Convert a list of "strings" to a character_vector* native struct.
-
as_charptr–Convert an object to
bytes, create as C array of char and copy values to it. Equivalent tochar arg[] = "world"if x is the bytes b"world". -
as_native_time_series–Convert a pure python time series to a native representation via a C struct
multi_regular_time_series_data. -
as_native_tsgeom–Convert a simlified time series geometry to a native representation.
-
as_np_array_double–Convert if possible a cffi pointer to a C data array, into a numpy array of double precision floats
double[n]. -
as_numeric_np_array–Convert if possible a cffi pointer to a C data array, into a numpy array.
-
as_string–Convert obj to string/unicode if it is a bytes object.
-
as_xarray_time_series–Converts a native time series structure to an xarray representation.
-
c_charptrptr_as_string_list–Convert if possible a cffi pointer to a C data array char** , into a list of python strings.
-
c_string_as_py_string–Convert if possible a cffi pointer to an ANSI C string
to a python string. -
convert_strings–Returns a wrapper that converts any str/unicode object arguments to bytes.
-
create_values_struct–Convert a list or array of numeric values to a cffi pointer to a
values_vectorstruct. -
datetime_to_dtts–Convert a python datetime to a cffi pointer to a C struct
date_time_to_second. -
dict_to_named_values–Convert a dictionary to a cffi pointer to a
named_values_vectorstruct. -
dict_to_string_map–Convert a dictionary to a cffi pointer to a
string_string_mapstruct. -
dtts_as_datetime–Convert if possible a cffi pointer to a C data array char** , into a list of python strings.
-
geom_to_xarray_time_series–Converts an native time series structure to an xarray representation.
-
get_native_tsgeom–Get a native representation of the geometry of a time series. A simple heuristic is used to find the time step.
-
get_tsgeom–Extract a simplified representation of the geometry of a time series. A simple heuristic is used to find the time step.
-
named_values_to_dict–Convert if possible a cffi pointer to a
named_values_vectorstruct, into a dictionary. -
new_charptr_array–Creates a new C array of pointers to char:
char*[n]. -
new_ctype_array–Creates a new C array of a specified type and size.
-
new_date_time_to_second–Create a new cffi pointer to a C struct
date_time_to_second. -
new_double_array–Creates a new C array of double precision floats
double[n]. -
new_doubleptr_array–Creates a new C array of pointers to double precision floats
double*[n]. -
new_int_array–Creates a new C array of integers
int[n]. -
new_int_scalar_ptr–Creates a new C array of integers.
-
string_map_to_dict–Convert if possible a cffi pointer to a
string_string_mapstruct, into a dictionary. -
two_d_as_np_array_double–Convert if possible a cffi pointer to a C data array, into a numpy array of double precision floats.
-
two_d_np_array_double_to_native–Convert if possible a cffi pointer to a C data array, into a numpy array of double precision floats.
-
values_to_nparray–Convert if possible a cffi pointer to a
values_vectorstruct, into a python array.
Attributes:
-
NativePointerLike(TypeAlias) –types that can represent time series
NativePointerLike module-attribute ¶
NativePointerLike: TypeAlias = Union[
OwningCffiNativeHandle, CffiNativeHandle, CffiData
]
types that can represent time series
CffiMarshal ¶
CffiMarshal(ffi: FFI)
A helper class for marshalling data to/from a native library module (i.e. DLL).
Methods:
-
as_arrayof_bytes–Convert a list of "strings" to a char** like C array.
-
as_c_double_array–Convert a list or array of numeric values to a cffi pointer to a C array of double precision floats.
-
as_character_vector–Convert a list of "strings" to a character_vector* native struct.
-
as_charptr–Convert an object to
bytes, create as C array of char and copy values to it. Equivalent tochar arg[] = "world"if x is the bytes b"world". -
as_datetime–Convert if possible a cffi pointer to a C date_time_to_second struct, into a datetime.
-
as_native_time_series–Convert a pure python time series to a native representation via a C struct
multi_regular_time_series_data. -
as_native_tsgeom–C-compatible representation of a time series geometry.
-
as_np_array_double–Convert if possible a cffi pointer to a C data array, into a numpy array of double precision floats
double[n]. -
as_numeric_np_array–Convert if possible a cffi pointer to a C data array, into a numpy array.
-
as_xarray_time_series–Convert a native time series structure to an xarray representation.
-
c_charptrptr_as_string_list–Convert if possible a cffi pointer to a C data array char** , into a list of python strings.
-
c_string_as_py_string–Convert if possible a cffi pointer to an ANSI C string
to a python string. -
character_vector_as_string_list–Convert if possible a cffi pointer to a C character_vector , into a list of python strings.
-
create_values_struct–Convert a list or array of numeric values to a cffi pointer to a
values_vectorstruct. -
datetime_to_dtts–Convert a python datetime to a cffi pointer to a C struct
date_time_to_second. -
dict_to_named_values–Convert a dictionary to a cffi pointer to a
named_values_vectorstruct. -
dict_to_string_map–Convert a dictionary to a cffi pointer to a
string_string_mapstruct. -
get_native_tsgeom–Get a native representation of the geometry of a time series. A simple heuristic is used to find the time step.
-
named_values_to_dict–Convert if possible a cffi pointer to a
named_values_vectorstruct, into a dictionary. -
new_charptr_array–Creates a new C array of pointers to char (strings)
char*[n]. -
new_ctype_array–Creates a new C array of the specified type and size.
-
new_date_time_to_second–Create a new cffi pointer to a C struct
date_time_to_second. -
new_double_array–Creates a new C array of double precision floats
double[n]. -
new_doubleptr_array–Creates a new C array of pointers to double precision floats
double*[n]. -
new_int_array–Creates a new C array of integers
int[n]. -
new_int_scalar_ptr–Creates a new C array of integers.
-
new_native_struct–Create a new native C struct of the specified type.
-
new_native_tsgeom–Create a new native time series geometry struct.
-
string_map_to_dict–Convert if possible a cffi pointer to a
string_string_mapstruct, into a dictionary. -
two_d_as_np_array_double–Convert if possible a cffi pointer to a C data array, into a numpy array of double precision floats.
-
two_d_np_array_double_to_native–Convert if possible a cffi pointer to a C data array, into a numpy array of double precision floats.
-
values_to_nparray–Convert if possible a cffi pointer to a
values_vectorstruct, into a python array.
Attributes:
Source code in src/cinterop/cffi/marshal.py
982 983 984 | |
as_arrayof_bytes ¶
Convert a list of "strings" to a char** like C array.
Source code in src/cinterop/cffi/marshal.py
1143 1144 1145 | |
as_c_double_array ¶
as_c_double_array(
data: ndarray, shallow: bool = False
) -> OwningCffiNativeHandle
Convert a list or array of numeric values to a cffi pointer to a C array of double precision floats.
Parameters:
-
data(Union[List[float], ndarray]) –list or array of numeric values
-
shallow(bool, default:False) –If True the resulting C array points directly to the data in the input numpy array (if it is a numpy array), otherwise a new C array is created and the data is copied to it. Defaults to False. Note that if the input data is a list, it will be converted to a numpy array and the resulting C array will not be shallow.
Returns:
-
OwningCffiNativeHandle(OwningCffiNativeHandle) –A wrapper that owns the memory allocated for the resulting C array of double precision floats.
Source code in src/cinterop/cffi/marshal.py
1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 | |
as_character_vector ¶
Convert a list of "strings" to a character_vector* native struct.
Source code in src/cinterop/cffi/marshal.py
1147 1148 1149 | |
as_charptr ¶
Convert an object to bytes, create as C array of char and copy values to it. Equivalent to char arg[] = "world" if x is the bytes b"world".
Parameters:
-
x(str) –a string-like object; bytes or str, or string like object that can be encoded to bytes (six.string_like)
-
wrap(bool, default:False) –return a "naked" cdata pointer object if False, or wrapped in a
OwningCffiNativeHandleif True. Defaults to False.
Returns:
-
CffiData–Union[OwningCffiNativeHandle,CffiData]: a (wrapper to a) cdata pointer object owning a new array of
char *s of lengthsize
Source code in src/cinterop/cffi/marshal.py
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 | |
as_datetime ¶
as_datetime(ptr: CffiData) -> datetime
Convert if possible a cffi pointer to a C date_time_to_second struct, into a datetime.
Parameters:
-
ptr(CffiData) –cffi pointer (FFI.CData)
Raises:
-
RuntimeError–conversion is not supported
Returns:
-
datetime(datetime) –converted data
Source code in src/cinterop/cffi/marshal.py
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 | |
as_native_time_series ¶
as_native_time_series(
data: TimeSeriesLike,
) -> OwningCffiNativeHandle
Convert a pure python time series to a native representation via a C struct multi_regular_time_series_data.
Parameters:
-
data(TimeSeriesLike) –xarray or pandas based time series
Raises:
-
TypeError–unexpected input type
Returns:
-
OwningCffiNativeHandle(OwningCffiNativeHandle) –wrapper to a C struct
multi_regular_time_series_data
Source code in src/cinterop/cffi/marshal.py
1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 | |
as_native_tsgeom ¶
as_native_tsgeom(
tsgeom: TimeSeriesGeometry,
) -> TimeSeriesGeometryNative
C-compatible representation of a time series geometry.
Returns:
-
TimeSeriesGeometryNative(TimeSeriesGeometryNative) –wrapper around a cdata pointer to a new C struct
regular_time_series_geometry
Source code in src/cinterop/cffi/marshal.py
1219 1220 1221 1222 1223 1224 1225 | |
as_np_array_double ¶
Convert if possible a cffi pointer to a C data array, into a numpy array of double precision floats double[n].
The returned numpy array may be directly pointing to the original data (faster performance), or a deep copy (memory safety - "normal" numpy array)
Parameters:
-
ptr(CffiData) –cffi pointer (FFI.CData)
-
size(int) –array size
-
shallow(bool, default:False) –If True the resulting numpy array points directly to the native data array. Otherwise, return a numpy array with a deep copy of the data, managed by Python. Defaults to False.
Raises:
-
RuntimeError–conversion is not supported
Returns:
-
ndarray–np.ndarray: converted data
Source code in src/cinterop/cffi/marshal.py
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 | |
as_numeric_np_array ¶
Convert if possible a cffi pointer to a C data array, into a numpy array.
Parameters:
-
ptr(CffiData) –cffi pointer (FFI.CData)
-
size(int) –array size
-
shallow(bool, default:False) –If true the array points directly to native data array. Defaults to False.
Raises:
-
RuntimeError–conversion is not supported
Returns:
-
ndarray–np.ndarray: converted data
Source code in src/cinterop/cffi/marshal.py
986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 | |
as_xarray_time_series ¶
as_xarray_time_series(ptr: CffiData) -> Optional[DataArray]
Convert a native time series structure to an xarray representation.
Source code in src/cinterop/cffi/marshal.py
1227 1228 1229 | |
c_charptrptr_as_string_list ¶
Convert if possible a cffi pointer to a C data array char** , into a list of python strings.
Parameters:
-
ptr(CffiData) –cffi pointer (FFI.CData)
-
size(int) –number of character strings in the char** pointer
Raises:
-
RuntimeError–conversion is not supported
Returns:
Source code in src/cinterop/cffi/marshal.py
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 | |
c_string_as_py_string ¶
c_string_as_py_string(ptr: CffiData) -> str
Convert if possible a cffi pointer to an ANSI C string
Parameters:
-
ptr(CffiData) –cffi pointer (FFI.CData)
Raises:
-
RuntimeError–conversion is not supported
Returns:
-
str(str) –converted string
Source code in src/cinterop/cffi/marshal.py
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 | |
character_vector_as_string_list ¶
Convert if possible a cffi pointer to a C character_vector , into a list of python strings.
Parameters:
-
ptr(CffiData) –cffi pointer (FFI.CData)
Raises:
-
RuntimeError–conversion is not supported
Returns:
Source code in src/cinterop/cffi/marshal.py
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 | |
create_values_struct ¶
Convert a list or array of numeric values to a cffi pointer to a values_vector struct.
Source code in src/cinterop/cffi/marshal.py
1209 1210 1211 1212 1213 1214 | |
datetime_to_dtts ¶
datetime_to_dtts(dt: datetime) -> OwningCffiNativeHandle
Convert a python datetime to a cffi pointer to a C struct date_time_to_second.
Source code in src/cinterop/cffi/marshal.py
1139 1140 1141 | |
dict_to_named_values ¶
Convert a dictionary to a cffi pointer to a named_values_vector struct.
Parameters:
Returns:
-
OwningCffiNativeHandle(OwningCffiNativeHandle) –A wrapper that owns the memory allocated for the resulting
named_values_vectorpointed to
Source code in src/cinterop/cffi/marshal.py
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 | |
dict_to_string_map ¶
Convert a dictionary to a cffi pointer to a string_string_map struct.
Source code in src/cinterop/cffi/marshal.py
1179 1180 1181 | |
get_native_tsgeom ¶
get_native_tsgeom(
pd_series: Series,
) -> OwningCffiNativeHandle
Get a native representation of the geometry of a time series. A simple heuristic is used to find the time step.
Source code in src/cinterop/cffi/marshal.py
1231 1232 1233 | |
named_values_to_dict ¶
Convert if possible a cffi pointer to a named_values_vector struct, into a dictionary.
Parameters:
-
ptr(CffiData) –cffi pointer (FFI.CData) to a
named_values_vectorstruct
Raises:
-
RuntimeError–conversion is not supported
Returns:
Source code in src/cinterop/cffi/marshal.py
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 | |
new_charptr_array ¶
Creates a new C array of pointers to char (strings) char*[n].
Parameters:
-
size(int) –array size
-
wrap(bool, default:False) –return a "naked" cdata pointer object if False, or wrapped in a
OwningCffiNativeHandleif True. Defaults to False.
Returns:
-
Union[OwningCffiNativeHandle, CffiData]–Union[OwningCffiNativeHandle,CffiData]: a (wrapper to a) cdata pointer object owning a new array of pointers to char (strings) of length
size
Source code in src/cinterop/cffi/marshal.py
1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 | |
new_ctype_array ¶
new_ctype_array(
ctype: str, size: int, wrap: bool = False
) -> Union[OwningCffiNativeHandle, CffiData]
Creates a new C array of the specified type and size.
Parameters:
-
ctype(str) –C type of the array elements, e.g. "int", "double", "char*"
-
size(int) –array size
-
wrap(bool, default:False) –return a "naked" cdata pointer object if False, or wrapped in a
OwningCffiNativeHandleif True. Defaults to False.
Returns:
-
Union[OwningCffiNativeHandle, CffiData]–Union[OwningCffiNativeHandle,CffiData]: a (wrapper to a) cdata pointer object owning a new array of the specified type and length
size
Source code in src/cinterop/cffi/marshal.py
1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 | |
new_date_time_to_second ¶
new_date_time_to_second() -> OwningCffiNativeHandle
Create a new cffi pointer to a C struct date_time_to_second.
Source code in src/cinterop/cffi/marshal.py
1239 1240 1241 | |
new_double_array ¶
Creates a new C array of double precision floats double[n].
Parameters:
-
size(int) –array size
-
wrap(bool, default:False) –return a "naked" cdata pointer object if False, or wrapped in a
OwningCffiNativeHandleif True. Defaults to False.
Returns:
-
Union[OwningCffiNativeHandle, CffiData]–Union[OwningCffiNativeHandle,CffiData]: a (wrapper to a) cdata pointer object owning a new array of double precision floats of length
size
Source code in src/cinterop/cffi/marshal.py
1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 | |
new_doubleptr_array ¶
Creates a new C array of pointers to double precision floats double*[n].
Parameters:
-
size(int) –array size
-
wrap(bool, default:False) –return a "naked" cdata pointer object if False, or wrapped in a
OwningCffiNativeHandleif True. Defaults to False.
Returns:
-
Union[OwningCffiNativeHandle, CffiData]–Union[OwningCffiNativeHandle,CffiData]: a (wrapper to a) cdata pointer object owning a new array of pointers to double precision floats of length
size
Source code in src/cinterop/cffi/marshal.py
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 | |
new_int_array ¶
Creates a new C array of integers int[n].
Parameters:
-
size(int) –array size
-
wrap(bool, default:False) –return a "naked" cdata pointer object if False, or wrapped in a
OwningCffiNativeHandleif True. Defaults to False.
Returns:
-
Union[OwningCffiNativeHandle, CffiData]–Union[OwningCffiNativeHandle,CffiData]: a (wrapper to a) cdata pointer object owning a new array of integers of length
size
Source code in src/cinterop/cffi/marshal.py
1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 | |
new_int_scalar_ptr ¶
new_int_scalar_ptr(value: int = 0) -> CffiData
Creates a new C array of integers.
Parameters:
-
value(int, default:0) –description. Defaults to 0.
Returns:
-
CffiData(CffiData) –a cdata pointer object owning a new pointer to a single integer valued as specified.
Source code in src/cinterop/cffi/marshal.py
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 | |
new_native_struct ¶
new_native_struct(
type_of_struct: str,
) -> OwningCffiNativeHandle
Create a new native C struct of the specified type.
Source code in src/cinterop/cffi/marshal.py
1243 1244 1245 | |
new_native_tsgeom ¶
new_native_tsgeom() -> TimeSeriesGeometryNative
Create a new native time series geometry struct.
Source code in src/cinterop/cffi/marshal.py
1235 1236 1237 | |
string_map_to_dict ¶
Convert if possible a cffi pointer to a string_string_map struct, into a dictionary.
Parameters:
-
ptr(CffiData) –cffi pointer (FFI.CData) to a
string_string_mapstruct
Raises:
-
RuntimeError–conversion is not supported
Returns:
Source code in src/cinterop/cffi/marshal.py
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 | |
two_d_as_np_array_double ¶
Convert if possible a cffi pointer to a C data array, into a numpy array of double precision floats.
Parameters:
-
ptr(CffiData) –cffi pointer (FFI.CData)
-
nrow(int) –number of rows
-
ncol(int) –number of columns
Raises:
-
RuntimeError–conversion is not supported
Returns:
-
ndarray–np.ndarray: converted data
Source code in src/cinterop/cffi/marshal.py
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 | |
two_d_np_array_double_to_native ¶
two_d_np_array_double_to_native(
data: ndarray,
) -> OwningCffiNativeHandle
Convert if possible a cffi pointer to a C data array, into a numpy array of double precision floats.
Parameters:
-
data(ndarray) –data
Raises:
-
RuntimeError–conversion is not supported
Returns:
-
OwningCffiNativeHandle(OwningCffiNativeHandle) –wrapper to a C array of pointers to double precision floats of length
nrow
Source code in src/cinterop/cffi/marshal.py
1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 | |
values_to_nparray ¶
values_to_nparray(ptr: CffiData) -> ndarray
Convert if possible a cffi pointer to a values_vector struct, into a python array.
Parameters:
-
ptr(CffiData) –cffi pointer (FFI.CData) to a
values_vectorstruct
Raises:
-
RuntimeError–conversion is not supported
Returns:
-
ndarray–Dict[str,float]: converted data
Source code in src/cinterop/cffi/marshal.py
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 | |
TimeSeriesGeometry ¶
TimeSeriesGeometry(
start: ConvertibleToTimestamp = None,
time_step_seconds: int = 3600,
length: int = 1,
time_step_code: int = 0,
)
Simplified representation of the temporal geometry of a time series.
Suitable for interop with the C struct regular_time_series_geometry
Suitable for interop with the C struct regular_time_series_geometry
Parameters:
-
start(ConvertibleToTimestamp, default:None) –Start date of a time series. Defaults to None.
-
time_step_seconds(int, default:3600) –time step length in seconds, used if this is a regular time step. Defaults to 3600.
-
length(int, default:1) –number of items in the time series. Defaults to 1.
-
time_step_code(int, default:0) –type of time step: 0 for even time steps, or 1 for monthly, in which case
time_step_secondsis overriden. Defaults to 0.
Methods:
-
as_native–C-compatible representation of a time series geometry.
-
from_native–Create a simplified time series geometry from a native representation.
Source code in src/cinterop/cffi/marshal.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
as_native ¶
as_native(ffi: FFI) -> TimeSeriesGeometryNative
C-compatible representation of a time series geometry.
Parameters:
-
ffi(FFI) –FFI instance wrapping the native compilation module owning the native memory
Returns:
-
TimeSeriesGeometryNative(TimeSeriesGeometryNative) –wrapper around a cdata pointer to a new C struct
regular_time_series_geometry
Source code in src/cinterop/cffi/marshal.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | |
from_native staticmethod ¶
from_native(
ts_geom: TimeSeriesGeometryNative,
) -> TimeSeriesGeometry
Create a simplified time series geometry from a native representation.
Source code in src/cinterop/cffi/marshal.py
373 374 375 376 377 378 379 380 381 | |
TimeSeriesGeometryNative ¶
TimeSeriesGeometryNative(
ffi: Union[FFI, CffiData],
start: ConvertibleToTimestamp = None,
time_step_seconds: int = 3600,
length: int = 1,
time_step_code: int = 0,
)
Bases: OwningCffiNativeHandle
Wrapper around a cdata pointer to a new C struct regular_time_series_geometry.
Parameters:
-
ffi(Union[FFI, CffiData]) –FFI instance, or a preexisting cdata pointer to a
regular_time_series_geometrystruct -
start(ConvertibleToTimestamp, default:None) –Start date of a time series. Defaults to None.
-
time_step_seconds(int, default:3600) –time step length in seconds, used if this is a regular time step. Defaults to 3600.
-
length(int, default:1) –number of items in the time series. Defaults to 1.
-
time_step_code(int, default:0) –type of time step: 0 for even time steps, or 1 for monthly, in which case
time_step_secondsis overriden. Defaults to 0.
Methods:
-
time_index–Get the time index corresponding to this time series geometry.
Attributes:
-
length(int) –Number of items in the time series.
-
start(datetime) –Start date of the time series.
-
time_step_code(int) –Type of time step: 0 for even time steps, or 1 for monthly, in which case
time_step_secondsis overriden. -
time_step_seconds(int) –Time step length in seconds, used if this is a regular time step.
Source code in src/cinterop/cffi/marshal.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | |
time_step_code property writable ¶
time_step_code: int
Type of time step: 0 for even time steps, or 1 for monthly, in which case time_step_seconds is overriden.
time_step_seconds property writable ¶
time_step_seconds: int
Time step length in seconds, used if this is a regular time step.
time_index ¶
Get the time index corresponding to this time series geometry.
Source code in src/cinterop/cffi/marshal.py
459 460 461 | |
as_arrayof_bytes ¶
Convert a list of "strings" to a char** like C array.
Parameters:
-
obj(List) –list of objects (strings) to convert
Returns:
-
List(OwningCffiNativeHandle) –objects converted to bytes if it was a type of string
Source code in src/cinterop/cffi/marshal.py
909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 | |
as_bytes ¶
Convert obj to bytes, if it is a type of string.
This function is mostly a legacy for python2/3 compatibility, though python 2 in practice is probably not supported anymore by the package. In python3, it converts str to bytes, and leaves bytes unchanged. In python2, it converts unicode to bytes, and leaves str unchanged.
Parameters:
-
obj(Any) –object to convert
Returns:
-
Union[bytes, Any]–Union[bytes, Any]: object converted to bytes if it was a type of string. If unknown type, returns the object unchanged.
Source code in src/cinterop/cffi/marshal.py
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 | |
as_c_double_array ¶
as_c_double_array(
ffi: FFI,
data: Union[List[float], ndarray],
shallow: bool = False,
) -> OwningCffiNativeHandle
Convert a list or array of numeric values to a cffi pointer to a C array of double precision floats.
Parameters:
-
ffi(FFI) –FFI instance wrapping the native compilation module owning the native memory
-
data(Union[List[float], ndarray]) –list or array of numeric values
-
shallow(bool, default:False) –If True the resulting C array points directly to the data in the input numpy array (if it is a numpy array), otherwise a new C array is created and the data is copied to it. Defaults to False. Note that if the input data is a list, it will be converted to a numpy array and the resulting C array will not be shallow.
Raises:
-
RuntimeError–conversion is not supported
Returns: OwningCffiNativeHandle: A wrapper that owns the memory allocated for the resulting C array of double precision floats.
Source code in src/cinterop/cffi/marshal.py
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 | |
as_character_vector ¶
Convert a list of "strings" to a character_vector* native struct.
Source code in src/cinterop/cffi/marshal.py
927 928 929 930 931 932 933 934 935 | |
as_charptr ¶
Convert an object to bytes, create as C array of char and copy values to it. Equivalent to char arg[] = "world" if x is the bytes b"world".
Parameters:
-
ffi(FFI) –ffi object to the native library accessed
-
x(str) –a string-like object; bytes or str, or string like object that can be encoded to bytes (six.string_like)
-
wrap(bool, default:False) –return a "naked" cdata pointer object if False, or wrapped in a
OwningCffiNativeHandleif True. Defaults to False.
Returns:
-
Union[OwningCffiNativeHandle, CffiData]–Union[OwningCffiNativeHandle,CffiData]: a (wrapper to a) cdata pointer object owning a new array of
char *s of lengthsize
Source code in src/cinterop/cffi/marshal.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
as_native_time_series ¶
as_native_time_series(
ffi: FFI, data: TimeSeriesLike
) -> OwningCffiNativeHandle
Convert a pure python time series to a native representation via a C struct multi_regular_time_series_data.
Parameters:
-
ffi(FFI) –description
-
data(TimeSeriesLike) –xarray or pandas based time series
Raises:
-
TypeError–unexpected input type
Returns:
-
OwningCffiNativeHandle(OwningCffiNativeHandle) –wrapper to a C struct
multi_regular_time_series_data
Source code in src/cinterop/cffi/marshal.py
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 | |
as_native_tsgeom ¶
as_native_tsgeom(
ffi: FFI, tsgeom: TimeSeriesGeometry
) -> TimeSeriesGeometryNative
Convert a simlified time series geometry to a native representation.
Parameters:
-
ffi(Union[FFI, CffiData]) –FFI instance, or a preexisting cdata pointer to a
regular_time_series_geometrystruct -
tsgeom(TimeSeriesGeometry) –simplified representation
Returns:
-
TimeSeriesGeometryNative(TimeSeriesGeometryNative) –Wrapper around a cdata pointer to a new C struct
regular_time_series_geometry
Source code in src/cinterop/cffi/marshal.py
477 478 479 480 481 482 483 484 485 486 487 | |
as_np_array_double ¶
Convert if possible a cffi pointer to a C data array, into a numpy array of double precision floats double[n].
The returned numpy array may be directly pointing to the original data (faster performance), or a deep copy (memory safety - "normal" numpy array)
Parameters:
-
ffi(FFI) –FFI instance wrapping the native compilation module owning the native memory
-
ptr(CffiData) –cffi pointer (FFI.CData)
-
size(int) –array size
-
shallow(bool, default:False) –If True the resulting numpy array points directly to the native data array. Otherwise, return a numpy array with a deep copy of the data, managed by Python. Defaults to False.
Raises:
-
RuntimeError–conversion is not supported
Returns:
-
ndarray–np.ndarray: converted data
Source code in src/cinterop/cffi/marshal.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
as_numeric_np_array ¶
Convert if possible a cffi pointer to a C data array, into a numpy array.
Parameters:
-
ffi(FFI) –FFI instance wrapping the native compilation module owning the native memory
-
ptr(CffiData) –cffi pointer (FFI.CData)
-
size(int) –array size
-
shallow(bool, default:False) –If true the array points directly to native data array. Defaults to False.
Raises:
-
TypeError–conversion is not supported
Returns:
-
ndarray–np.ndarray: converted data
Source code in src/cinterop/cffi/marshal.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
as_string ¶
Convert obj to string/unicode if it is a bytes object.
Mostly a legacy for python2/3 compatibility.
Parameters:
-
obj(Any) –object to convert
Returns:
Source code in src/cinterop/cffi/marshal.py
938 939 940 941 942 943 944 945 946 947 948 949 950 951 | |
as_xarray_time_series ¶
as_xarray_time_series(
ffi: FFI,
ptr: CffiData,
name: Optional[str] = None,
allow_empty: bool = True,
) -> Optional[DataArray]
Converts a native time series structure to an xarray representation.
Parameters:
-
ffi(FFI) –ffi object to the library
-
ptr(CffiData) –pointer to the native struct
multi_regular_time_series_data -
name(str, default:None) –name of the returned series. Defaults to None.
Returns:
-
Optional[DataArray]–xr.DataArray: xarray time series
Source code in src/cinterop/cffi/marshal.py
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 | |
c_charptrptr_as_string_list ¶
Convert if possible a cffi pointer to a C data array char** , into a list of python strings.
Parameters:
-
ffi(FFI) –FFI instance wrapping the native compilation module owning the native memory
-
ptr(CffiData) –cffi pointer (FFI.CData)
-
size(int) –number of character strings in the char** pointer
Raises:
-
RuntimeError–conversion is not supported
Returns:
Source code in src/cinterop/cffi/marshal.py
824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 | |
c_string_as_py_string ¶
c_string_as_py_string(ffi: FFI, ptr: CffiData) -> str
Convert if possible a cffi pointer to an ANSI C string
Parameters:
-
ffi(FFI) –FFI instance wrapping the native compilation module owning the native memory
-
ptr(CffiData) –cffi pointer (FFI.CData)
Raises:
-
RuntimeError–conversion is not supported
Returns:
-
str(str) –converted string
Source code in src/cinterop/cffi/marshal.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 | |
convert_strings ¶
Returns a wrapper that converts any str/unicode object arguments to bytes.
Source code in src/cinterop/cffi/marshal.py
954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 | |
create_values_struct ¶
Convert a list or array of numeric values to a cffi pointer to a values_vector struct.
Parameters:
-
ffi(FFI) –FFI instance wrapping the native compilation module owning the native memory
-
data(Union[List[float], ndarray]) –list or array of numeric values
Returns:
-
OwningCffiNativeHandle(OwningCffiNativeHandle) –A wrapper that owns the memory allocated for the resulting
values_vectorpointed to.
Source code in src/cinterop/cffi/marshal.py
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 | |
datetime_to_dtts ¶
datetime_to_dtts(
ffi: FFI, dt: datetime
) -> OwningCffiNativeHandle
Convert a python datetime to a cffi pointer to a C struct date_time_to_second.
Source code in src/cinterop/cffi/marshal.py
876 877 878 879 880 | |
dict_to_named_values ¶
Convert a dictionary to a cffi pointer to a named_values_vector struct.
Parameters:
-
ffi(FFI) –FFI instance wrapping the native compilation module owning the native memory
-
data(Dict[str, float]) –mapping from keys to numeric values
Returns:
-
OwningCffiNativeHandle(OwningCffiNativeHandle) –A wrapper that owns the memory allocated for the resulting
named_values_vectorpointed to
Source code in src/cinterop/cffi/marshal.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
dict_to_string_map ¶
Convert a dictionary to a cffi pointer to a string_string_map struct.
Parameters:
-
ffi(FFI) –FFI instance wrapping the native compilation module owning the native memory
-
data(Dict[str, float]) –mapping from keys to (str) values
Returns:
-
OwningCffiNativeHandle(OwningCffiNativeHandle) –A wrapper that owns the memory allocated for the resulting
string_string_mappointed to.
Source code in src/cinterop/cffi/marshal.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
dtts_as_datetime ¶
dtts_as_datetime(ptr: CffiData) -> datetime
Convert if possible a cffi pointer to a C data array char** , into a list of python strings.
Parameters:
-
ptr(CffiData) –cffi pointer (FFI.CData)
Raises:
-
RuntimeError–conversion is not supported
Returns:
-
datetime(datetime) –converted data
Source code in src/cinterop/cffi/marshal.py
843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 | |
geom_to_xarray_time_series ¶
geom_to_xarray_time_series(
ts_geom: TimeSeriesGeometryNative,
data: ndarray,
name: Optional[str] = None,
) -> DataArray
Converts an native time series structure to an xarray representation.
Parameters:
-
ts_geom(TimeSeriesGeometryNative) –time series geometry
-
data(ndarray) –time series data, with one dimension
-
name(str, default:None) –name of the returned series. Defaults to None.
Returns:
-
DataArray–xr.DataArray: xarray time series
Source code in src/cinterop/cffi/marshal.py
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 | |
get_native_tsgeom ¶
get_native_tsgeom(
ffi: FFI, pd_series: TimeSeriesLike
) -> OwningCffiNativeHandle
Get a native representation of the geometry of a time series. A simple heuristic is used to find the time step.
Parameters:
-
ffi(FFI) –FFI instance wrapping the native compilation module owning the native memory
-
pd_series(TimeSeriesLike) –A pandas or xarray representation of a time series, with the pandas index or "time" dimension expected.
Raises:
-
TypeError–Unexpected type of data
Returns:
-
OwningCffiNativeHandle(OwningCffiNativeHandle) –wrapper to a cdata pointer to a new C struct
regular_time_series_geometry
Source code in src/cinterop/cffi/marshal.py
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 | |
get_tsgeom ¶
get_tsgeom(data: TimeSeriesLike) -> TimeSeriesGeometry
Extract a simplified representation of the geometry of a time series. A simple heuristic is used to find the time step.
Parameters:
-
data(TimeSeriesLike) –A pandas or xarray representation of a time series, with the pandas index or "time" dimension expected.
Raises:
-
TypeError–Unexpected type of data
Returns:
-
TimeSeriesGeometry(TimeSeriesGeometry) –simplified time series geometry
Source code in src/cinterop/cffi/marshal.py
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |
named_values_to_dict ¶
Convert if possible a cffi pointer to a named_values_vector struct, into a dictionary.
Parameters:
-
ffi(FFI) –FFI instance wrapping the native compilation module owning the native memory
-
ptr(CffiData) –cffi pointer (FFI.CData) to a
named_values_vectorstruct
Raises:
-
RuntimeError–conversion is not supported
Returns:
Source code in src/cinterop/cffi/marshal.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
new_charptr_array ¶
new_charptr_array(
ffi: FFI, size: int, wrap: bool = False
) -> Union[OwningCffiNativeHandle, CffiData]
Creates a new C array of pointers to char: char*[n].
Parameters:
-
ffi(FFI) –ffi object to the native library accessed
-
size(int) –array size
-
wrap(bool, default:False) –return a "naked" cdata pointer object if False, or wrapped in a
OwningCffiNativeHandleif True. Defaults to False.
Returns:
-
Union[OwningCffiNativeHandle, CffiData]–Union[OwningCffiNativeHandle,CffiData]: a (wrapper to a) cdata pointer object owning a new array of
char *s of lengthsize
Source code in src/cinterop/cffi/marshal.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
new_ctype_array ¶
new_ctype_array(
ffi: FFI, ctype: str, size: int, wrap: bool = False
) -> Union[OwningCffiNativeHandle, CffiData]
Creates a new C array of a specified type and size.
Parameters:
-
ffi(FFI) –ffi object to the native library accessed
-
ctype(str) –valid C type for array creation
-
size(int) –array size
-
wrap(bool, default:False) –return a "naked" cdata pointer object if False, or wrapped in a
OwningCffiNativeHandleif True. Defaults to False.
Returns:
-
Union[OwningCffiNativeHandle, CffiData]–Union[OwningCffiNativeHandle,CffiData]: cdata pointer or wrapper to it.
Source code in src/cinterop/cffi/marshal.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
new_date_time_to_second ¶
new_date_time_to_second(ffi: FFI) -> OwningCffiNativeHandle
Create a new cffi pointer to a C struct date_time_to_second.
Source code in src/cinterop/cffi/marshal.py
883 884 885 886 | |
new_double_array ¶
new_double_array(
ffi: FFI, size: int, wrap: bool = False
) -> Union[OwningCffiNativeHandle, CffiData]
Creates a new C array of double precision floats double[n].
Parameters:
-
ffi(FFI) –ffi object to the native library accessed
-
size(int) –array size
-
wrap(bool, default:False) –return a "naked" cdata pointer object if False, or wrapped in a
OwningCffiNativeHandleif True. Defaults to False.
Returns:
-
Union[OwningCffiNativeHandle, CffiData]–Union[OwningCffiNativeHandle,CffiData]: a (wrapper to a) cdata pointer object owning a new array of
doubles of lengthsize
Source code in src/cinterop/cffi/marshal.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
new_doubleptr_array ¶
new_doubleptr_array(
ffi: FFI, size: int, wrap: bool = False
) -> Union[OwningCffiNativeHandle, CffiData]
Creates a new C array of pointers to double precision floats double*[n].
Parameters:
-
ffi(FFI) –ffi object to the native library accessed
-
size(int) –array size
-
wrap(bool, default:False) –return a "naked" cdata pointer object if False, or wrapped in a
OwningCffiNativeHandleif True. Defaults to False.
Returns:
-
Union[OwningCffiNativeHandle, CffiData]–Union[OwningCffiNativeHandle,CffiData]: a (wrapper to a) cdata pointer object owning a new array of
double *s of lengthsize
Source code in src/cinterop/cffi/marshal.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
new_int_array ¶
Creates a new C array of integers int[n].
Parameters:
-
ffi(FFI) –ffi object to the native library accessed
-
size(int) –array size
-
wrap(bool, default:False) –return a "naked" cdata pointer object if False, or wrapped in a
OwningCffiNativeHandleif True. Defaults to False.
Returns:
-
Union[OwningCffiNativeHandle, CffiData]–Union[OwningCffiNativeHandle,CffiData]: a (wrapper to a) cdata pointer object owning a new array of integers of length
size
Source code in src/cinterop/cffi/marshal.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
new_int_scalar_ptr ¶
new_int_scalar_ptr(ffi: FFI, value: int = 0) -> CffiData
Creates a new C array of integers.
Parameters:
-
ffi(FFI) –ffi object to the native library accessed
-
value(int, default:0) –description. Defaults to 0.
Returns:
-
CffiData(CffiData) –a cdata pointer object owning a new pointer to a single integer valued as specified.
Source code in src/cinterop/cffi/marshal.py
47 48 49 50 51 52 53 54 55 56 57 58 59 | |
string_map_to_dict ¶
Convert if possible a cffi pointer to a string_string_map struct, into a dictionary.
Parameters:
-
ffi(FFI) –FFI instance wrapping the native compilation module owning the native memory
-
ptr(CffiData) –cffi pointer (FFI.CData) to a
string_string_mapstruct
Raises:
-
RuntimeError–conversion is not supported
Returns:
Source code in src/cinterop/cffi/marshal.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
two_d_as_np_array_double ¶
Convert if possible a cffi pointer to a C data array, into a numpy array of double precision floats.
Parameters:
-
ffi(FFI) –FFI instance wrapping the native compilation module owning the native memory
-
ptr(CffiData) –cffi pointer (FFI.CData)
-
nrow(int) –number of rows
-
ncol(int) –number of columns
Raises:
-
RuntimeError–conversion is not supported
Returns:
-
ndarray–np.ndarray: converted data
Source code in src/cinterop/cffi/marshal.py
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 | |
two_d_np_array_double_to_native ¶
two_d_np_array_double_to_native(
ffi: FFI, data: ndarray
) -> OwningCffiNativeHandle
Convert if possible a cffi pointer to a C data array, into a numpy array of double precision floats.
Parameters:
-
ffi(FFI) –FFI instance wrapping the native compilation module owning the native memory
-
data(ndarray) –data
Raises:
-
RuntimeError–conversion is not supported
Returns:
-
OwningCffiNativeHandle–np.ndarray: converted data
Source code in src/cinterop/cffi/marshal.py
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 | |
values_to_nparray ¶
values_to_nparray(ffi: FFI, ptr: CffiData) -> ndarray
Convert if possible a cffi pointer to a values_vector struct, into a python array.
Parameters:
-
ffi(FFI) –FFI instance wrapping the native compilation module owning the native memory
-
ptr(CffiData) –cffi pointer (FFI.CData) to a
values_vectorstruct
Raises:
-
RuntimeError–conversion is not supported
Returns:
-
ndarray–np.ndarray: converted data
Source code in src/cinterop/cffi/marshal.py
649 650 651 652 653 654 655 656 657 658 659 660 661 662 | |
timeseries ¶
Python representations of multidimensional time series and interop with Python cffi.
Functions:
-
as_datetime64–Convert, if possible, to a numpy datetime64.
-
as_pydatetime–Convert, if possible, to a datetime.
-
as_timestamp–Converts, if possible, a value to a pandas
Timestamp. -
create_daily_time_index–Creates a daily time index.
-
create_ensemble_forecasts_series–Create an ensemble forecasts time series (i.e. a series of ensembles of series).
-
create_ensemble_series–Create an ensemble (i.e. special type of multi-variate) time series.
-
create_even_time_index–Creates a regular, evenly spaces time index.
-
create_hourly_time_index–Creates an hourly time index.
-
create_monthly_time_index–Creates a monthly time index.
-
create_single_series–Create an uni-variate time series.
-
end_ts–Gets the ending date of a time series.
-
mk_daily_xarray_series–Create a daily xarray time series.
-
mk_even_step_xarray_series–Create an xarray time series with an even time step.
-
mk_hourly_xarray_series–Create an hourly xarray time series.
-
mk_xarray_series–Create an xarray time series.
-
pd_series_to_xr_series–Converts a pandas series to an xarray.
-
set_xr_units–Sets the units attribute of an xr.DataArray. No effect if x is not a dataarray.
-
slice_pd_time_series–Subset a time series to a period.
-
slice_xr_time_series–Subset a time series to a period.
-
start_ts–Gets the starting date of a time series.
-
ts_window–Gets a temporal window of a time series.
-
xr_ts_end–Deprecated: use end_ts.
-
xr_ts_start–Deprecated: use start_ts.
Attributes:
-
ConvertibleToTimestamp–types that can be converted with relative unambiguity to a pandas Timestamp
-
TimeSeriesLike–types that can represent time series
-
XR_UNITS_ATTRIB_ID(str) –key for the units attribute on xarray DataArray objects
ConvertibleToTimestamp module-attribute ¶
types that can be converted with relative unambiguity to a pandas Timestamp
TimeSeriesLike module-attribute ¶
TimeSeriesLike = Union[Series, DataFrame, DataArray]
types that can represent time series
XR_UNITS_ATTRIB_ID module-attribute ¶
XR_UNITS_ATTRIB_ID: str = 'units'
key for the units attribute on xarray DataArray objects
as_datetime64 ¶
as_datetime64(t: ConvertibleToTimestamp) -> datetime64
Convert, if possible, to a numpy datetime64.
Parameters:
-
t(ConvertibleToTimestamp) –date time value to convert
Raises:
-
ValueError–input value is not supported, notably values with time zone informations are excluded
-
TypeError–unexpected input type
Returns:
-
datetime64–np.datetime64: value as a datetime64
Source code in src/cinterop/timeseries.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
as_pydatetime ¶
as_pydatetime(t: ConvertibleToTimestamp) -> datetime
Convert, if possible, to a datetime.
Parameters:
-
t(ConvertibleToTimestamp) –date time value to convert
Raises:
-
ValueError–input value is not supported, notably values with time zone informations are excluded
-
TypeError–unexpected input type
Returns:
-
datetime(datetime) –value as a datetime
Source code in src/cinterop/timeseries.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
as_timestamp ¶
as_timestamp(t: ConvertibleToTimestamp) -> Timestamp
Converts, if possible, a value to a pandas Timestamp.
Parameters:
-
t(ConvertibleToTimestamp) –date time value to convert
Raises:
-
ValueError–input value is not supported, notably values with time zone informations are excluded
-
TypeError–unexpected input type
Returns:
-
Timestamp–pd.Timestamp: date time as a pandas Timestamp
Source code in src/cinterop/timeseries.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
create_daily_time_index ¶
create_daily_time_index(
start: ConvertibleToTimestamp, n: int
) -> DatetimeIndex
Creates a daily time index.
Parameters:
-
start(ConvertibleToTimestamp) –first datetime in the time index
-
n(int) –length of the index
Returns:
-
DatetimeIndex–pd.DatetimeIndex: a time index suitable for a time series.
Source code in src/cinterop/timeseries.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
create_ensemble_forecasts_series ¶
create_ensemble_forecasts_series(
npx: ndarray,
ens_index: List,
lead_time_index: List,
time_index: Union[List, DatetimeIndex],
) -> DataArray
Create an ensemble forecasts time series (i.e. a series of ensembles of series).
Source code in src/cinterop/timeseries.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
create_ensemble_series ¶
create_ensemble_series(
npx: ndarray,
ens_index: List,
time_index: Union[List, DatetimeIndex],
) -> DataArray
Create an ensemble (i.e. special type of multi-variate) time series.
Source code in src/cinterop/timeseries.py
361 362 363 364 365 366 367 368 369 370 371 | |
create_even_time_index ¶
create_even_time_index(
start: ConvertibleToTimestamp,
time_step_seconds: int,
n: int,
) -> DatetimeIndex
Creates a regular, evenly spaces time index.
Parameters:
-
start(ConvertibleToTimestamp) –first datetime in the time index
-
time_step_seconds(int) –time step length in seconds
-
n(int) –length of the index
Returns:
-
DatetimeIndex–pd.DatetimeIndex: a time index suitable for a time series.
Source code in src/cinterop/timeseries.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
create_hourly_time_index ¶
create_hourly_time_index(
start: ConvertibleToTimestamp, n: int
) -> DatetimeIndex
Creates an hourly time index.
Parameters:
-
start(ConvertibleToTimestamp) –first datetime in the time index
-
n(int) –length of the index
Returns:
-
DatetimeIndex–pd.DatetimeIndex: a time index suitable for a time series.
Source code in src/cinterop/timeseries.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
create_monthly_time_index ¶
create_monthly_time_index(
start: ConvertibleToTimestamp, n: int
) -> DatetimeIndex
Creates a monthly time index.
Parameters:
-
start(ConvertibleToTimestamp) –first datetime in the time index
-
n(int) –length of the index
Raises:
-
ValueError–day of month of the start date is more than 28
Returns:
-
DatetimeIndex–pd.DatetimeIndex: a time index suitable for a time series.
Source code in src/cinterop/timeseries.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
create_single_series ¶
Create an uni-variate time series.
Source code in src/cinterop/timeseries.py
394 395 396 397 398 399 400 401 402 | |
end_ts ¶
end_ts(x: TimeSeriesLike) -> datetime64
Gets the ending date of a time series.
Parameters:
-
x(TimeSeriesLike) –time series
Returns:
-
Any(datetime64) –end of the series
Source code in src/cinterop/timeseries.py
442 443 444 445 446 447 448 449 450 451 | |
mk_daily_xarray_series ¶
mk_daily_xarray_series(
data: Union[ndarray, TimeSeriesLike],
start_date: ConvertibleToTimestamp,
dim_name: Optional[str] = None,
units: Optional[str] = None,
colnames: Optional[List[str]] = None,
fill_miss_func: Optional[
Callable[[TsArrayLike], TsArrayLike]
] = None,
) -> DataArray
Create a daily xarray time series.
Parameters:
-
data(Union[ndarray, TimeSeriesLike]) –data from which to create the xarray series
-
start_date(ConvertibleToTimestamp) –start date of the daily time series
-
dim_name(str, default:None) –the name of the dimension for a multivariate series. Ignored if univariate. Defaults to None.
-
units(str, default:None) –units in the time series. Defaults to None.
-
colnames(Optional[List[str]], default:None) –names of the columns in a multivariate series. Defaults to None.
-
fill_miss_func(Optional[Callable[[TsArrayLike], TsArrayLike]], default:None) –optional function that fills in missing values (np.nan). Defaults to None.
Raises:
-
NotImplementedError–Input arguments are not consistent.
Returns:
-
DataArray–xr.DataArray: output xarray time series with at least a dimension "time"
Source code in src/cinterop/timeseries.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
mk_even_step_xarray_series ¶
mk_even_step_xarray_series(
data: Union[ndarray, TimeSeriesLike],
start_date: ConvertibleToTimestamp,
time_step_seconds: int,
dim_name: Optional[str] = None,
units: Optional[str] = None,
colnames: Optional[List[str]] = None,
fill_miss_func: Optional[
Callable[[TsArrayLike], TsArrayLike]
] = None,
) -> DataArray
Create an xarray time series with an even time step.
Parameters:
-
data(Union[ndarray, TimeSeriesLike]) –data from which to create the xarray series
-
start_date(ConvertibleToTimestamp) –start date of the daily time series
-
time_step_seconds(int) –time step length in seconds
-
dim_name(str, default:None) –the name of the dimension for a multivariate series. Ignored if univariate. Defaults to None.
-
units(str, default:None) –units in the time series. Defaults to None.
-
colnames(Optional[List[str]], default:None) –names of the columns in a multivariate series. Defaults to None.
-
fill_miss_func(Optional[Callable[[TsArrayLike], TsArrayLike]], default:None) –optional function that fills in missing values (np.nan). Defaults to None.
Raises:
-
NotImplementedError–Input arguments are not consistent.
Returns:
-
DataArray–xr.DataArray: output xarray time series with at least a dimension "time"
Source code in src/cinterop/timeseries.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
mk_hourly_xarray_series ¶
mk_hourly_xarray_series(
data: Union[ndarray, TimeSeriesLike],
start_date: ConvertibleToTimestamp,
dim_name: Optional[str] = None,
units: Optional[str] = None,
colnames: Optional[List[str]] = None,
fill_miss_func: Optional[
Callable[[TsArrayLike], TsArrayLike]
] = None,
) -> DataArray
Create an hourly xarray time series.
Parameters:
-
data(Union[ndarray, TimeSeriesLike]) –Data from which to create the xarray series
-
dim_name(str, default:None) –the name of the dimension for a multivariate series. Ignored if univariate. Defaults to None.
-
units(str, default:None) –units in the time series. Defaults to None.
-
colnames(Optional[List[str]], default:None) –names of the columns in a multivariate series. Defaults to None.
-
fill_miss_func(Optional[Callable[[TsArrayLike], TsArrayLike]], default:None) –optional function that fills in missing values (np.nan). Defaults to None.
Raises:
-
NotImplementedError–Input arguments are not consistent.
Returns:
-
DataArray–xr.DataArray: output xarray time series with at least a dimension "time"
Source code in src/cinterop/timeseries.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | |
mk_xarray_series ¶
mk_xarray_series(
data: Union[ndarray, TimeSeriesLike],
dim_name: Optional[str] = None,
units: Optional[str] = None,
time_index: Optional[Union[List, DatetimeIndex]] = None,
colnames: Optional[List[str]] = None,
fill_miss_func: Optional[
Callable[[TsArrayLike], TsArrayLike]
] = None,
) -> DataArray
Create an xarray time series.
Parameters:
-
data(Union[ndarray, TimeSeriesLike]) –data from which to create the xarray series
-
dim_name(str, default:None) –the name of the dimension for a multivariate series. Ignored if univariate. Defaults to None.
-
units(str, default:None) –units in the time series. Defaults to None.
-
time_index(Optional[Union[List, DatetimeIndex]], default:None) –the time index of the series. Optional if the input data already has a time index, such as a pandas series. Defaults to None.
-
colnames(Optional[List[str]], default:None) –names of the columns in a multivariate series. Defaults to None.
-
fill_miss_func(Optional[Callable[[TsArrayLike], TsArrayLike]], default:None) –optional function that fills in missing values (np.nan). Defaults to None.
Raises:
-
NotImplementedError–Input arguments are not consistent.
Returns:
-
DataArray–xr.DataArray: output xarray time series with at least a dimension "time"
Source code in src/cinterop/timeseries.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
pd_series_to_xr_series ¶
pd_series_to_xr_series(series: Series) -> DataArray
Converts a pandas series to an xarray.
Source code in src/cinterop/timeseries.py
405 406 407 408 409 | |
set_xr_units ¶
set_xr_units(x: DataArray, units: str) -> None
Sets the units attribute of an xr.DataArray. No effect if x is not a dataarray.
Parameters:
-
x(DataArray) –data array
-
units(str) –units descriptor
Source code in src/cinterop/timeseries.py
348 349 350 351 352 353 354 355 356 357 358 | |
slice_pd_time_series ¶
slice_pd_time_series(
data: Series,
from_date: ConvertibleToTimestamp = None,
to_date: ConvertibleToTimestamp = None,
) -> Series
Subset a time series to a period.
Parameters:
-
data(Series) –input xarray time series
-
from_date(ConvertibleToTimestamp, default:None) –date, convertible to a timestamp. Defaults to None.
-
to_date(ConvertibleToTimestamp, default:None) –end date of the slice. Inclusive. Defaults to None.
Returns:
-
Series–pd.Series: a subset time series
Examples:
slice_pd_time_series(unaccounted_indus, from_date='1980-04-01', to_date='2000-04-01')
Source code in src/cinterop/timeseries.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |
slice_xr_time_series ¶
slice_xr_time_series(
data: DataArray,
from_date: ConvertibleToTimestamp = None,
to_date: ConvertibleToTimestamp = None,
) -> DataArray
Subset a time series to a period.
Parameters:
-
data(DataArray) –input xarray time series
-
from_date(ConvertibleToTimestamp, default:None) –date, convertible to a timestamp. Defaults to None.
-
to_date(ConvertibleToTimestamp, default:None) –end date of the slice. Inclusive. Defaults to None.
Returns:
-
DataArray–xr.DataArray: a subset time series
Examples:
slice_xr_time_series(unaccounted_indus, from_date='1980-04-01', to_date='2000-04-01')
Source code in src/cinterop/timeseries.py
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 | |
start_ts ¶
start_ts(x: TimeSeriesLike) -> datetime64
Gets the starting date of a time series.
Parameters:
-
x(TimeSeriesLike) –time series
Returns:
-
Any(datetime64) –start of the series
Source code in src/cinterop/timeseries.py
430 431 432 433 434 435 436 437 438 439 | |
ts_window ¶
ts_window(
ts: TimeSeriesLike,
from_date: ConvertibleToTimestamp = None,
to_date: ConvertibleToTimestamp = None,
) -> TimeSeriesLike
Gets a temporal window of a time series.
Parameters:
-
ts(TimeSeriesLike) –pandas dataframe, series, or xarray DataArray
-
from_date(ConvertibleToTimestamp, default:None) –start date of the window. Defaults to None.
-
to_date(ConvertibleToTimestamp, default:None) –end date of the window. Defaults to None.
Raises:
-
TypeError–unhandled input time for
ts
Returns:
-
TimeSeriesLike(TimeSeriesLike) –Subset window of the full time series
Examples:
ts_window(unaccounted_indus, from_date='1980-04-01', to_date='2000-04-01')
Source code in src/cinterop/timeseries.py
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 | |
xr_ts_end ¶
xr_ts_end(x: TimeSeriesLike) -> datetime64
Deprecated: use end_ts.
Source code in src/cinterop/timeseries.py
460 461 462 | |
xr_ts_start ¶
xr_ts_start(x: TimeSeriesLike) -> datetime64
Deprecated: use start_ts.
Source code in src/cinterop/timeseries.py
455 456 457 | |