polars-distr
Native Polars expressions for statistics over piecewise-uniform distributions. The plugin computes means, CDF values, quantiles, and exact CRPS inside lazy and streaming query plans without Python UDFs.
Install with uv add polars-distr or pip install polars-distr.
import polars as pl
import polars_distr as pld # registers the Distribution dtype
result = (
pl.scan_parquet("distributions.parquet")
.select(
pld.quantiles("distribution", [0.1, 0.5, 0.9]).alias("quantiles"),
pld.crps("distribution", "observation").alias("crps"),
)
.collect(engine="streaming")
)
The .distr accessor
Importing the package also registers a .distr expression namespace that delegates
to these same functions:
pl.col("weights").distr.quantile(0.5, edges="edges")
pl.struct(weights="weights", edges="edges").distr.crps("observation")
It adds no semantics. It exists for callers that can only reach registered Polars
namespaces and cannot import this package — notably YAML/JSON pipeline configs whose
expression strings are evaluated with pl alone in scope. The subject is a
Distribution column or raw Struct{weights, edges} storage; passing edges
instead treats the subject as the weights, so a config never has to spell out
pl.struct(...).
Named quantiles
Pass quantiles() a sequence of levels for a fixed-size Array in request order, or
a name-to-level mapping for a Struct in mapping order — the same single traversal
either way:
result = frame.select(
pld.quantiles("distribution", {"p10": 0.1, "p50": 0.5, "p90": 0.9}).alias("q")
).unnest("q") # -> p10, p50, p90 columns
Values and ordering are identical target for target. Validity differs in shape only:
where the sequence form nulls the outer Array row, the mapping form yields a
non-null Struct whose every field is null, so the unnested columns keep the row and
carry the null per target.
Constructing distributions
distribution() accepts either paired fixed-width Array columns or paired
variable-width List columns:
distribution = pld.distribution("weights", "edges")
It produces the logical Distribution dtype with serialized identity
polars_distr.piecewise_uniform.v1. Its storage is a Struct with exactly
weights and edges, in that order. Fixed storage must be Array/Array with edge
width equal to weight width plus one. Ragged storage must be List/List. Mixed layouts
are rejected by the constructor and statistics kernels.
Integer, Float32, and Float64 child values are supported. Invalid distribution rows produce null results; statically invalid schemas raise during schema resolution. Raw paired Struct storage is also accepted by every statistics kernel for interoperability.
v0.2 breaking changes
- The public vocabulary is
distribution,weights, andedges; the v0.1histogramandcountsnames are removed. - The extension identity is
polars_distr.piecewise_uniform.v1. Data written with the pre-contractpolars_distr.distribution.v1identity is not guaranteed to load. distribution()accepts paired Array/Array and paired List/List storage. Mixed Array/List storage is rejected.
Release files for polars-distr 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| polars_distr-0.3.0-cp311-abi3-manylinux_2_28_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.28+ x86-64 | Details |
| polars_distr-0.3.0-cp311-abi3-manylinux_2_28_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.28+ ARM64 | Details |
| polars_distr-0.3.0-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details |
Total release size: 19.2 MB
Release files / polars_distr-0.3.0-cp311-abi3-manylinux_2_28_x86_64.whl
| Download URL | polars_distr-0.3.0-cp311-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 7.0 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
622c0569a98749e38d1b336d5124bd550a9073ce8cfa4a6e0a27f7bab4b42308
|
|
BLAKE2b-256 checksum How to use checksums |
3beae4e2e084947c5f580194804709f02fbd4894b7240a7728072abfd2e9554b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 19, 2026.
Transparency logRelease files / polars_distr-0.3.0-cp311-abi3-manylinux_2_28_aarch64.whl
| Download URL | polars_distr-0.3.0-cp311-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 6.4 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
e1a41a419bc67246329c29c3cdfb9cb52bf5518ba6f3608349a6a5a8ac4fa426
|
|
BLAKE2b-256 checksum How to use checksums |
d8e5dc7d305932e361f4f7c250cc56d868c6c21aa0dbd52c03a195b0cc04aa01
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 19, 2026.
Transparency logRelease files / polars_distr-0.3.0-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | polars_distr-0.3.0-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.9 MB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
d4d07f0d507aef8d2985c41a5b86575e2852b2e7317eec40f80c694b5ae46b14
|
|
BLAKE2b-256 checksum How to use checksums |
b878c210c47a1b21c7df865b14d06fe4414a83d1d0cb18dcd151f97c0cce1d9c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 19, 2026.
Transparency log