Table Reads¶
scan_table
¶
scan_table(
location: str | Path | tuple[str | Path, ...],
columns: tuple[str, ...] | None = None,
filters: Expr | None = None,
limit: int | None = None,
) -> LazyFrame
Create a lazy parquet scan for one or more table locations.
Parameters:
-
location(str | Path | tuple[str | Path, ...]) –One parquet location, or a tuple of locations to scan as one lazy frame.
-
columns(tuple[str, ...] | None, default:None) –Optional columns to select from the scan.
-
filters(Expr | None, default:None) –Optional Polars expression applied to the lazy frame.
-
limit(int | None, default:None) –Optional maximum number of rows to read.
Returns:
-
LazyFrame–Polars lazy frame for the selected parquet data.
Examples:
Load selected manifest rows without materializing unrelated columns:
>>> manifest = store.scan_table(
... "manifest.parquet",
... columns=("protocol", "segments"),
... filters=pl.col("protocol") == "cycling",
... ).collect()
Source code in batgrad/storage/local.py
iter_table_chunks
¶
iter_table_chunks(
location: str | Path | tuple[str | Path, ...],
chunk_rows: int,
columns: tuple[str, ...] | None = None,
filters: Expr | None = None,
) -> Iterator[DataFrame]
Yield sequential parquet batches from one or more complete tables.
This method streams every row from each table in order, with batches of
at most chunk_rows before any optional filter is applied. Use it when
a stage should process a complete table without loading it all into
memory.
Parameters:
-
location(str | Path | tuple[str | Path, ...]) –One parquet location, or a tuple of locations to process in order.
-
chunk_rows(int) –Maximum number of rows requested per parquet batch before filtering.
-
columns(tuple[str, ...] | None, default:None) –Optional columns to read from the parquet file.
-
filters(Expr | None, default:None) –Optional Polars expression applied to each batch after it is read.
Yields:
-
DataFrame–Non-empty dataframe chunks.
Raises:
-
ValueError–If
chunk_rowsis less than one.
Examples:
Consume a scratch table in bounded-size chunks before deleting it:
>>> for chunk in store.iter_table_chunks(temp_path, chunk_rows):
... writer.append(chunk, metadata, source_paths)
>>> store.delete_file(temp_path, missing_ok=True)
Source code in batgrad/storage/local.py
iter_table_slices
¶
iter_table_slices(
location: str | Path,
slices: tuple[tuple[int, int], ...],
chunk_rows: int,
columns: tuple[str, ...] | None = None,
) -> Iterator[DataFrame]
Yield selected row windows from a single parquet table.
Unlike iter_table_chunks, this method does not scan the whole table. It
reads only row groups that overlap the requested slices and emits the
selected rows in chunks of at most chunk_rows. Use it for
manifest segments or sharded selections that reference specific row
ranges.
Parameters:
-
location(str | Path) –Parquet table location to read from.
-
slices(tuple[tuple[int, int], ...]) –Row windows as
(row_start, row_count)tuples. -
chunk_rows(int) –Maximum number of rows yielded per chunk.
-
columns(tuple[str, ...] | None, default:None) –Optional columns to read from the parquet file.
Yields:
-
DataFrame–Non-empty dataframe chunks for the requested row windows.
Raises:
-
ValueError–If
chunk_rowsis less than one.
Examples:
Read a manifest segment that points to a row range in a shard:
>>> slices = ((row_start, row_count),)
>>> for chunk in store.iter_table_slices(path, slices, 100_000):
... process(chunk)