Skip to main content
Version: Next

ts_shape.loader.timeseries.timescale_loader

Classes
NameDescription
TimescaleDBDataAccessLoad timeseries data for given UUIDs and a time range from TimescaleDB.

TimescaleDBDataAccess​

classsource
TimescaleDBDataAccess(
start: str, end: str, uuids: list[str], db_config: dict[str, Any]
)

Load timeseries data for given UUIDs and a time range from TimescaleDB.

Needs the postgres extra (pip install ts-shape[postgres]: SQLAlchemy and the psycopg2 driver). Creating the loader does not connect; the first fetch does. repr(loader) masks the password.

Functions
NameDescription
fetch_data_as_parquetRetrieve timeseries data from TimescaleDB and save it as Parquet files.
fetch_data_as_dataframeRetrieve timeseries data from TimescaleDB as a single DataFrame.
Parameters
NameTypeDescriptionDefault
startstrStart of the time range (inclusive) to query.required
endstrEnd of the time range (inclusive) to query.required
uuidslist[str]List of UUIDs to retrieve data for.required
db_configdict[str, Any]Connection settings with the keys db_user, db_pass, db_host and db_name, and optionally db_port (default 5432) and db_driver (the DB-API driver, default "psycopg2"). The password is used as is; it needs no URL escaping.required
Raises
TypeDescription
ImportErrorSQLAlchemy or the database driver is not installed.

fetch_data_as_parquet​

methodsource
fetch_data_as_parquet(output_dir: str) -> None

Retrieve timeseries data from TimescaleDB and save it as Parquet files.

Rows are grouped by the hour of systime and written to one file per UUID and hour at <output_dir>/year/month/day/hour/<uuid>.parquet.

Parameters
NameTypeDescriptionDefault
output_dirstrBase directory to save the Parquet files.required

fetch_data_as_dataframe​

methodsource
fetch_data_as_dataframe() -> pd.DataFrame

Retrieve timeseries data from TimescaleDB as a single DataFrame.

Returns
TypeDescription
DataFrameA combined DataFrame with data for all specified UUIDs within the time
DataFramerange.