Polars backend adapter for PlanFrame.
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
planframe-polars
Polars adapter package for PlanFrame. Import as planframe_polars.
Documentation (ReadTheDocs):
- Polars track (end users):
https://planframe.readthedocs.io/en/latest/planframe_polars/ - Light API reference:
https://planframe.readthedocs.io/en/latest/planframe_polars/reference/api/
Install
pip install planframe-polars
Usage
from planframe_polars import PolarsFrame
class User(PolarsFrame):
id: int
age: int
# Construct from python data:
pf = User({"id": [1], "age": [2]})
df = pf.select("id").collect()
# Common transforms (PlanFrame is always lazy; these build a plan until `collect()`).
pf3 = pf.with_row_index(name="row_nr").clip(lower=0, subset=("age",))
pf4 = pf.rename_upper().cast_many({"age": float})
# If you already have a Polars DataFrame/LazyFrame, use `Frame.source(...)`:
import polars as pl
pf2 = User.source(pl.DataFrame({"id": [1], "age": [2]}).lazy(), adapter=User._adapter_singleton, schema=User)
Execution model
PlanFrame is always lazy:
- Chaining methods (like
.select(...)) does not run Polars operations. collect()evaluates the full plan (and returnslist[pydantic.BaseModel]).- If you need a backend-native
polars.DataFrame/polars.LazyFrame, usecollect_backend(). - If you want to iterate rows, use
stream_dicts()/stream()(see the Streaming rows guide).
Optional API skins (core)
The core package includes typed mixins you can combine with PolarsFrame if you want a different surface API (same lazy plan underneath):
planframe.spark.SparkFrame: PySpark-like column access,withColumns,groupBy().agg(...),hint(), … — see PySpark-like API.planframe.pandas.PandasLikeFrame: pandas-like naming — see pandas-like API (the pandas adapter’sPandasFrameuses this mixin by default).
Notes (Polars-specific)
- Pivot:
LazyFrame.pivot(...)requireson_columnsto be provided up-front (Polars must know the output schema prior tocollect()). PlanFrame enforces this at execution time. - pivot_wider: wrapper around
pivot(...); for deterministic output columns on lazy sources, passon_columns. - vstack: implemented via
polars.concat(..., how="vertical"). - Join: implemented via
LazyFrame.join(...)/DataFrame.join(...)with symmetriconor asymmetricleft_on/right_on, plus optionalJoinOptionsmapped to Polars (nulls_equal,validate,coalesce,maintain_order,allow_parallel/force_parallel,streaming,engine_streamingwhen supported by the installed Polars). - Group by / agg:
group_bycompiles to Polarsgroup_bywith column or expression keys (expression keys are aliased__pf_g{i}).aggcompiles tuple reductions topl.col(...).sum()-style calls andAggExprto aggregated expressions on compiled inners (e.g.agg_sum(truediv(col("a"), col("b")))).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file planframe_polars-1.1.0.tar.gz.
File metadata
- Download URL: planframe_polars-1.1.0.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f62bf6e1ff3b50cd55e4c33edbcec173f8d45f02303b0535e2bf6e1a9943535c
|
|
| MD5 |
308dedd649211370b0862813ba0d0b22
|
|
| BLAKE2b-256 |
616cede62eebbadead26f093b491732a8364ba822590028f34af33d5b41596f7
|
File details
Details for the file planframe_polars-1.1.0-py3-none-any.whl.
File metadata
- Download URL: planframe_polars-1.1.0-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0da684da09d757898e9b8a6fded306d4eecfb0e930f0cb4292d9a5cb67e337b
|
|
| MD5 |
9903963e1f4994f380587179344795c9
|
|
| BLAKE2b-256 |
8999c58690c09327f8e1ef922e323e084dd8d75b2b9619f269b0d33ae550e242
|