Continuous distributions¶
Every continuous distribution inherits the shared method surface from ContinuousDistribution (shown first); the
concrete classes follow, alphabetically. The members listed under each class include those inherited methods.
Base class¶
ContinuousDistribution
¶
Abstract base class for continuous univariate distributions.
pdf
¶
pdf(value: float | IntoExprColumn) -> Expr
Probability density function evaluated at value. Nulls and NaNs in value are propagated.
log_pdf
¶
log_pdf(value: float | IntoExprColumn) -> Expr
Natural logarithm of the pdf. Nulls and NaNs in value are propagated.
sample
¶
sample(seed: int | None = None) -> Expr
Draw one random variate per row.
Returns a column with one variate per input row, in the distribution's element dtype
(Float64, UInt64 or Boolean). Output length follows the surrounding context (frame length
under select / with_columns, partition length under over / group_by), and each row's draw
is derived from a per-row sub-seed mixed from seed and the row's position, so the result is
independent of Polars chunking and thread scheduling.
A row with an invalid parameter raises; a row with a null parameter yields null. The output is
named "sample" when every parameter is constant (the fast path); with any column-valued
parameter the name follows the first parameter expression (polars root-name semantics, so
.name.* modifiers keep working).
Source code in polars_stats/distributions/_base.py
samples
¶
Draw size random variates per row, returning Array(inner=<element dtype>, shape=size).
Each row's size draws are consecutive values from one per-row random stream keyed by seed and the
row's position, so the result is reproducible for a fixed seed and independent of Polars chunking and
thread scheduling. samples(size=1) matches sample for the same seed, and growing size extends each
row's array without changing the existing draws.
A row with a null parameter yields a null array (not an array of null elements), produced natively by the plugin via the output's outer validity; an invalid parameterisation raises.
Naming follows sample: "samples" with all-constant parameters, the first parameter
expression's root name otherwise.
Source code in polars_stats/distributions/_base.py
cdf
¶
cdf(value: float | IntoExprColumn) -> Expr
Cumulative distribution function, P(X <= value). Nulls and NaNs in value are propagated.
log_cdf
¶
log_cdf(value: float | IntoExprColumn) -> Expr
Natural logarithm of the cdf. Nulls and NaNs in value are propagated.
sf
¶
sf(value: float | IntoExprColumn) -> Expr
Survival function, P(X > value) = 1 - cdf(value). Nulls and NaNs in value are propagated.
log_sf
¶
log_sf(value: float | IntoExprColumn) -> Expr
Natural logarithm of the survival function. Nulls and NaNs in value are propagated.
ppf
¶
ppf(quantile: float | IntoExprColumn) -> Expr
Percent point function (inverse cdf).
A quantile outside [0, 1] yields null.
Nulls are propagated and a NaN quantile yields NaN, matching scipy.
Source code in polars_stats/distributions/_base.py
isf
¶
isf(quantile: float | IntoExprColumn) -> Expr
Inverse survival function, the value x with sf(x) == quantile.
Same domain contract as ppf, with the endpoints reversed: quantile outside [0, 1] yields
null, nulls propagate, NaN yields NaN.
Source code in polars_stats/distributions/_base.py
mean
abstractmethod
¶
variance
abstractmethod
¶
std
¶
median
¶
Distributions¶
Beta
¶
Bases: ContinuousDistribution
Beta distribution on [0, 1] with shape parameters a (alpha) and b (beta).
Equivalent to scipy.stats.beta(a, b). The parameter names follow scipy; statrs calls
them shape_a / shape_b.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float | IntoExprColumn
|
First shape parameter (alpha), with |
required |
b
|
float | IntoExprColumn
|
Second shape parameter (beta), with |
required |
An invalid shape (a <= 0, b <= 0, or a non-finite parameter) is not checked at construction; matching every
other distribution, it raises InvalidOperation (a ComputeError) when any method is evaluated.
Null parameters propagate to null.
The support is [0, 1]: pdf is 0 outside it, and when a shape is < 1 the density
diverges (inf or large finite values) at the corresponding boundary.
Source code in polars_stats/distributions/_beta.py
sample
¶
sample(seed: int | None = None) -> Expr
Draw one random variate per row.
Returns a column with one variate per input row, in the distribution's element dtype
(Float64, UInt64 or Boolean). Output length follows the surrounding context (frame length
under select / with_columns, partition length under over / group_by), and each row's draw
is derived from a per-row sub-seed mixed from seed and the row's position, so the result is
independent of Polars chunking and thread scheduling.
A row with an invalid parameter raises; a row with a null parameter yields null. The output is
named "sample" when every parameter is constant (the fast path); with any column-valued
parameter the name follows the first parameter expression (polars root-name semantics, so
.name.* modifiers keep working).
Source code in polars_stats/distributions/_base.py
samples
¶
Draw size random variates per row, returning Array(inner=<element dtype>, shape=size).
Each row's size draws are consecutive values from one per-row random stream keyed by seed and the
row's position, so the result is reproducible for a fixed seed and independent of Polars chunking and
thread scheduling. samples(size=1) matches sample for the same seed, and growing size extends each
row's array without changing the existing draws.
A row with a null parameter yields a null array (not an array of null elements), produced natively by the plugin via the output's outer validity; an invalid parameterisation raises.
Naming follows sample: "samples" with all-constant parameters, the first parameter
expression's root name otherwise.
Source code in polars_stats/distributions/_base.py
cdf
¶
cdf(value: float | IntoExprColumn) -> Expr
Cumulative distribution function, P(X <= value). Nulls and NaNs in value are propagated.
log_cdf
¶
log_cdf(value: float | IntoExprColumn) -> Expr
Natural logarithm of the cdf. Nulls and NaNs in value are propagated.
sf
¶
sf(value: float | IntoExprColumn) -> Expr
Survival function, P(X > value) = 1 - cdf(value). Nulls and NaNs in value are propagated.
log_sf
¶
log_sf(value: float | IntoExprColumn) -> Expr
Natural logarithm of the survival function. Nulls and NaNs in value are propagated.
ppf
¶
ppf(quantile: float | IntoExprColumn) -> Expr
Percent point function (inverse cdf).
A quantile outside [0, 1] yields null.
Nulls are propagated and a NaN quantile yields NaN, matching scipy.
Source code in polars_stats/distributions/_base.py
isf
¶
isf(quantile: float | IntoExprColumn) -> Expr
Inverse survival function, the value x with sf(x) == quantile.
Same domain contract as ppf, with the endpoints reversed: quantile outside [0, 1] yields
null, nulls propagate, NaN yields NaN.
Source code in polars_stats/distributions/_base.py
std
¶
median
¶
pdf
¶
pdf(value: float | IntoExprColumn) -> Expr
Probability density function evaluated at value. Nulls and NaNs in value are propagated.
log_pdf
¶
log_pdf(value: float | IntoExprColumn) -> Expr
Natural logarithm of the pdf. Nulls and NaNs in value are propagated.
mean
¶
variance
¶
entropy
¶
Differential entropy in nats, ln B(a, b) - (a - 1) psi(a) - (b - 1) psi(b) + (a + b - 2) psi(a + b).
Source code in polars_stats/distributions/_beta.py
Exponential
¶
Exponential(rate: float | IntoExprColumn)
Bases: ContinuousDistribution
Exponential distribution with rate rate (λ).
Equivalent to scipy.stats.expon(scale=1 / rate). The API exposes rate (the statrs
parameterisation) rather than scipy's scale = 1 / rate: it is the natural parameter and
avoids the divide-by-zero footgun of passing scale=0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate
|
float | IntoExprColumn
|
Rate parameter λ, with |
required |
An invalid rate (rate <= 0 or NaN) is not checked at construction; matching every
other distribution, it raises InvalidOperation (a ComputeError) when any method is
evaluated. A null rate propagates to null. The support is x >= 0: pdf and cdf are
0 for x < 0, and sf is 1 there.
Source code in polars_stats/distributions/_exponential.py
sample
¶
sample(seed: int | None = None) -> Expr
Draw one random variate per row.
Returns a column with one variate per input row, in the distribution's element dtype
(Float64, UInt64 or Boolean). Output length follows the surrounding context (frame length
under select / with_columns, partition length under over / group_by), and each row's draw
is derived from a per-row sub-seed mixed from seed and the row's position, so the result is
independent of Polars chunking and thread scheduling.
A row with an invalid parameter raises; a row with a null parameter yields null. The output is
named "sample" when every parameter is constant (the fast path); with any column-valued
parameter the name follows the first parameter expression (polars root-name semantics, so
.name.* modifiers keep working).
Source code in polars_stats/distributions/_base.py
samples
¶
Draw size random variates per row, returning Array(inner=<element dtype>, shape=size).
Each row's size draws are consecutive values from one per-row random stream keyed by seed and the
row's position, so the result is reproducible for a fixed seed and independent of Polars chunking and
thread scheduling. samples(size=1) matches sample for the same seed, and growing size extends each
row's array without changing the existing draws.
A row with a null parameter yields a null array (not an array of null elements), produced natively by the plugin via the output's outer validity; an invalid parameterisation raises.
Naming follows sample: "samples" with all-constant parameters, the first parameter
expression's root name otherwise.
Source code in polars_stats/distributions/_base.py
cdf
¶
cdf(value: float | IntoExprColumn) -> Expr
Cumulative distribution function, P(X <= value). Nulls and NaNs in value are propagated.
log_cdf
¶
log_cdf(value: float | IntoExprColumn) -> Expr
Natural logarithm of the cdf. Nulls and NaNs in value are propagated.
sf
¶
sf(value: float | IntoExprColumn) -> Expr
Survival function, P(X > value) = 1 - cdf(value). Nulls and NaNs in value are propagated.
log_sf
¶
log_sf(value: float | IntoExprColumn) -> Expr
Natural logarithm of the survival function. Nulls and NaNs in value are propagated.
ppf
¶
ppf(quantile: float | IntoExprColumn) -> Expr
Percent point function (inverse cdf).
A quantile outside [0, 1] yields null.
Nulls are propagated and a NaN quantile yields NaN, matching scipy.
Source code in polars_stats/distributions/_base.py
isf
¶
isf(quantile: float | IntoExprColumn) -> Expr
Inverse survival function, the value x with sf(x) == quantile.
Same domain contract as ppf, with the endpoints reversed: quantile outside [0, 1] yields
null, nulls propagate, NaN yields NaN.
Source code in polars_stats/distributions/_base.py
pdf
¶
pdf(value: float | IntoExprColumn) -> Expr
Probability density function evaluated at value. Nulls and NaNs in value are propagated.
log_pdf
¶
log_pdf(value: float | IntoExprColumn) -> Expr
Natural logarithm of the pdf. Nulls and NaNs in value are propagated.
mean
¶
variance
¶
std
¶
Standard deviation, 1 / rate, the same expression as mean.
Overrides the base-class variance().sqrt(), which squares the rate and then unsquares
it: the round trip saturates about 300 decades before 1 / rate does.
Source code in polars_stats/distributions/_exponential.py
median
¶
LogNormal
¶
Bases: ContinuousDistribution
Log-normal distribution: X such that ln(X) is Normal(mu, sigma).
Parameterised by the underlying normal's location mu and scale sigma (sigma > 0).
Equivalent to scipy.stats.lognorm(s=sigma, scale=exp(mu)) (with loc=0):
scipy's shape s is sigma and its scale is exp(mu).
The support is x > 0; pdf and cdf are 0 and sf is 1 for x <= 0, matching scipy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
float | IntoExprColumn
|
Location of the underlying normal (mean of |
0.0
|
sigma
|
float | IntoExprColumn
|
Scale of the underlying normal (std-dev of |
1.0
|
An invalid parameterisation (sigma <= 0 or a non-finite parameter) is not checked at construction;
it raises InvalidOperation (a ComputeError) when any method is evaluated.
Null parameters propagate to null.
Source code in polars_stats/distributions/_lognormal.py
sample
¶
sample(seed: int | None = None) -> Expr
Draw one random variate per row.
Returns a column with one variate per input row, in the distribution's element dtype
(Float64, UInt64 or Boolean). Output length follows the surrounding context (frame length
under select / with_columns, partition length under over / group_by), and each row's draw
is derived from a per-row sub-seed mixed from seed and the row's position, so the result is
independent of Polars chunking and thread scheduling.
A row with an invalid parameter raises; a row with a null parameter yields null. The output is
named "sample" when every parameter is constant (the fast path); with any column-valued
parameter the name follows the first parameter expression (polars root-name semantics, so
.name.* modifiers keep working).
Source code in polars_stats/distributions/_base.py
samples
¶
Draw size random variates per row, returning Array(inner=<element dtype>, shape=size).
Each row's size draws are consecutive values from one per-row random stream keyed by seed and the
row's position, so the result is reproducible for a fixed seed and independent of Polars chunking and
thread scheduling. samples(size=1) matches sample for the same seed, and growing size extends each
row's array without changing the existing draws.
A row with a null parameter yields a null array (not an array of null elements), produced natively by the plugin via the output's outer validity; an invalid parameterisation raises.
Naming follows sample: "samples" with all-constant parameters, the first parameter
expression's root name otherwise.
Source code in polars_stats/distributions/_base.py
cdf
¶
cdf(value: float | IntoExprColumn) -> Expr
Cumulative distribution function, P(X <= value). Nulls and NaNs in value are propagated.
log_cdf
¶
log_cdf(value: float | IntoExprColumn) -> Expr
Natural logarithm of the cdf. Nulls and NaNs in value are propagated.
sf
¶
sf(value: float | IntoExprColumn) -> Expr
Survival function, P(X > value) = 1 - cdf(value). Nulls and NaNs in value are propagated.
log_sf
¶
log_sf(value: float | IntoExprColumn) -> Expr
Natural logarithm of the survival function. Nulls and NaNs in value are propagated.
ppf
¶
ppf(quantile: float | IntoExprColumn) -> Expr
Percent point function (inverse cdf).
A quantile outside [0, 1] yields null.
Nulls are propagated and a NaN quantile yields NaN, matching scipy.
Source code in polars_stats/distributions/_base.py
isf
¶
isf(quantile: float | IntoExprColumn) -> Expr
Inverse survival function, the value x with sf(x) == quantile.
Same domain contract as ppf, with the endpoints reversed: quantile outside [0, 1] yields
null, nulls propagate, NaN yields NaN.
Source code in polars_stats/distributions/_base.py
pdf
¶
pdf(value: float | IntoExprColumn) -> Expr
Probability density function evaluated at value. Nulls and NaNs in value are propagated.
log_pdf
¶
log_pdf(value: float | IntoExprColumn) -> Expr
Natural logarithm of the pdf. Nulls and NaNs in value are propagated.
mean
¶
variance
¶
Variance, (exp(sigma ** 2) - 1) * exp(2 * mu + sigma ** 2).
The leading factor is spelled 2 * exp(t / 2) * sinh(t / 2), which is expm1(t)
identically. Polars has no expm1, and the literal exp(t) - 1 cancels for a small
sigma. The identity holds full precision on both sides and overflows no earlier than the
result does.
Source code in polars_stats/distributions/_lognormal.py
std
¶
Standard deviation, exp(0.5 * log(exp(sigma ** 2) - 1) + mu + sigma ** 2 / 2).
Overrides the base-class variance().sqrt(), which inherits an overflow the square root
would have undone: the variance genuinely exceeds f64 above sigma ~ 18.8 (so inf
is right there), but the standard deviation only does above sigma ~ 26.6.
Consequence worth knowing: std() ** 2 and variance() are no longer interchangeable
at a large sigma, because one is representable and the other is not.
Source code in polars_stats/distributions/_lognormal.py
median
¶
entropy
¶
Differential entropy, mu + 0.5 * log(2 * pi * e * sigma ** 2).
Normal
¶
Bases: ContinuousDistribution
Normal (Gaussian) distribution with location mu and scale sigma.
Equivalent to scipy.stats.norm(loc=mu, scale=sigma). The standard normal (mu=0, sigma=1) is the
default parameterisation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
float | IntoExprColumn
|
Location parameter. Either a Python |
0.0
|
sigma
|
float | IntoExprColumn
|
Scale parameter, with |
1.0
|
An invalid scale (sigma <= 0 or a non-finite parameter) is not checked at construction;
it raises InvalidOperation (a ComputeError) when any method is evaluated.
Null parameters propagate to null.
Source code in polars_stats/distributions/_normal.py
sample
¶
sample(seed: int | None = None) -> Expr
Draw one random variate per row.
Returns a column with one variate per input row, in the distribution's element dtype
(Float64, UInt64 or Boolean). Output length follows the surrounding context (frame length
under select / with_columns, partition length under over / group_by), and each row's draw
is derived from a per-row sub-seed mixed from seed and the row's position, so the result is
independent of Polars chunking and thread scheduling.
A row with an invalid parameter raises; a row with a null parameter yields null. The output is
named "sample" when every parameter is constant (the fast path); with any column-valued
parameter the name follows the first parameter expression (polars root-name semantics, so
.name.* modifiers keep working).
Source code in polars_stats/distributions/_base.py
samples
¶
Draw size random variates per row, returning Array(inner=<element dtype>, shape=size).
Each row's size draws are consecutive values from one per-row random stream keyed by seed and the
row's position, so the result is reproducible for a fixed seed and independent of Polars chunking and
thread scheduling. samples(size=1) matches sample for the same seed, and growing size extends each
row's array without changing the existing draws.
A row with a null parameter yields a null array (not an array of null elements), produced natively by the plugin via the output's outer validity; an invalid parameterisation raises.
Naming follows sample: "samples" with all-constant parameters, the first parameter
expression's root name otherwise.
Source code in polars_stats/distributions/_base.py
cdf
¶
cdf(value: float | IntoExprColumn) -> Expr
Cumulative distribution function, P(X <= value). Nulls and NaNs in value are propagated.
log_cdf
¶
log_cdf(value: float | IntoExprColumn) -> Expr
Natural logarithm of the cdf. Nulls and NaNs in value are propagated.
sf
¶
sf(value: float | IntoExprColumn) -> Expr
Survival function, P(X > value) = 1 - cdf(value). Nulls and NaNs in value are propagated.
log_sf
¶
log_sf(value: float | IntoExprColumn) -> Expr
Natural logarithm of the survival function. Nulls and NaNs in value are propagated.
ppf
¶
ppf(quantile: float | IntoExprColumn) -> Expr
Percent point function (inverse cdf).
A quantile outside [0, 1] yields null.
Nulls are propagated and a NaN quantile yields NaN, matching scipy.
Source code in polars_stats/distributions/_base.py
isf
¶
isf(quantile: float | IntoExprColumn) -> Expr
Inverse survival function, the value x with sf(x) == quantile.
Same domain contract as ppf, with the endpoints reversed: quantile outside [0, 1] yields
null, nulls propagate, NaN yields NaN.
Source code in polars_stats/distributions/_base.py
pdf
¶
pdf(value: float | IntoExprColumn) -> Expr
Probability density function evaluated at value. Nulls and NaNs in value are propagated.
log_pdf
¶
log_pdf(value: float | IntoExprColumn) -> Expr
Natural logarithm of the pdf. Nulls and NaNs in value are propagated.
mean
¶
variance
¶
std
¶
Standard deviation, the sigma scale parameter.
Overrides the base-class variance().sqrt(), which squares sigma and then unsquares
it: the round trip saturates across roughly 300 decades where sigma is the answer.
Source code in polars_stats/distributions/_normal.py
median
¶
entropy
¶
Uniform
¶
Bases: ContinuousDistribution
Continuous uniform distribution over [min, max].
Equivalent to scipy.stats.uniform(loc=min, scale=max - min).
Following scipy, the density, cdf and the other closed forms treat the support as the closed interval [min, max]
(so pdf(max) == 1 / (max - min)); the sample plugin draws on the half-open [min, max).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min
|
float | IntoExprColumn
|
Lower bound. Either a Python |
required |
max
|
float | IntoExprColumn
|
Upper bound, with |
required |
An invalid parameterisation (max <= min, a non-finite bound, or a width max - min
overflowing float64) is not checked at construction; matching every other distribution, it
raises InvalidOperation (a ComputeError) when any method is evaluated. Null bounds
propagate to null.
Source code in polars_stats/distributions/_uniform.py
range
property
¶
Width of the support, max - min.
Validated in Rust so an invalid parameterisation (max <= min, a non-finite bound, or a
width overflowing float64) raises rather than silently yielding a non-positive or
infinite width. Every closed-form method (moments and pdf/cdf/ppf) derives from this, so they
all validate consistently; null bounds propagate. See _checked for the scalar-vs-column
routing.
sample
¶
sample(seed: int | None = None) -> Expr
Draw one random variate per row.
Returns a column with one variate per input row, in the distribution's element dtype
(Float64, UInt64 or Boolean). Output length follows the surrounding context (frame length
under select / with_columns, partition length under over / group_by), and each row's draw
is derived from a per-row sub-seed mixed from seed and the row's position, so the result is
independent of Polars chunking and thread scheduling.
A row with an invalid parameter raises; a row with a null parameter yields null. The output is
named "sample" when every parameter is constant (the fast path); with any column-valued
parameter the name follows the first parameter expression (polars root-name semantics, so
.name.* modifiers keep working).
Source code in polars_stats/distributions/_base.py
samples
¶
Draw size random variates per row, returning Array(inner=<element dtype>, shape=size).
Each row's size draws are consecutive values from one per-row random stream keyed by seed and the
row's position, so the result is reproducible for a fixed seed and independent of Polars chunking and
thread scheduling. samples(size=1) matches sample for the same seed, and growing size extends each
row's array without changing the existing draws.
A row with a null parameter yields a null array (not an array of null elements), produced natively by the plugin via the output's outer validity; an invalid parameterisation raises.
Naming follows sample: "samples" with all-constant parameters, the first parameter
expression's root name otherwise.
Source code in polars_stats/distributions/_base.py
cdf
¶
cdf(value: float | IntoExprColumn) -> Expr
Cumulative distribution function, P(X <= value). Nulls and NaNs in value are propagated.
log_cdf
¶
log_cdf(value: float | IntoExprColumn) -> Expr
Natural logarithm of the cdf. Nulls and NaNs in value are propagated.
sf
¶
sf(value: float | IntoExprColumn) -> Expr
Survival function, P(X > value) = 1 - cdf(value). Nulls and NaNs in value are propagated.
log_sf
¶
log_sf(value: float | IntoExprColumn) -> Expr
Natural logarithm of the survival function. Nulls and NaNs in value are propagated.
ppf
¶
ppf(quantile: float | IntoExprColumn) -> Expr
Percent point function (inverse cdf).
A quantile outside [0, 1] yields null.
Nulls are propagated and a NaN quantile yields NaN, matching scipy.
Source code in polars_stats/distributions/_base.py
isf
¶
isf(quantile: float | IntoExprColumn) -> Expr
Inverse survival function, the value x with sf(x) == quantile.
Same domain contract as ppf, with the endpoints reversed: quantile outside [0, 1] yields
null, nulls propagate, NaN yields NaN.
Source code in polars_stats/distributions/_base.py
pdf
¶
pdf(value: float | IntoExprColumn) -> Expr
Probability density function evaluated at value. Nulls and NaNs in value are propagated.
log_pdf
¶
log_pdf(value: float | IntoExprColumn) -> Expr
Natural logarithm of the pdf. Nulls and NaNs in value are propagated.
mean
¶
variance
¶
std
¶
Standard deviation, (max - min) / sqrt(12).
Overrides the base-class variance().sqrt(), which squares the span and then unsquares
it: the round trip saturates about 300 decades before the answer does. Dividing by
sqrt(12) once also drops a rounding.