Continuous distributions¶
Every continuous distribution inherits the shared method surface from ContinuousDistribution, documented first.
The concrete classes follow, alphabetically, and list only what they define or override.
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.
Output length follows the surrounding context (frame length under select / with_columns,
partition length under over / group_by). Each row's draw derives from a sub-seed mixed from
seed and the row's position, so the result is independent of 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; otherwise it 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, as Array(inner=<element dtype>, shape=size).
Each row's draws are consecutive values from one per-row stream keyed by seed and the row's
position, so samples(size=1) matches sample for the same seed and growing size extends
each row's array without changing the existing draws. A null-parameter row yields a null array
(outer validity), an invalid parameterisation raises. Named like sample, as "samples".
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; 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
Cauchy
¶
Bases: ContinuousDistribution
Cauchy distribution with location loc and scale scale.
Equivalent to scipy.stats.cauchy(loc=loc, scale=scale).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loc
|
float | IntoExprColumn
|
Location parameter, the median and the mode. Either a Python |
required |
scale
|
float | IntoExprColumn
|
Scale parameter, the half-width at half-maximum, with |
required |
Cauchy has no moments of any order, so mean(), variance() and std() are null where scipy
returns nan. All three still validate: an invalid scale raises rather than nulling.
An invalid scale (scale <= 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/_cauchy.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; it raises
InvalidOperation (a ComputeError) when any method is evaluated. The support is x >= 0:
pdf and cdf are 0 for x < 0, and sf is 1 there. A null rate nulls every
method, on the support and below it.
Source code in polars_stats/distributions/_exponential.py
LogNormal
¶
Bases: ContinuousDistribution
Log-normal distribution: X such that ln(X) is Normal(mu, sigma).
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
mean
¶
variance
¶
Variance, (exp(sigma ** 2) - 1) * exp(2 * mu + sigma ** 2).
The leading factor goes through expm1: the literal exp(sigma ** 2) - 1 cancels for a small
sigma. No cut-over is needed, the argument is positive.
Source code in polars_stats/distributions/_lognormal.py
std
¶
Standard deviation, exp(0.5 * log(exp(sigma ** 2) - 1) + mu + sigma ** 2 / 2).
Not variance().sqrt(): the variance overflows f64 above sigma ~ 18.8 (so inf is right
there), the standard deviation only above sigma ~ 26.6. std() ** 2 and variance() are
therefore not interchangeable at a large sigma.
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
Pareto
¶
Bases: ContinuousDistribution
Pareto (type I) distribution with scale scale and shape shape, on the support x >= scale.
Equivalent to scipy.stats.pareto(b=shape, scale=scale): scipy's shape b is shape here, and the two
arguments are in the opposite order, so pass both by keyword.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
float | IntoExprColumn
|
Scale parameter |
required |
shape
|
float | IntoExprColumn
|
Shape parameter |
required |
mean() is +inf for shape <= 1 and variance() / std() for shape <= 2, where the
integral diverges, as in scipy.
An invalid parameterisation (scale <= 0, shape <= 0 or a non-finite parameter) is not checked at
construction; it raises InvalidOperation (a ComputeError) when any method is evaluated. Below the support
pdf and cdf are 0 and sf is 1. A null parameter nulls every method, on the support and below it.
Source code in polars_stats/distributions/_pareto.py
mean
¶
Expected value, shape * scale / (shape - 1) for shape > 1, else +inf.
Source code in polars_stats/distributions/_pareto.py
variance
¶
Variance, scale**2 * shape / ((shape - 1)**2 * (shape - 2)) for shape > 2, else +inf.
Source code in polars_stats/distributions/_pareto.py
std
¶
Standard deviation, scale / (shape - 1) * sqrt(shape / (shape - 2)) for shape > 2, else +inf.
Not variance().sqrt(): squaring and unsquaring the scale saturates about 300 decades earlier.
Source code in polars_stats/distributions/_pareto.py
entropy
¶
Differential entropy, log(scale / shape) + 1 / shape + 1.
Summed as log(scale) - log(shape): the ratio over- and underflows where neither log does.
Source code in polars_stats/distributions/_pareto.py
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; it raises InvalidOperation (a ComputeError) when any
method is evaluated. A null bound nulls every method, on the support and off it.
Source code in polars_stats/distributions/_uniform.py
Weibull
¶
Bases: ContinuousDistribution
Weibull distribution with shape shape and scale scale, on the support x >= 0.
Equivalent to scipy.stats.weibull_min(c=shape, scale=scale): scipy's shape c is shape here.
Weibull(shape=1.0, scale=s) is Exponential(rate=1 / s).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
float | IntoExprColumn
|
Shape parameter |
required |
scale
|
float | IntoExprColumn
|
Scale parameter |
required |
An invalid parameterisation (shape <= 0, scale <= 0 or a non-finite parameter) is not checked at
construction; it raises InvalidOperation (a ComputeError) when any method is evaluated. Below the support
pdf and cdf are 0 and sf is 1. A null parameter nulls every method, on the support and below it.
Source code in polars_stats/distributions/_weibull.py
mean
¶
variance
¶
Variance, scale**2 * (Gamma(1 + 2 / shape) - Gamma(1 + 1 / shape)**2).
Squared from std(), which saturates about 300 decades later than the gamma function does.
Source code in polars_stats/distributions/_weibull.py
std
¶
entropy
¶
Differential entropy, euler_gamma * (1 - 1 / shape) + log(scale / shape) + 1.
Summed as log(scale) - log(shape): the ratio over- and underflows where neither log does.