Skip to content

Commit 0b2fa3a

Browse files
authored
polars lazyframe support added to get_dataframe (#33)
1 parent 8cbb0f0 commit 0b2fa3a

4 files changed

Lines changed: 231 additions & 418 deletions

File tree

cfa/dataops/catalog.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,17 @@ def _get_version_blobs(self, version: str = "latest") -> list:
301301
)
302302

303303
def get_dataframe(
304-
self, output="pandas", version="latest"
304+
self, output="pandas", version="latest", pl_lazy: bool = False
305305
) -> pd.DataFrame | pl.DataFrame:
306306
"""Get the data as a pandas or polars dataframe
307307
308308
Args:
309309
output (str, optional): the type of dataframe to return,
310-
either 'pandas' or 'polars'. Defaults to "pandas".
310+
either 'pandas' or 'polars'. Defaults to "pandas".
311311
version (str, optional): the version of the data to get.
312-
Defaults to "latest".
312+
Defaults to "latest".
313+
pl_lazy (bool, optional): whether to return a lazy polars dataframe.
314+
Defaults to False.
313315
314316
Raises:
315317
ValueError: if output is not 'pandas' or 'polars'
@@ -334,6 +336,8 @@ def get_dataframe(
334336
[pl.read_csv(blob) for blob in blob_files],
335337
how="vertical_relaxed",
336338
)
339+
if pl_lazy:
340+
df = df.lazy()
337341
return df
338342
elif file_ext == "json":
339343
if output in ["pandas", "pd"]:
@@ -343,6 +347,8 @@ def get_dataframe(
343347
df = pl.concat(
344348
[pl.read_json(blob) for blob in blob_files],
345349
)
350+
if pl_lazy:
351+
df = df.lazy()
346352
return df
347353
elif file_ext == "jsonl":
348354
if output in ["pandas", "pd"]:
@@ -354,6 +360,8 @@ def get_dataframe(
354360
df = pl.concat(
355361
[pl.read_ndjson(blob) for blob in blob_files],
356362
)
363+
if pl_lazy:
364+
df = df.lazy()
357365
return df
358366
elif file_ext == "parquet" or file_ext == "parq":
359367
if output in ["pandas", "pd"]:
@@ -366,6 +374,8 @@ def get_dataframe(
366374
[pl.read_parquet(pq_file) for pq_file in blob_files],
367375
how="vertical_relaxed",
368376
)
377+
if pl_lazy:
378+
df = df.lazy()
369379
return df
370380

371381
def ledger_entry(self, action: str) -> None:

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ The versioning pattern is `YYYY.MM.DD.micro(a/b/{none if release})
88

99
---
1010

11+
## [2025.10.14.0a]
12+
13+
### Added
14+
15+
- Support for getting polars LazyFrames
16+
1117
## [2025.10.03.0a]
1218

1319
### Added

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "cfa.dataops"
3-
version = "2025.10.03.0a"
3+
version = "2025.10.14.0a"
44
description = "Data cataloging, ETL, modeling, verification, and validation for CFA"
55
authors = [
66
{ name = "Phil Rogers", email = "ap66@cdc.gov" },

0 commit comments

Comments
 (0)