pandas_ts.ts_dtype
Module Contents
Classes
Data type to handle packed time series data |
- class TsDtype(pyarrow_dtype: pyarrow.DataType)[source]
Bases:
pandas.ArrowDtypeData type to handle packed time series data
- classmethod from_fields(fields: collections.abc.Mapping[str, pyarrow.DataType]) Self[source]
Make TsDtype from a mapping of field names and list item types.
- Parameters:
fields (Mapping[str, pa.DataType]) – A mapping of field names and their item types. Since all fields are lists, the item types are inner types of the lists, not the list types themselves.
- Returns:
The constructed TsDtype.
- Return type:
Examples
>>> dtype = TsDtype.from_fields({"a": pa.float64(), "b": pa.int64()}) >>> dtype ts<a: [double], b: [int64]> >>> assert ( ... dtype.pyarrow_dtype ... == pa.struct({"a": pa.list_(pa.float64()), "b": pa.list_(pa.int64())}) ... )
- classmethod construct_from_string(string: str) Self[source]
Construct TsDtype from a string representation.
This works only for simple types, i.e. non-parametric pyarrow types.
- Parameters:
string (str) – The string representation of the ts type. For example, ‘ts<x: [int64], y: [float64]’. It must be consistent with the string representation of the dtype given by the name attribute.
- Returns:
The constructed TsDtype.
- Return type:
- Raises:
ValueError – If the string is not a valid ts type string or if the element types are parametric pyarrow types.
- classmethod from_pandas_arrow_dtype(pandas_arrow_dtype: pandas.ArrowDtype)[source]
Construct TsDtype from a pandas.ArrowDtype.
- Parameters:
pandas_arrow_dtype (ArrowDtype) – The pandas.ArrowDtype to construct TsDtype from.
- Returns:
The constructed TsDtype.
- Return type:
- Raises:
ValueError – If the given dtype is not a valid ts type.