Skip to main content

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

Docs PyPI License: MIT

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 returns list[pydantic.BaseModel]).
  • If you need a backend-native polars.DataFrame / polars.LazyFrame, use collect_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’s PandasFrame uses this mixin by default).

Notes (Polars-specific)

  • Pivot: LazyFrame.pivot(...) requires on_columns to be provided up-front (Polars must know the output schema prior to collect()). PlanFrame enforces this at execution time.
  • pivot_wider: wrapper around pivot(...); for deterministic output columns on lazy sources, pass on_columns.
  • vstack: implemented via polars.concat(..., how="vertical").
  • Join: implemented via LazyFrame.join(...) / DataFrame.join(...) with symmetric on or asymmetric left_on / right_on, plus optional JoinOptions mapped to Polars (nulls_equal, validate, coalesce, maintain_order, allow_parallel / force_parallel, streaming, engine_streaming when supported by the installed Polars).
  • Group by / agg: group_by compiles to Polars group_by with column or expression keys (expression keys are aliased __pf_g{i}). agg compiles tuple reductions to pl.col(...).sum()-style calls and AggExpr to aggregated expressions on compiled inners (e.g. agg_sum(truediv(col("a"), col("b")))).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

planframe_polars-1.0.0.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

planframe_polars-1.0.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file planframe_polars-1.0.0.tar.gz.

File metadata

  • Download URL: planframe_polars-1.0.0.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for planframe_polars-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fa8cc396017054a05eafadaf55a71154a3caa1d0519f51003b3ab72c3e0d6481
MD5 eea3d60e9756ab43621d26f1c20d0851
BLAKE2b-256 c62edf619b039b1bea3e450fb8a965b795b1bb8f02714fd78fafe6e82a9c22e5

See more details on using hashes here.

File details

Details for the file planframe_polars-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for planframe_polars-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 08860e319475fd1e97d3a0350893808b4c65513f9b69d58951356469a1d4a531
MD5 7a6a8c870fcd480f779df2bf7d9d1c4f
BLAKE2b-256 d66a150fc88e6b37fa538e7644c56718c08bba467bbe78d8d39272abec2d185a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page