tstore package#

Subpackages#

Submodules#

tstore.backend module#

Define possible backends for type hinting.

tstore.backend.cast_column_to_large_string(df: DataFrame | GeoDataFrame | DataFrame | DataFrame | Table, col: str) DataFrame | GeoDataFrame | DataFrame | DataFrame | Table[source]#

Cast a column to a large string type.

tstore.backend.change_backend(obj: T, new_backend: Literal['dask', 'geopandas', 'pandas', 'polars', 'pyarrow'], index_var: str | None = None, **backend_kwargs) T[source]#

Change the backend of a dataframe or a series.

If index_var is provided, the corresponding column is set as the index if the backend supports it. Otherwise, it is converted to a regular column (DataFrame) or dropped (Series).

tstore.backend.get_backend(obj: T) Literal['dask', 'geopandas', 'pandas', 'polars', 'pyarrow'][source]#

Get the backend of a dataframe or a series.

tstore.backend.get_column_names(df: DataFrame | GeoDataFrame | DataFrame | DataFrame | Table) list[str][source]#

Get the column names of a DataFrame.

tstore.backend.get_dataframe_index(df: DataFrame | GeoDataFrame | DataFrame | DataFrame | Table) str | None[source]#

Get the name of the index of a DataFrame.

tstore.backend.re_set_dataframe_index(df: DataFrame | GeoDataFrame | DataFrame | DataFrame | Table, index_var: str | None = None) DataFrame | GeoDataFrame | DataFrame | DataFrame | Table[source]#

Remove existing dataframe index and set a new one if index_var is provided.

tstore.backend.re_set_dataframe_index_decorator(func: Callable) Callable[source]#

Decorator to remove existing dataframe index and set a new one if index_var is provided.

tstore.backend.remove_dataframe_index(df: DataFrame | GeoDataFrame | DataFrame | DataFrame | Table) DataFrame | GeoDataFrame | DataFrame | DataFrame | Table[source]#

Remove the index of a DataFrame and keep it as a regular column.

Module contents#

tstore.

class tstore.TS(df: DataFrame | GeoDataFrame | DataFrame | DataFrame | Table, time_var='time')[source]#

Bases: object

TS object.

change_backend(new_backend)[source]#

Return a new TS object with the dataframe converted to a different backend.

property current_backend#

Return the backend of the wrapped dataframe.

static from_disk(fpath, partitions, backend: Literal['dask', 'geopandas', 'pandas', 'polars', 'pyarrow'] = 'dask', columns=None, start_time=None, end_time=None, inclusive=None, split_row_groups=False, calculate_divisions=True, ignore_metadata_file=False, **kwargs)[source]#

Read a time series from disk into a Dask.DataFrame.

to_disk(fpath, partitioning_str=None)[source]#

Write TS object to disk.

class tstore.TSArray(data, copy: bool = False)[source]#

Bases: ExtensionArray

An ExtensionArray for TS objects, holding the array-based implementations.

copy()[source]#

Return a copy of the array.

property dtype#

An instance of TSDtype.

isna()[source]#

A 1-D array indicating if the TS is missing.

property nbytes: int#

The number of bytes needed to store this object in memory.

take(indices, allow_fill=False, fill_value=None)[source]#

Take elements from an array.

property ts_class#

TS inner class.

class tstore.TSDF(*args, **kwargs)[source]#

Bases: TSWrapper

Wrapper for a DataFrame of TSArray objects.

change_ts_backend(new_backend: Literal['dask', 'geopandas', 'pandas', 'polars', 'pyarrow'], ts_cols: list[str] | None = None) TSDF[source]#

Return a new TSDF object with dataframes wrapped in internal TS objects converted to a different backend.

Parameters:
  • new_backend (Backend) – New backend to use for the TS objects.

  • ts_cols (Optional[list[str]]) – List of columns to convert. If None, convert all TS columns.

static from_tstore(base_dir: str, backend: Literal['dask', 'geopandas', 'pandas', 'polars', 'pyarrow'] = 'dask') TSDF[source]#

Read TStore into TSDF object.

get_ts_backend(ts_col: str) Literal['dask', 'geopandas', 'pandas', 'polars', 'pyarrow'][source]#

Return the current backend of a wrapped dataframe.

to_tslong(backend: Literal['dask', 'geopandas', 'pandas', 'polars', 'pyarrow'] = 'dask') TSLong[source]#

Convert the wrapper into a TSLong object.

to_tstore(base_dir, partitioning=None, tstore_structure='id-var', overwrite=True)[source]#

Write TStore from TSDF object.

to_tswide(backend: Literal['dask', 'geopandas', 'pandas', 'polars', 'pyarrow'] = 'dask') TSWide[source]#

Convert the wrapper into a TSWide object.

static wrap(self, df: DataFrame | GeoDataFrame | DataFrame | DataFrame | Table, id_var: str) TSDF[source]#

Wrap a DataFrame of TSArrays as a TSDF object.

Parameters:
  • df (pd.DataFrame) – DataFrame to wrap.

  • id_var (str) – Name of the column containing the identifier variable.

class tstore.TSDtype(ts_class=None)[source]#

Bases: ExtensionDtype

An ExtensionDtype for TS time series data.

classmethod construct_array_type()[source]#

Return the array type associated with this dtype.

classmethod construct_from_string(string: str)[source]#

Construct an TSDtype from a string.

Example:#

>>> TSDtype.construct_from_string("TS[pandas]")
TS['pandas']
property name: str#

A string representation of the dtype.

property ts_class: str#

The TS object class.

type#

alias of TS

class tstore.TSLong(*args, **kwargs)[source]#

Bases: TSWrapper

Abstract wrapper for a long-form timeseries DataFrame.

change_backend(new_backend: Literal['dask', 'geopandas', 'pandas', 'polars', 'pyarrow']) TSLong[source]#

Return a new wrapper with the dataframe converted to a different backend.

to_tsdf() TSDF[source]#

Convert the wrapper into a TSDF object.

to_tswide() TSWide[source]#

Convert the wrapper into a TSWide object.

static wrap(self, df: DataFrame | GeoDataFrame | DataFrame | DataFrame | Table, id_var: str, time_var: str = 'time', ts_vars: dict[str, list[str]] | list[str] | None = None, static_vars: list[str] | None = None, geometry: GeoDataFrame | None = None) TSLong[source]#

Wrap a long-form timeseries DataFrame as a TSLong object.

Parameters:
  • df (DataFrame) – DataFrame to wrap.

  • id_var (str) – Name of the column containing the identifier variable.

  • time_var (str) – Name of the column containing the time variable. Defaults to “time”.

  • ts_vars (Union[dict[str, list[str]], list[str], None]) – Dictionary of named groups of column names or list of column names (which will create one group per entry). Defaults to None, which will group all columns not in static_vars together under a group called “ts_variable”.

  • static_vars (Optional[list[str]]) – List of column names that are static across time. Defaults to None.

  • geometry (Optional[GeoPandasDataFrame]) – GeoPandas DataFrame containing geometry information for each id. Defaults to None.

class tstore.TSWide(*args, **kwargs)[source]#

Bases: TSWrapper

Abstract wrapper for a wide-form timeseries DataFrame.

to_tsdf() TSDF[source]#

Convert the wrapper into a TSDF object.

abstract to_tslong() TSLong[source]#

Convert the wrapper into a TSLong object.

static wrap(df: DataFrame | GeoDataFrame | DataFrame | DataFrame | Table, *args, **kwargs) TSWide[source]#

Wrap a DataFrame in the appropriate TSWide subclass.

tstore.open_tsdf(base_dir: str | Path, *args, backend: Literal['dask', 'geopandas', 'pandas', 'polars', 'pyarrow'] = 'dask', **kwargs)[source]#

Read a TStore file structure as a TSDF object.

tstore.open_tslong(base_dir: str | Path, *args, backend: Literal['dask', 'geopandas', 'pandas', 'polars', 'pyarrow'] = 'dask', **kwargs)[source]#

Read a TStore file structure as a TSLong object.

tstore.open_tswide(base_dir: str | Path, *args, backend: Literal['dask', 'geopandas', 'pandas', 'polars', 'pyarrow'] = 'dask', **kwargs)[source]#

Read a TStore file structure as a TSWide object.