Discrete distributions¶
Every discrete distribution inherits the shared method surface from DiscreteDistribution (shown first); the concrete
classes follow, alphabetically. The members listed under each class include those inherited methods.
Base class¶
DiscreteDistribution
¶
Abstract base class for discrete univariate distributions.
pmf
¶
pmf(value: float | IntoExprColumn) -> Expr
Probability mass function, P(X = value). Nulls and NaNs in value are propagated.
log_pmf
¶
log_pmf(value: float | IntoExprColumn) -> Expr
Natural logarithm of the pmf. 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¶
Bernoulli
¶
Bernoulli(p: float | IntoExprColumn)
Bases: DiscreteDistribution
Bernoulli distribution with success probability p.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float | IntoExprColumn
|
Success probability of Bernoulli distribution. Either a Python |
required |
Source code in polars_stats/distributions/_bernoulli.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
¶
pmf
¶
pmf(value: float | IntoExprColumn) -> Expr
Probability mass function, P(X = value). Nulls and NaNs in value are propagated.
log_pmf
¶
log_pmf(value: float | IntoExprColumn) -> Expr
Natural logarithm of the pmf. Nulls and NaNs in value are propagated.
mean
¶
variance
¶
entropy
¶
Shannon entropy, -p * log(p) - (1 - p) * log1p(-p).
Uses the convention 0 * log 0 = 0 so the result is 0 at the degenerate endpoints p in {0, 1}.
The second term goes through log1p for the reason in _log_pmf.
Source code in polars_stats/distributions/_bernoulli.py
Binomial
¶
Bases: DiscreteDistribution
Binomial distribution: number of successes in n trials, each with success probability p.
Equivalent to scipy.stats.binom(n, p). The argument order differs from statrs
(Binomial(p, n)); this class follows scipy's (n, p).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int | IntoExprColumn
|
Number of trials, an integer |
required |
p
|
float | IntoExprColumn
|
Success probability in |
required |
Neither parameter is validated at construction: a negative n or a p outside [0, 1]
raises InvalidOperation (a ComputeError) when a method is evaluated, identically to an
invalid column row. Construction rejects only wrong types (TypeError). Null parameters
propagate to null.
Source code in polars_stats/distributions/_binomial.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
¶
pmf
¶
pmf(value: float | IntoExprColumn) -> Expr
Probability mass function, P(X = value). Nulls and NaNs in value are propagated.
log_pmf
¶
log_pmf(value: float | IntoExprColumn) -> Expr
Natural logarithm of the pmf. Nulls and NaNs in value are propagated.
mean
¶
variance
¶
entropy
¶
Shannon entropy in nats, the exact support sum -sum_k pmf(k) log pmf(k).
0 at the degenerate endpoints p in {0, 1}.