ts_shape.loader.timeseries.parquet_loader
Classes
| Name | Description |
|---|
ParquetLoader | This class provides class methods to load parquet files from a specified directory structure. |
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
Parameters
| Name | Type | Description | Default |
|---|
base_path | str | The base directory where parquet files are stored. | required |
Raises
| Type | Description |
|---|
LoaderError | If base_path does not exist or is not a directory. |
load_all_files(base_path: str) -> pd.DataFrame
Loads all parquet files in the specified base directory into a single pandas DataFrame.
Parameters
| Name | Type | Description | Default |
|---|
base_path | str | The base directory where parquet files are stored. | required |
Returns
| Type | Description |
|---|
DataFrame | pd.DataFrame: A DataFrame containing all the data from the parquet files. |
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
| Name | Type | Description | Default |
|---|
base_path | str | The base directory where parquet files are stored. | required |
start | Timestamp | The start timestamp. | required |
end | Timestamp | The end timestamp. | required |
trim_to_range | bool | If 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
| Type | Description |
|---|
DataFrame | pd.DataFrame: A DataFrame containing the data from the parquet files within the time range. |
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
| Name | Type | Description | Default |
|---|
base_path | [str | The folder of hour folders, or a .zip export. | required |
start | Timestamp | First instant. | required |
end | Timestamp | End of the range, exclusive. | required |
chunk | str | Slice length ("1h", "6h", "1D"). | '1h' |
signal_uuids | list | None | Load only these signals (default: all). | None |
compact | bool | Shrink each slice with :func:ts_shape.utils.frames.compact_frame. | False |
Yields
| Type | Description |
|---|
DataFrame | One DataFrame per slice (slices without data are skipped). |
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
| Name | Type | Description | Default |
|---|
base_path | str | The base directory where parquet files are stored. | required |
uuid_list | list | A list of UUIDs to filter the files. | required |
Returns
| Type | Description |
|---|
DataFrame | pd.DataFrame: A DataFrame containing the data from the parquet files with matching UUIDs. |
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
| Name | Type | Description | Default |
|---|
base_path | str | The base directory where parquet files are stored. | required |
start | Timestamp | The start timestamp. | required |
end | Timestamp | The end timestamp. | required |
uuid_list | list | A list of UUIDs to filter the files. | required |
trim_to_range | bool | If 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
| Type | Description |
|---|
DataFrame | pd.DataFrame: A DataFrame containing the data from the parquet files that meet both criteria. |