Skip to main content

Statistical distributions as native Polars expressions — PDF, CDF, PPF, SF, and sampling for 20+ distributions, powered by Rust.

Project description

polars-sdist

Statistical distributions as native Polars expressions. Built with Rust and PyO3 for zero-copy, vectorized computation over Polars DataFrames.

Install

pip install polars-sdist

Quick start

import polars as pl
from polars_sdist import SdistNamespace as sdist

df = pl.DataFrame({"x": [-1.96, 0.0, 1.96]})

# CDF, PDF, PPF, SF, ln_pdf — all as expressions
df.with_columns(
    cdf=sdist(pl.col("x")).normal_cdf(mu=0, sigma=1),
    pdf=sdist(pl.col("x")).normal_pdf(mu=0, sigma=1),
    sf=sdist(pl.col("x")).normal_sf(mu=0, sigma=1),
)

Inverse CDF (PPF)

df = pl.DataFrame({"p": [0.025, 0.5, 0.975]})
df.with_columns(
    z=sdist(pl.col("p")).normal_ppf(mu=0, sigma=1),
)

Discrete distributions

df = pl.DataFrame({"k": [0, 1, 2, 3, 4, 5]}).cast({"k": pl.Float64})
df.with_columns(
    pmf=sdist(pl.col("k")).poisson_pmf(lambda_=3.0),
    cdf=sdist(pl.col("k")).poisson_cdf(lambda_=3.0),
)

Random sampling (fixed parameters)

import polars_sdist

s = polars_sdist.sample_normal(n=10_000, mu=0, sigma=1, seed=42)
s = polars_sdist.sample_beta(n=10_000, alpha=2, beta=5, seed=42)

Random sampling (column parameters)

df = pl.DataFrame({
    "mu": [0.0, 10.0, -10.0],
    "sigma": [1.0, 0.5, 2.0],
})
df.with_columns(
    sample=sdist(pl.col("mu")).sample_normal(sigma=pl.col("sigma"), seed=42),
)

Supported distributions

Continuous

Distribution Parameters PDF CDF PPF SF ln_pdf
Normal mu, sigma x x x x x
Log-Normal mu, sigma x x x x x
Beta alpha, beta x x x x x
Gamma shape, rate x x x x x
Exponential lambda_ x x x x x
Cauchy location, scale x x x x x
Chi-Squared df x x x x x
Student's t df x x x x x
Fisher-Snedecor (F) d1, d2 x x x x x
Gumbel location, scale x x x x x
Inverse Gamma shape, scale x x x x x
Laplace location, scale x x x x x
Pareto shape, scale x x x x x
Triangular min, max, mode x x x x x
Uniform a, b x x x x x
Weibull shape, scale x x x x x

Discrete

Distribution Parameters PMF CDF PPF SF
Bernoulli p x x x x
Binomial n, p x x x x
Geometric p x x x x
Hypergeometric pop_size, success_states, draws x x x x
Negative Binomial r, p x x x x
Poisson lambda_ x x x x
Discrete Uniform a, b x x x x

Sampling-only

These distributions support random sampling but not PDF/CDF:

PERT, Skew-Normal, Inverse Gaussian, Frechet, Zeta, Zipf

Performance

Benchmarked end-to-end against scipy/numpy on 1M elements. Median of 5 runs after warmup.

Distribution Operation polars-sdist scipy Speedup
normal pdf 8.6 ms 36.8 ms 4.3x
normal ppf 20.9 ms 48.4 ms 2.3x
normal sample 3.6 ms 7.6 ms 2.1x
normal cdf 23.3 ms 37.2 ms 1.6x
lognormal pdf 17.1 ms 63.8 ms 3.7x
lognormal sample 7.2 ms 12.7 ms 1.8x
lognormal ppf 27.8 ms 42.3 ms 1.5x
lognormal cdf 32.5 ms 41.4 ms 1.3x
binomial pmf 32.0 ms 86.2 ms 2.7x
binomial sample 20.1 ms 30.5 ms 1.5x
chi-squared sample 10.0 ms 16.7 ms 1.7x
chi-squared pdf 49.2 ms 60.9 ms 1.2x
chi-squared cdf 90.3 ms 110.9 ms 1.2x
beta ppf 517.8 ms 601.1 ms 1.2x
beta pdf 80.3 ms 89.5 ms 1.1x

polars-sdist is faster in 15 of 19 benchmarks. Areas where scipy is faster (beta CDF/sample, chi-squared PPF, binomial CDF) use highly optimized C/Fortran special-function implementations.

Run it yourself:

pip install scipy
python benchmarks/bench_distributions.py --sizes 1000000

License

MIT

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

polars_sdist-0.1.1.tar.gz (38.1 kB view details)

Uploaded Source

Built Distributions

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

polars_sdist-0.1.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

polars_sdist-0.1.1-cp39-abi3-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.9+Windows x86-64

polars_sdist-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

polars_sdist-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

polars_sdist-0.1.1-cp39-abi3-macosx_11_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

polars_sdist-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file polars_sdist-0.1.1.tar.gz.

File metadata

  • Download URL: polars_sdist-0.1.1.tar.gz
  • Upload date:
  • Size: 38.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for polars_sdist-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2720efd6dfaca6e0d0e839b933e3de7b1d32cbc11c65b6b0643645039cd1f3d2
MD5 6de72638ec5b3ed3ec5f881ae8f4ef2d
BLAKE2b-256 4ace1858cce0724e3c731377422a891243bebe6c9dd3986eb7aac1b96bee3b12

See more details on using hashes here.

Provenance

The following attestation bundles were made for polars_sdist-0.1.1.tar.gz:

Publisher: release.yml on mattbuck85/polars-sdist

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_sdist-0.1.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for polars_sdist-0.1.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7c5c371d22ed61dd807c117ecc393e43908d6848246cda1b3358dab0b6bee98e
MD5 fc16f9ef82fcd245227d091e4dda7f09
BLAKE2b-256 4be32126c37a2d4b3b160b2ff357a02c36550a3f6f5345a3b2fb717c4be4478e

See more details on using hashes here.

Provenance

The following attestation bundles were made for polars_sdist-0.1.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on mattbuck85/polars-sdist

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_sdist-0.1.1-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: polars_sdist-0.1.1-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 4.6 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for polars_sdist-0.1.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 dd18bddaaac491701571e48054c4cd2104e5dd11029d5bf73241b9b73fe1cf4d
MD5 12403584880ee4272e3a2bbadc49c819
BLAKE2b-256 1248fa36bcd542aa428356f37a7390801fcd7701ba284670c8ee5b81195a3451

See more details on using hashes here.

Provenance

The following attestation bundles were made for polars_sdist-0.1.1-cp39-abi3-win_amd64.whl:

Publisher: release.yml on mattbuck85/polars-sdist

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_sdist-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for polars_sdist-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2b94f0868d9a921bf408e528114120ea98fa2e6da2a557d51d4638bc6b6720f7
MD5 15271906808da411215ca6707c50bbb8
BLAKE2b-256 fe8b428e1d06b540828c69c5f1266a5e22b68de556b8e24c2b17c9d160199509

See more details on using hashes here.

Provenance

The following attestation bundles were made for polars_sdist-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on mattbuck85/polars-sdist

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_sdist-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for polars_sdist-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2f7546ee8c75cfbdaf8f499f9ac74d89bd5626915fed6fa6201e8ecffb88d6a7
MD5 0da4f2e0c0d05eb7a9ee2b8131b2b837
BLAKE2b-256 7b34176c8abd45dd0f92caa0a6008a4187111ee98ced3ff99c72cd87d9459178

See more details on using hashes here.

Provenance

The following attestation bundles were made for polars_sdist-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on mattbuck85/polars-sdist

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_sdist-0.1.1-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for polars_sdist-0.1.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 284f44ef2b46c2d371fe437b679f5f0b7adc8889ddea92e02187c8b3dbd1e895
MD5 aa80ce2e397d9c92915910078d0d9578
BLAKE2b-256 3b166dc62757ee40c502d7e3079656610e13777fceea4c07a8ee6e0975d22cd0

See more details on using hashes here.

Provenance

The following attestation bundles were made for polars_sdist-0.1.1-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on mattbuck85/polars-sdist

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_sdist-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for polars_sdist-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 2c77f01b7d6521644b293b2eaa8229bf4d949b454f341c05e746b0423f21737a
MD5 10c4be0b4b3d6c97913d161dce442155
BLAKE2b-256 c73286d2c5d6d396db0b158613d63824cf0dc2cdac9ac999db589b070d77d3f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for polars_sdist-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on mattbuck85/polars-sdist

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