Skip to main content
Version: Next

ts_shape.loader.timeseries.parquet_loader

Classes
NameDescription
ParquetLoaderThis class provides class methods to load parquet files from a specified directory structure.

ParquetLoader​

classsource
ParquetLoader(base_path: str)

This class provides class methods to load parquet files from a specified directory structure.

base_path is a folder of YYYY/MM/DD/HH/<uuid>.parquet files, or a .zip export of such a folder (read in place, no unpacking).

Example

Files are named <uuid>.parquet in YYYY/MM/DD/HH folders:

>>> import tempfile
>>> from pathlib import Path
>>> import ts_shape
>>> from ts_shape import ParquetLoader
>>> tmp = tempfile.TemporaryDirectory()
>>> folder = Path(tmp.name, "2025", "01", "01", "00")
>>> folder.mkdir(parents=True)
>>> ts_shape.make_timeseries(["temp"], n_points=3, freq="1min", noise=0).to_parquet(
... folder / "temp.parquet")
>>> ParquetLoader.load_by_uuid_list(tmp.name, ["temp"])[
... ["systime", "uuid", "value_double"]]
systime uuid value_double
0 2025-01-01 00:00:00 temp 100.0
1 2025-01-01 00:01:00 temp 100.0
2 2025-01-01 00:02:00 temp 100.0
>>> tmp.cleanup()
Functions
NameDescription
load_all_filesLoads all parquet files in the specified base directory into a single pandas DataFrame.
load_by_time_rangeLoads parquet files that fall within a specified time range based on the directory structure.
stream_by_time_rangeLoad [start, end) one slice at a time (for month-scale data).
load_by_uuid_listLoads parquet files that match any UUID in the specified list.
load_files_by_time_range_and_uuidsLoads parquet files that fall within a specified time range and match any UUID in the list.
Parameters
NameTypeDescriptionDefault
base_pathstrThe base directory where parquet files are stored.required
Raises
TypeDescription
LoaderErrorIf base_path does not exist or is not a directory.

load_all_files​

classmethodsource
load_all_files(base_path: str) -> pd.DataFrame

Loads all parquet files in the specified base directory into a single pandas DataFrame.

Parameters
NameTypeDescriptionDefault
base_pathstrThe base directory where parquet files are stored.required
Returns
TypeDescription
DataFramepd.DataFrame: A DataFrame containing all the data from the parquet files.

load_by_time_range​

classmethodsource
load_by_time_range(
base_path: str,
start: pd.Timestamp,
end: pd.Timestamp,
*,
trim_to_range: bool = True
) -> pd.DataFrame

Loads parquet files that fall within a specified time range based on the directory structure.

The directory structure is expected to be in the format YYYY/MM/DD/HH (UTC). The hour folder that contains start is included; tz-aware bounds are converted to UTC, naive ones are taken as UTC.

Parameters
NameTypeDescriptionDefault
base_pathstrThe base directory where parquet files are stored.required
startTimestampThe start timestamp.required
endTimestampThe end timestamp.required
trim_to_rangeboolIf True (default), drop rows whose systime falls outside [start, end] (both bounds inclusive; naive bounds are UTC). Frames without a systime column are left as read. False keeps whole hour folders.True
Returns
TypeDescription
DataFramepd.DataFrame: A DataFrame containing the data from the parquet files within the time range.

stream_by_time_range​

classmethodsource
stream_by_time_range(
base_path: str,
start: pd.Timestamp,
end: pd.Timestamp,
*,
chunk: str = "1h",
signal_uuids: list | None = None,
compact: bool = False
) -> Iterator[pd.DataFrame]

Load start, end) one slice at a time (for month-scale data).

A month of a large line does not fit in memory at once; this yields one frame per chunk (via :func:ts_shape.stream.time_range_source), ready for :func:ts_shape.run_chunked::

for frame in ParquetLoader.stream_by_time_range(path, t0, t1, chunk="6h"):
...
Parameters
NameTypeDescriptionDefault
base_path[strThe folder of hour folders, or a .zip export.required
startTimestampFirst instant.required
endTimestampEnd of the range, exclusive.required
chunkstrSlice length ("1h", "6h", "1D").'1h'
signal_uuidslist | NoneLoad only these signals (default: all).None
compactboolShrink each slice with :func:ts_shape.utils.frames.compact_frame.False
Yields
TypeDescription
DataFrameOne DataFrame per slice (slices without data are skipped).

load_by_uuid_list​

classmethodsource
load_by_uuid_list(base_path: str, uuid_list: list) -> pd.DataFrame

Loads parquet files that match any UUID in the specified list.

A file matches when its name without .parquet equals a UUID (exact match, not a substring).

Parameters
NameTypeDescriptionDefault
base_pathstrThe base directory where parquet files are stored.required
uuid_listlistA list of UUIDs to filter the files.required
Returns
TypeDescription
DataFramepd.DataFrame: A DataFrame containing the data from the parquet files with matching UUIDs.

load_files_by_time_range_and_uuids​

classmethodsource
load_files_by_time_range_and_uuids(
base_path: str,
start: pd.Timestamp,
end: pd.Timestamp,
uuid_list: list,
*,
trim_to_range: bool = True
) -> pd.DataFrame

Loads parquet files that fall within a specified time range and match any UUID in the list.

The directory structure is expected to be in the format YYYY/MM/DD/HH (UTC; the hour folder that contains start is included), and a file matches when its name without .parquet equals a UUID.

Parameters
NameTypeDescriptionDefault
base_pathstrThe base directory where parquet files are stored.required
startTimestampThe start timestamp.required
endTimestampThe end timestamp.required
uuid_listlistA list of UUIDs to filter the files.required
trim_to_rangeboolIf True (default), drop rows whose systime falls outside [start, end] (both bounds inclusive; naive bounds are UTC). Frames without a systime column are left as read. False keeps whole hour folders.True
Returns
TypeDescription
DataFramepd.DataFrame: A DataFrame containing the data from the parquet files that meet both criteria.