quantlab.backend.parquet.PlBackend#
- class quantlab.backend.parquet.PlBackend[source]#
Bases:
DataBackendParquet-backed storage for a long-format table held as a lazy frame.
datais apolars.LazyFrameproduced byscan_parquet, so reads and filters stay lazy untilwriteorget_xarray_datasetcollects them. Used for reference tables that are tabular rather than panel shaped.Examples
>>> table = PlBackend().read("universe.parquet") >>> frame = table.filter_by_symbol("symbol", ("AAPL",)).get_lazyframe() >>> frame.collect()
- filter_by_date(col, start_date, end_date)[source]#
Narrow
datain place to rows whosecollies in the range.- Parameters:
- colstr
The date column to filter on.
- start_datestr
First date to keep, inclusive.
- end_datestr
Last date to keep, inclusive.
Examples
>>> table.filter_by_date("timestamp", "2024-01-02", "2024-01-03") PlBackend() >>> table.get_lazyframe().collect().height # two days of two symbols 4
- filter_by_symbol(col, symbols)[source]#
Narrow
datain place to rows whosecolis insymbols.- Parameters:
- colstr
The column to filter on.
- symbolstuple[str, …]
The values to keep.
Examples
>>> table = PlBackend().read("universe.parquet") >>> table.filter_by_symbol("symbol", ("BBB",)) PlBackend() >>> table.get_lazyframe().collect()["symbol"].unique().to_list() ['BBB']
- get_lazyframe()[source]#
Return the held lazy frame.
Examples
>>> table.get_lazyframe().collect().shape (8, 3)
- get_xarray_dataset(indexes=None)[source]#
Collect
dataand convert it to a dataset indexed byindexes.The named columns become the dataset’s dimensions and every other column becomes a data variable.
- Parameters:
- indexeslist[str]
The columns to index by. Required: a lazy frame has no dimensions to fall back on.
- Raises:
- ValueError
If
indexesisNone.
Examples
>>> ds = table.get_xarray_dataset(["timestamp", "symbol"]) >>> tuple(ds.dims), list(ds.data_vars) (('timestamp', 'symbol'), ['close'])
- head(path, n)[source]#
Return at most
nrows scanned lazily frompath.- Parameters:
- pathstr
Path of the Parquet file.
- nint
Maximum number of rows to return.
- The limit is pushed down into the Parquet reader, and a fresh frame
- is returned without touching ``data``. The existence check is done
- here because ``scan_parquet`` on a missing file only fails at
- collect time.
- Raises:
- FileNotFoundError
If
pathdoes not exist.
Examples
>>> PlBackend().head("universe.parquet", 3).collect().shape (3, 3)
- read(path, **kwargs)[source]#
Lazily scan the Parquet file at
pathintodata.- Parameters:
- pathstr
Path of the Parquet file.
- **kwargs
Accepted for interface compatibility and ignored.
- Raises:
- FileNotFoundError
If
pathdoes not exist.
Examples
>>> table = PlBackend().read("universe.parquet") >>> type(table.data).__name__ LazyFrame
- resample(labels, how)[source]#
Aggregate the long-format frame onto the bars
labelsassigns.Rows are grouped by their label and by every non-
timestampindex column the frame has (symbol, in a panel).hownames a method for every other column. The result replacesdatalazily; nothing is collected here.- Parameters:
- labelspd.Series
Source timestamp to target timestamp; see
DataBackend.- howdict[str, str]
Column name to aggregation method, one entry per value column.
Examples
>>> table.resample(labels, {"close": "last"}) >>> table.get_lazyframe().collect().shape (2, 3)