Skip to main content

Native Polars expressions for piecewise-uniform distribution statistics

Project description

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")
)

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, and edges; the v0.1 histogram and counts names are removed.
  • The extension identity is polars_distr.piecewise_uniform.v1. Data written with the pre-contract polars_distr.distribution.v1 identity is not guaranteed to load.
  • distribution() accepts paired Array/Array and paired List/List storage. Mixed Array/List storage is rejected.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

polars_distr-0.2.1-cp311-abi3-manylinux_2_28_x86_64.whl (7.0 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ x86-64

polars_distr-0.2.1-cp311-abi3-manylinux_2_28_aarch64.whl (6.4 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ ARM64

polars_distr-0.2.1-cp311-abi3-macosx_11_0_arm64.whl (5.9 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

File details

Details for the file polars_distr-0.2.1-cp311-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for polars_distr-0.2.1-cp311-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1f1495ba2c983c964ee8065c32aaea0c8b5704ed3216c01807f775935a8e4e9d
MD5 0f6c1e40931c74f16882d338660d4c3e
BLAKE2b-256 02d9586fdf90a927608953adffddff0d885c834867186a3ed5c9decf8432c937

See more details on using hashes here.

Provenance

The following attestation bundles were made for polars_distr-0.2.1-cp311-abi3-manylinux_2_28_x86_64.whl:

Publisher: release.yml on silurian-ai/polars-distr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file polars_distr-0.2.1-cp311-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for polars_distr-0.2.1-cp311-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ac429e0dc2fc1338246f479744acf4fa213c97e0fabeeab662f6d89016af8687
MD5 a6e4900ed1865ff3790d0dfd25ebcd07
BLAKE2b-256 d27ef813fbefdfa11f722520892cf5f4e91f490fac2bb9f2f51b5c5e12bbf34d

See more details on using hashes here.

Provenance

The following attestation bundles were made for polars_distr-0.2.1-cp311-abi3-manylinux_2_28_aarch64.whl:

Publisher: release.yml on silurian-ai/polars-distr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file polars_distr-0.2.1-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for polars_distr-0.2.1-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f1281a3fd23618a8e14bb1876714749275885e421248c9827d7d92b536ed912d
MD5 7677ef52f33fa230b387be2a56eefc5a
BLAKE2b-256 22df9ae7bc5104ac32fb5938c27f22a053f272c25e3e7f777871b9c7cf488a0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for polars_distr-0.2.1-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on silurian-ai/polars-distr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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