Expr
Namespace: Polars.FSharp
Represents a Polars Expression (lazy evaluation). Expressions are the building blocks of Polars queries, representing columns, literals, or transformations.
Sub-namespaces
| Sub-namespace | Page | Description |
|---|---|---|
.Array | Expr.Array | Access array operations. |
.Bin | Expr.Bin | Access binary operations. |
.Cat | Expr.Cat | Access categorical operations. |
.Dt | Expr.Dt | Access temporal (date/time) operations. |
.Ext | Expr.Ext | Access extension datatype operations. |
.List | Expr.List | Access list operations. |
.Meta | Expr.Meta | Access meta operations. |
.Name | Expr.Name | Access naming operations (prefix/suffix). |
.Str | Expr.Str | Access string manipulation operations. |
.Struct | Expr.Struct | Access struct operations. |
Constructors & Static Methods
AsStruct
Create a Struct expression from a list of expressions.
static member AsStruct(exprs: seq<Expr>) : ExprParameters
| Name | Type | Description |
|---|---|---|
exprs | seq<Expr> | - |
ConcatExpr
Concat multiple expressions into a single expression.
static member ConcatExpr(exprs: seq<Expr>, ?rechunk: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
exprs | seq<Expr> | - |
rechunk | bool (optional) | - |
ConcatString
Concat multiple string expressions into a single string expression.
static member ConcatString(exprs: seq<Expr>, ?separator: string, ?ignoreNulls: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
exprs | seq<Expr> | - |
separator | string (optional) | - |
ignoreNulls | bool (optional) | - |
FormatString
Format multiple string expressions into a single formated string expression.
static member FormatString(format: string, exprs: seq<Expr>) : ExprParameters
| Name | Type | Description |
|---|---|---|
format | string | - |
exprs | seq<Expr> | - |
SqlExpr
Create a Polars Expr from a SQL string.
static member SqlExpr(sql: string) : ExprParameters
| Name | Type | Description |
|---|---|---|
sql | string | The SQL expression string. |
Returns: A Polars Expr representing the SQL logic.
SqlExprs
Create an array of Polars Exprs from a collection of SQL strings.
static member SqlExprs(sqls: seq<string>) : Expr[]Parameters
| Name | Type | Description |
|---|---|---|
sqls | seq<string> | The collection of SQL expression strings. |
Returns: An array of Polars Expr objects.
Operators
( + ) Addition
static member op_Addition(lhs: Expr, rhs: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
lhs | Expr | - |
rhs | Expr | - |
( ! ) Logical NOT
Logical NOT.
static member op_Dereference(e: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
e | Expr | - |
( / ) Division
static member op_Division(lhs: Expr, rhs: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
lhs | Expr | - |
rhs | Expr | - |
( .&& ) Logical AND
Logical AND.
static member op_DotAmpAmp(lhs: Expr, rhs: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
lhs | Expr | - |
rhs | Expr | - |
( .!= ) Not Equal
Not equal comparison.
static member op_DotBangEquals(lhs: Expr, rhs: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
lhs | Expr | - |
rhs | Expr | - |
( .|| ) Logical OR
Logical OR.
static member op_DotBarBar(lhs: Expr, rhs: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
lhs | Expr | - |
rhs | Expr | - |
( .== ) Equal
Equal comparison.
static member op_DotEqualsEquals(lhs: Expr, rhs: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
lhs | Expr | - |
rhs | Expr | - |
( .> ) Greater Than
Greater than comparison.
static member op_DotGreater(lhs: Expr, rhs: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
lhs | Expr | - |
rhs | Expr | - |
( .>= ) Greater Or Equal
Greater than or equal comparison.
static member op_DotGreaterEquals(lhs: Expr, rhs: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
lhs | Expr | - |
rhs | Expr | - |
( .^ ) Bitwise XOR
static member op_DotHat(lhs: Expr, rhs: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
lhs | Expr | - |
rhs | Expr | - |
( .< ) Less Than
Less than comparison.
static member op_DotLess(lhs: Expr, rhs: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
lhs | Expr | - |
rhs | Expr | - |
( .<= ) Less Or Equal
Less than or equal comparison.
static member op_DotLessEquals(lhs: Expr, rhs: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
lhs | Expr | - |
rhs | Expr | - |
( .** ) Power
Power / Exponentiation.
static member op_DotMultiplyMultiply(baseExpr: Expr, exponent: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
baseExpr | Expr | - |
exponent | Expr | - |
( <<< ) Left Shift
Bitwise left shift operator (expr <<< n).
static member op_LeftShift(lhs: Expr, rhs: int) : ExprParameters
| Name | Type | Description |
|---|---|---|
lhs | Expr | - |
rhs | int | - |
( % ) Modulus
static member op_Modulus(lhs: Expr, rhs: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
lhs | Expr | - |
rhs | Expr | - |
( * ) Multiply
static member op_Multiply(lhs: Expr, rhs: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
lhs | Expr | - |
rhs | Expr | - |
( >>> ) Right Shift
Bitwise right shift operator (expr >>> n).
static member op_RightShift(lhs: Expr, rhs: int) : ExprParameters
| Name | Type | Description |
|---|---|---|
lhs | Expr | - |
rhs | int | - |
( - ) Subtraction
static member op_Subtraction(lhs: Expr, rhs: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
lhs | Expr | - |
rhs | Expr | - |
( ~- ) UnaryNegation
Negates the expression numerically.
static member op_UnaryNegation(e: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
e | Expr | - |
Instance Methods
Abs
Calculate the absolute value of the expression.
member Abs : unit -> ExprAlias
Rename the output column.
member Alias(name: string) : ExprParameters
| Name | Type | Description |
|---|---|---|
name | string | - |
All
Check if all values in the boolean expression are true.
This is a boolean aggregation.
member All(?ignoreNulls: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
ignoreNulls | bool (optional) | If true, null values are ignored. If false (default), the result propagates nulls (i.e., if there is a null and no false, the result might be null). |
Returns: A new expression representing the boolean result.
Any
Check if any value in the boolean expression is true.
This is a boolean aggregation.
member Any(?ignoreNulls: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
ignoreNulls | bool (optional) | If true, null values are ignored. If false (default), the result propagates nulls. |
Returns: A new expression representing the boolean result.
Append
Append expressions. This is done by adding the chunks of other to this Series.
member Append(other: Expr, ?execUpcast: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
other | Expr | Expression to append. |
execUpcast | bool (optional) | Cast both Series to the same supertype. |
ApproxNUnique
Approximate count of unique values. This is done using the HyperLogLog++ algorithm for cardinality estimation.
member ApproxNUnique : unit -> ExprArcCos
Compute the arccos of each element.
member ArcCos : unit -> ExprArcCosh
Compute the arccosh of each element.
member ArcCosh : unit -> ExprArcSin
Compute the arcsin of each element.
member ArcSin : unit -> ExprArcSinh
Compute the arcsinh of each element.
member ArcSinh : unit -> ExprArcTan
Compute the arctan of each element.
member ArcTan : unit -> ExprArcTanh
Compute the arctanh of each element.
member ArcTanh : unit -> ExprArgMax
Get the index of the maximum value.
member ArgMax : unit -> ExprArgMin
Get the index of the minimum value.
member ArgMin : unit -> ExprArgSort
Get the index values that would sort this expression.
member ArgSort(?descending: bool, ?nullsLast: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
descending | bool (optional) | If true, sort in descending order. Default is false. |
nullsLast | bool (optional) | If true, place null values last. Default is false. |
ArgTrue
Return indices where expression evaluates True.
member ArgTrue : unit -> ExprReturns: Expression of data type UInt32.
ArgUnique
Get the index of the unique values.
member ArgUnique : unit -> ExprBackwardFill
Fill null values with a specific strategy (Backward).
member BackwardFill(?limit: int) : ExprParameters
| Name | Type | Description |
|---|---|---|
limit | int (optional) | - |
BitLeftShift
Bitwise left shift (<<).
member BitLeftShift(n: int) : ExprParameters
| Name | Type | Description |
|---|---|---|
n | int | - |
BitRightShift
Bitwise right shift (>>).
member BitRightShift(n: int) : ExprParameters
| Name | Type | Description |
|---|---|---|
n | int | - |
BitwiseAnd
Perform an aggregation of bitwise ANDs.
member BitwiseAnd : unit -> ExprBitwiseCountOnes
Evaluate the number of set bits.
member BitwiseCountOnes : unit -> ExprBitwiseCountZeros
Evaluate the number of unset bits.
member BitwiseCountZeros : unit -> ExprBitwiseLeadingOnes
Evaluate the number most-significant set bits before seeing an unset bit.
member BitwiseLeadingOnes : unit -> ExprBitwiseLeadingZeros
Evaluate the number most-significant unset bits before seeing a set bit.
member BitwiseLeadingZeros : unit -> ExprBitwiseOr
Perform an aggregation of bitwise Ors.
member BitwiseOr : unit -> ExprBitwiseTrailingOnes
Evaluate the number least-significant set bits before seeing an unset bit.
member BitwiseTrailingOnes : unit -> ExprBitwiseTrailingZeros
Evaluate the number least-significant unset bits before seeing a set bit.
member BitwiseTrailingZeros : unit -> ExprBitwiseXor
Perform an aggregation of bitwise Xors.
member BitwiseXor : unit -> ExprBottomK
Get the k smallest elements. Result is sorted ascending.
member BottomK(k: int) : ExprParameters
| Name | Type | Description |
|---|---|---|
k | int | - |
BottomKBy
Get the bottom k elements determined by the values in the 'by' columns.
member BottomKBy(k: int, by: seq<'e>, ?reverse: seq<bool>) : Expr
member BottomKBy(k: int, by: 'b, reverse: bool) : Expr
member BottomKBy(k: int, by: 'a) : ExprParameters
| Name | Type | Description |
|---|---|---|
k | int | Number of elements to return. |
by | seq<'e> / 'b / 'a | Column to sort by. |
reverse | seq<bool> (optional) | Reverse the sort order for each by column. Default false. |
Cast
Cast expression to the type of 'T.
Cast expression to the polars datatype.
member Cast(?strict: bool, ?wrapNumerical: bool) : Expr
member Cast(dtype: DataType, ?strict: bool, ?wrapNumerical: bool) : Expr
member Cast(dtype: DataTypeExpr, ?strict: bool, ?wrapNumerical: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
strict | bool (optional) | - |
wrapNumerical | bool (optional) | - |
dtype | DataType / DataTypeExpr | - |
Cbrt
Calculate the cube root of the expression.
member Cbrt : unit -> ExprCeil
Round up to the nearest integer.
member Ceil : unit -> ExprClip
Set values outside the given boundaries to the boundary value.
member Clip(?lowerBound: Expr, ?upperBound: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
lowerBound | Expr (optional) | Lower bound. Accepts expression input. |
upperBound | Expr (optional) | Upper bound. Accepts expression input. |
Clone
member Clone : unit -> ExprCoalesce
Returns the first non-null value between this expression and other expressions. Syntactic sugar for pl.coalesce(this, others).
member Coalesce(others: seq<Expr>) : ExprParameters
| Name | Type | Description |
|---|---|---|
others | seq<Expr> | Fallback expressions, column names, or literals. |
Returns: A new coalesced expression.
Cos
Compute the cosine of each element.
member Cos : unit -> ExprCosh
Compute the cosh of each element.
member Cosh : unit -> ExprCot
Compute the cotangent of each element.
member Cot : unit -> ExprCount
Count the number of valid (non-null) values.
member Count : unit -> ExprCumCount
Get an array with the cumulative count computed at every element.
member CumCount(?reverse: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
reverse | bool (optional) | Reverse the operation. |
CumMax
Get an array with the cumulative max computed at every element.
member CumMax(?reverse: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
reverse | bool (optional) | Reverse the operation. |
CumMin
Get an array with the cumulative min computed at every element.
member CumMin(?reverse: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
reverse | bool (optional) | Reverse the operation. |
CumProd
Get an array with the cumulative prod computed at every element.
member CumProd(?reverse: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
reverse | bool (optional) | Reverse the operation. |
CumSum
Get an array with the cumulative sum computed at every element.
member CumSum(?reverse: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
reverse | bool (optional) | Reverse the operation. |
CumulativeEval
Run an expression over a sliding window that increases 1 slot every iteration. This can be really slow as it can have O(n^2) complexity. Don’t use this for operations that visit all elements.
member CumulativeEval(expr: Expr, ?minSamples: int) : ExprParameters
| Name | Type | Description |
|---|---|---|
expr | Expr | Expression to evaluate |
minSamples | int (optional) | Number of valid values there should be in the window before the expression is evaluated. valid values = length - null_count |
Cut
Bin continuous values into discrete categories.
member Cut(
breaks: seq<float>,
?labels: seq<string>,
?leftClosed: bool,
?includeBreaks: bool
) : ExprParameters
| Name | Type | Description |
|---|---|---|
breaks | seq<float> | List of unique cut points. |
labels | seq<string> (optional) | Names of the categories. The number of labels must be equal to the number of cut points plus one. |
leftClosed | bool (optional) | Set the intervals to be left-closed instead of right-closed. |
includeBreaks | bool (optional) | Include a column with the right endpoint of the bin each observation falls in. This will change the data type of the output from an Enum to a Struct. |
Returns: Expression/Series of data type Enum if include_breaks is set to False (default), otherwise an expression of data type Struct.
Degrees
Convert from radians to degrees.
member Degrees : unit -> ExprDiff
Calculate the difference with the previous value (n-th lag). Null values are propagated.
member Diff(?n: int64, ?nullBehavior: NullBehavior) : ExprParameters
| Name | Type | Description |
|---|---|---|
n | int64 (optional) | - |
nullBehavior | NullBehavior (optional) | - |
Dot
Compute the dot/inner product between two expressions.
member Dot(other: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
other | Expr | - |
DropNans
Drop NaN values.
member DropNans : unit -> ExprDropNulls
Drop null values.
member DropNulls : unit -> ExprEntropy
Computes the entropy. Uses the formula -sum(pk * log(pk)) where pk are discrete probabilities.
member Entropy(?baseVal: float, ?normalize: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
baseVal | float (optional) | Given base, defaults to e |
normalize | bool (optional) | Normalize pk if it doesn’t sum to 1. |
EqMissing
Check if this expression is equal to another, treating nulls as valid values. (e.g., Null == Null is True, 5 == Null is False)
member EqMissing(other: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
other | Expr | - |
EwmMean
Compute exponentially-weighted moving average.
member EwmMean(
alpha: float,
?adjust: bool,
?bias: bool,
?minPeriods: int,
?ignoreNulls: bool
) : ExprParameters
| Name | Type | Description |
|---|---|---|
alpha | float | Specify smoothing factor alpha directly. Constraint: 0 < alpha <= 1 |
adjust | bool (optional) | If true, divide by decaying adjustment factor in beginning periods to account for imbalance in relative weightings (viewing data as finite history). If false, assume infinite history. |
bias | bool (optional) | If true, use a biased estimator (Standard deviation uses N in denominator). If false, use an unbiased estimator (Standard deviation uses N-1). Note: This is primarily relevant for Variance/StdDev. For Mean, it typically defaults to true. |
minPeriods | int (optional) | Minimum number of observations in window required to have a value (otherwise result is null). |
ignoreNulls | bool (optional) | Ignore missing values when calculating weights. |
Returns: A new expression representing the EWM mean.
EwmMeanBy
Compute exponentially-weighted moving average based on a temporal or index column.
member EwmMeanBy(by: Expr, halfLife: string) : ExprParameters
| Name | Type | Description |
|---|---|---|
by | Expr | The column used to determine the distance between observations. Supported data types: Date, DateTime, UInt64, UInt32, Int64, or Int32. |
halfLife | string | The unit over which an observation decays to half its value. Supported string formats: - Time units ns (nanosecond), us (microsecond), ms (millisecond), s (second), m (minute), h (hour), d (day), w (week). - Index unitsi (index count). Example: "2i" means decay by half every 2 index steps. - CompoundExample: "3d12h4m25s".Warning: halfLife is treated as a constant duration. Calendar durations such as months (mo) or years (y) are NOT supported because they vary in length. Please express such durations in hours (e.g. use '730h' instead of '1mo'). |
Returns: A new expression representing the time/index-based EWM mean.
EwmStd
Compute exponentially-weighted moving standard deviation.
member EwmStd(
alpha: float,
?adjust: bool,
?bias: bool,
?minPeriods: int,
?ignoreNulls: bool
) : ExprParameters
| Name | Type | Description |
|---|---|---|
alpha | float | Specify smoothing factor alpha directly. Constraint: 0 < alpha <= 1 |
adjust | bool (optional) | If true, divide by decaying adjustment factor in beginning periods to account for imbalance in relative weightings (viewing data as finite history). If false, assume infinite history. |
bias | bool (optional) | If true, use a biased estimator (Standard deviation uses N in denominator). If false, use an unbiased estimator (Standard deviation uses N-1). Note: This is primarily relevant for Variance/StdDev. For Mean, it typically defaults to true. |
minPeriods | int (optional) | Minimum number of observations in window required to have a value (otherwise result is null). |
ignoreNulls | bool (optional) | Ignore missing values when calculating weights. |
Returns: A new expression representing the EWM standard deviation.
EwmSum
Compute exponentially-weighted moving sum.
member EwmSum(
alpha: float,
?adjust: bool,
?bias: bool,
?minPeriods: int,
?ignoreNulls: bool
) : ExprParameters
| Name | Type | Description |
|---|---|---|
alpha | float | - |
adjust | bool (optional) | - |
bias | bool (optional) | - |
minPeriods | int (optional) | - |
ignoreNulls | bool (optional) | - |
EwmSumBy
Compute exponentially-weighted moving sum based on a temporal or index column.
member EwmSumBy(by: Expr, halfLife: string) : ExprParameters
| Name | Type | Description |
|---|---|---|
by | Expr | - |
halfLife | string | - |
EwmVar
Compute exponentially-weighted moving variance.
member EwmVar(
alpha: float,
?adjust: bool,
?bias: bool,
?minPeriods: int,
?ignoreNulls: bool
) : ExprParameters
| Name | Type | Description |
|---|---|---|
alpha | float | Specify smoothing factor alpha directly. Constraint: 0 < alpha <= 1 |
adjust | bool (optional) | If true, divide by decaying adjustment factor in beginning periods to account for imbalance in relative weightings (viewing data as finite history). If false, assume infinite history. |
bias | bool (optional) | If true, use a biased estimator (Standard deviation uses N in denominator). If false, use an unbiased estimator (Standard deviation uses N-1). Note: This is primarily relevant for Variance/StdDev. For Mean, it typically defaults to true. |
minPeriods | int (optional) | Minimum number of observations in window required to have a value (otherwise result is null). |
ignoreNulls | bool (optional) | Ignore missing values when calculating weights. |
Returns: A new expression representing the EWM variance.
Exclude
member Exclude(names: seq<string>) : Expr
member Exclude(dtypes: seq<DataType>) : ExprParameters
| Name | Type | Description |
|---|---|---|
names | seq<string> | - |
dtypes | seq<DataType> | - |
Exp
Calculate the power of the Euler's number.
member Exp : unit -> ExprExplode
Explode a list column into multiple rows.
member Explode(?emptyAsNull: bool, ?keepNulls: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
emptyAsNull | bool (optional) | - |
keepNulls | bool (optional) | - |
ExtendConstant
Extending the Series with ‘n’ copies of a value.
member ExtendConstant(value: Expr, n: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
value | Expr | A constant literal value or a unit expression with which to extend the expression result Series; can pass None to extend with nulls. |
n | Expr | The number of additional values that will be added. |
FillNan
Fill NaN values with the given fill value.
member FillNan(fillValue: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
fillValue | Expr | The value to fill NaN values with. |
FillNull
Fill null values with a specific value.
Fill null values with a specific strategy (Forward/Backward/...).
Fill null values with a scalar literal.
member FillNull(value: Expr) : Expr
member FillNull(strategy: FillNullStrategy, ?limit: int) : Expr
member FillNull(value: 'T) : ExprParameters
| Name | Type | Description |
|---|---|---|
value | Expr / 'T | Value to fill null values with. |
strategy | FillNullStrategy | Strategy to use for filling null values. |
limit | int (optional) | Max number of consecutive nulls to fill. (Default null = infinite) |
FillNull$W
member FillNull$W(this: Expr, value: 'T) : ExprParameters
| Name | Type | Description |
|---|---|---|
this | Expr | - |
value | 'T | - |
Filter
Filter a single column. Mostly useful in group_by context or when you want to filter an expression based on another expression within a Select context.
member Filter(predicate: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
predicate | Expr | Boolean expression used to filter the current expression. |
Returns: A new expression with filtered values.
First
Get the first value of the group/series.
member First(?ignoreNulls: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
ignoreNulls | bool (optional) | - |
Returns: A new expression representing the first value.
Floor
Round down to the nearest integer.
member Floor : unit -> ExprFloorDiv
Integer division (floor division).
member FloorDiv(other: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
other | Expr | - |
ForwardFill
Fill null values with a specific strategy (Forward).
member ForwardFill(?limit: int) : ExprParameters
| Name | Type | Description |
|---|---|---|
limit | int (optional) | Max number of consecutive nulls to fill. (Default null = infinite) |
Gather
Gather values by an index expression.
member Gather(indices: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
indices | Expr | - |
GatherEvery
Take every nth value starting from an offset.
member GatherEvery(n: uint64, ?offset: uint64) : ExprParameters
| Name | Type | Description |
|---|---|---|
n | uint64 | - |
offset | uint64 (optional) | - |
Get
Get a single value by index. Returns a scalar.
member Get(index: Expr, ?nullOnOutOfBounds: bool) : Expr
member Get(index: uint64, ?nullOnOutOfBounds: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
index | Expr / uint64 | The index expression. |
nullOnOutOfBounds | bool (optional) | If true, returns Null when the index is out of bounds instead of raising an error. |
HasNulls
Check whether the expression contains one or more null values.
member HasNulls : unit -> ExprHash
Hash the elements in the selection.The hash value is of type UInt64.
member Hash(
?seed: uint64,
?seed1: uint64,
?seed2: uint64,
?seed3: uint64
) : ExprParameters
| Name | Type | Description |
|---|---|---|
seed | uint64 (optional) | Random seed parameter. Defaults to 0. |
seed1 | uint64 (optional) | Random seed parameter. Defaults to seed if not set. |
seed2 | uint64 (optional) | Random seed parameter. Defaults to seed if not set. |
seed3 | uint64 (optional) | Random seed parameter. Defaults to seed if not set. |
Head
Get the first n rows.
member Head(?n: int) : ExprParameters
| Name | Type | Description |
|---|---|---|
n | int (optional) | Number of rows to return. |
Hist
Bin values into buckets and count their occurrences.
member Hist(
?bins: Expr,
?binCount: int,
?includeCategory: bool,
?includeBreakPoint: bool
) : ExprParameters
| Name | Type | Description |
|---|---|---|
bins | Expr (optional) | Bin edges. If None given, we determine the edges based on the data. |
binCount | int (optional) | If bins is not provided, binCount uniform bins are created that fully encompass the data. |
includeCategory | bool (optional) | Include a column that indicates the upper breakpoint. |
includeBreakPoint | bool (optional) | Include a column that shows the intervals as categories. |
Implode
Implode multiple rows to a list.
member Implode(?maintainOrder: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
maintainOrder | bool (optional) | - |
IndexOf
Find the index of the first occurrence of a specific value.
member IndexOf(element: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
element | Expr | The element expression to search for. |
Inspect
Print the value that this expression evaluates to and pass on the value.
member Inspect(?format: string) : ExprParameters
| Name | Type | Description |
|---|---|---|
format | string (optional) | - |
Interpolate
Interpolate intermediate values. The interpolation method can be configured.
Nulls at the beginning and end of the series remain null.
member Interpolate(?method: InterpolationMethod) : ExprParameters
| Name | Type | Description |
|---|---|---|
method | InterpolationMethod (optional) | Interpolation method (Linear or Nearest). |
InterpolateBy
Interpolate intermediate values based on the values of another column.
This is useful when the data is not equally spaced, for example when interpolating based on a timestamp column.
member InterpolateBy(by: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
by | Expr | The column to use for interpolation (e.g. a timestamp column). |
Returns: A new expression with interpolated values.
IsBetween
Check if the value is between lower and upper bounds (inclusive).
member IsBetween(lower: Expr, upper: Expr, ?closedInterval: ClosedInterval) : ExprParameters
| Name | Type | Description |
|---|---|---|
lower | Expr | - |
upper | Expr | - |
closedInterval | ClosedInterval (optional) | - |
IsClose
Check if this expression is close, i.e. almost equal, to the other expression.
member IsClose(
other: Expr,
?absTol: float,
?relTol: float,
?nansEqual: bool
) : ExprParameters
| Name | Type | Description |
|---|---|---|
other | Expr | A literal or expression value to compare with. |
absTol | float (optional) | Absolute tolerance. This is the maximum allowed absolute difference betweentwo values. Must be non-negative. |
relTol | float (optional) | Relative tolerance. This is the maximum allowed difference between two values, relative to the larger absolute value. Must be non-negative. |
nansEqual | bool (optional) | Whether NaN values should be considered equal. |
Returns: Expression/Series of data type Boolean.
IsDuplicated
Get a boolean mask indicating which values are duplicated.
member IsDuplicated : unit -> ExprIsEmpty
Return whether the column is empty.
member IsEmpty(?ignoreNulls: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
ignoreNulls | bool (optional) | If true a column containing only nulls will also be considered empty. The default is false. |
IsFinite
Returns a boolean Series indicating which values are finite.
member IsFinite : unit -> ExprReturns: Expression of data type Boolean.
IsFirstDistinct
Return a boolean mask indicating the first occurrence of each distinct value.
member IsFirstDistinct : unit -> ExprReturns: Expression of data type Boolean.
IsIn
Check if the value is in given collection.
member IsIn(other: Expr, ?nullsEqual: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
other | Expr | - |
nullsEqual | bool (optional) | - |
IsInFinite
Returns a boolean Series indicating which values are infinite.
member IsInFinite : unit -> ExprReturns: Expression of data type Boolean.
IsLastDistinct
Return a boolean mask indicating the last occurrence of each distinct value.
member IsLastDistinct : unit -> ExprReturns: Expression of data type Boolean.
IsNan
Returns a boolean Series indicating which values are NaN.
member IsNan : unit -> ExprIsNotNan
Returns a boolean Series indicating which values are not NaN.
member IsNotNan : unit -> ExprIsNotNull
Evaluate whether the expression is not null.
member IsNotNull : unit -> ExprIsNull
Evaluate whether the expression is null.
member IsNull : unit -> ExprIsSorted
Checks if an expression is sorted.
If descending and/or nulls_last are None, it will check True and False for the unspecified option(s), and return True if the expression is sorted under any combination of those settings.
member IsSorted(?descending: bool, ?nullsLast: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
descending | bool (optional) | Checks if the expression is sorted in descending order.Defaults to False. |
nullsLast | bool (optional) | Consider null values as being ordered last when checking sortedness.Defaults to False. |
Returns: Expression of Boolean
IsUnique
Get a boolean mask indicating which values are unique.
member IsUnique : unit -> ExprItem
Access one element in this array/list/tuple expression.
member Item(?allowEmpty: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
allowEmpty | bool (optional) | - |
Kurtosis
Compute the kurtosis (Fisher or Pearson) of a dataset.
member Kurtosis(?fisher: bool, ?bias: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
fisher | bool (optional) | If True, Fisher’s definition is used (normal ==> 0.0). If False, Pearson’s definition is used (normal ==> 3.0). |
bias | bool (optional) | If False, the calculations are corrected for statistical bias. |
Last
Get the last value of the group/series.
member Last(?ignoreNulls: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
ignoreNulls | bool (optional) | - |
Returns: A new expression representing the last value.
Len
Return the number of elements in the column. Null values count towards the total.
member Len : unit -> ExprLn
Calculate the natural logarithm (base e).
member Ln : unit -> ExprLog
Calculate the logarithm with the given base.
Compute the logarithm with base e.
Compute the logarithm with the given expression as base.
member Log(baseVal: float) : Expr
member Log : unit -> Expr
member Log(baseExpr: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
baseVal | float | - |
baseExpr | Expr | - |
Log10
Compute the base 10 logarithm of the input array, element-wise.
member Log10 : unit -> ExprLog1p
Compute the natural logarithm of each element plus one.This computes log(1 + x) but is more numerically stable for x close to zero.
member Log1p : unit -> ExprLowerBound
Calculate the lower bound. Returns a unit Series with the lowest value possible for the dtype of this expression.
member LowerBound : unit -> ExprMap
Map values using a standard F# function. Automatically wraps it using Udf.map.
member Map(f: ('T -> 'U)) : ExprParameters
| Name | Type | Description |
|---|---|---|
f | ('T -> 'U) | - |
MapArrow
Apply a custom C#/F# function (UDF) to the expression. The function receives an Apache Arrow Array and returns an Arrow Array.
member MapArrow(mapping: (IArrowArray -> IArrowArray), ?outputType: DataType) : ExprParameters
| Name | Type | Description |
|---|---|---|
mapping | (IArrowArray -> IArrowArray) | Function mapping IArrowArray -> IArrowArray. |
outputType | DataType (optional) | The expected output DataType (optional). |
MapOption
Map values using an F# function that handles Options. Automatically wraps it using Udf.mapOption.
member MapOption(f: ('T option -> 'U option)) : ExprParameters
| Name | Type | Description |
|---|---|---|
f | ('T option -> 'U option) | - |
MapValueOption
Map values using an F# function that handles Value Options. Automatically wraps it using Udf.mapValueOption.
member MapValueOption(f: ('T voption -> 'U voption)) : ExprParameters
| Name | Type | Description |
|---|---|---|
f | ('T voption -> 'U voption) | - |
Max
Get the max value.
member Max : unit -> ExprMaxBy
Get maximum value, ordered by another expression. If the by expression has multiple values equal to the maximum it is not defined which value will be chosen.
member MaxBy(by: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
by | Expr | - |
Mean
Calculate the average of the values in the group or column.
member Mean : unit -> ExprMedian
Get the median value.
member Median : unit -> ExprMin
Get the min value.
member Min : unit -> ExprMinBy
Get minimum value, ordered by another expression. If the by expression has multiple values equal to the minimum it is not defined which value will be chosen.
member MinBy(by: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
by | Expr | - |
Mod
Modulo operator (remainder).
member Mod(other: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
other | Expr | - |
Mode
Get the mode value.
member Mode : unit -> ExprNUnique
Count unique values. Notes: Null is considered to be a unique value for the purposes of this operation.
member NUnique : unit -> ExprNanMax
Get maximum value, but propagate/poison encountered NaN values.
member NanMax : unit -> ExprNanMin
Get minimum value, but propagate/poison encountered NaN values.
member NanMin : unit -> ExprNeqMissing
Check if this expression is NOT equal to another, treating nulls as valid values. (e.g., Null != Null is False, 5 != Null is True)
member NeqMissing(other: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
other | Expr | - |
NullCount
Count the number of null.
member NullCount : unit -> ExprOver
Apply a window function over specific partition columns.
member Over(
?partitionBy: seq<Expr>,
?orderBy: seq<Expr>,
?descending: bool,
?nullsLast: bool,
?multithreaded: bool,
?maintainOrder: bool,
?mapping: WindowMappingStrategy
) : Expr
member Over(partitionCol: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
partitionBy | seq<Expr> (optional) | - |
orderBy | seq<Expr> (optional) | - |
descending | bool (optional) | - |
nullsLast | bool (optional) | - |
multithreaded | bool (optional) | - |
maintainOrder | bool (optional) | - |
mapping | WindowMappingStrategy (optional) | - |
partitionCol | Expr | Column to partition by. |
Example
Calculate sum of "Value" per "Group"
pl.col("Value").Sum().Over(pl.col("Group"))PctChange
Computes percentage change between values. Percentage change (as fraction) between current element and most-recent non-null element at least n period(s) before the current element. Computes the change from the previous row by default.
member PctChange(?n: int) : ExprParameters
| Name | Type | Description |
|---|---|---|
n | int (optional) | periods to shift for forming percent change. |
PeakMax
Get a boolean mask of the local maximum peaks.
member PeakMax : unit -> ExprPeakMin
Get a boolean mask of the local minimum peaks.
member PeakMin : unit -> ExprPipe
Apply a user-defined function to this expression, returning the result of the function. This allows encapsulating a sequence of Polars expression operations into a reusable function.
member Pipe(func: (Expr -> 'T)) : 'TParameters
| Name | Type | Description |
|---|---|---|
func | (Expr -> 'T) | A function that receives the current expression and returns a value of type T. Typically this function wraps several Polars API calls that operate on the given expression. |
Returns: The result of applying func to this expression.
Pow
Calculate the power of the expression.
Calculate the power of a double.
Calculate the power of an integer.
Calculate the power of a single.
Calculate the power of an int64.
member Pow(exponent: Expr) : Expr
member Pow(exponent: float) : Expr
member Pow(exponent: int) : Expr
member Pow(exponent: float32) : Expr
member Pow(exponent: int64) : ExprParameters
| Name | Type | Description |
|---|---|---|
exponent | Expr / float / int / float32 / int64 | - |
Product
Compute the product of an expression
member Product : unit -> ExprQCut
Bin continuous values into discrete categories based on their quantiles.
member QCut(
quantiles: seq<float>,
?labels: seq<string>,
?leftClosed: bool,
?allowDuplicates: bool,
?includeBreaks: bool
) : Expr
member QCut(
quantiles: int,
?labels: seq<string>,
?leftClosed: bool,
?allowDuplicates: bool,
?includeBreaks: bool
) : ExprParameters
| Name | Type | Description |
|---|---|---|
quantiles | seq<float> / int | Either a list of quantile probabilities between 0 and 1 or a positive integer determining the number of bins with uniform probability. |
labels | seq<string> (optional) | Names of the categories. The number of labels must be equal to the number of categories. |
leftClosed | bool (optional) | Set the intervals to be left-closed instead of right-closed. |
allowDuplicates | bool (optional) | If set to True, duplicates in the resulting quantiles are dropped, rather than raising a DuplicateError. This can happen even with unique probabilities, depending on the data. |
includeBreaks | bool (optional) | Include a column with the right endpoint of the bin each observation falls in. This will change the data type of the output from a Categorical to a Struct. |
Returns: Expression/Series of data type Categorical if include_breaks is set to False (default), otherwise an expression of data type Struct.
Quantile
Get the quantile value.
member Quantile(quantile: float, ?interpolation: QuantileMethod) : ExprParameters
| Name | Type | Description |
|---|---|---|
quantile | float | Quantile between 0.0 and 1.0. |
interpolation | QuantileMethod (optional) | ['nearest’, ‘higher’, ‘lower’, ‘midpoint’, ‘linear’] Interpolation method. |
Radians
Convert from degrees to radians.
member Radians : unit -> ExprRank
Assign ranks to data, dealing with ties appropriately.
member Rank(?method: RankMethod, ?descending: bool, ?seed: uint64) : ExprParameters
| Name | Type | Description |
|---|---|---|
method | RankMethod (optional) | The method used to assign ranks to tied elements. See RankMethod for details. Default is RankMethod.Average. |
descending | bool (optional) | Rank in descending order. |
seed | uint64 (optional) | If method="random", use this as seed. |
Rechunk
Create a single chunk of memory for this Series.
member Rechunk : unit -> ExprReinterpret
Reinterpret the underlying bits as a signed/unsigned integer. This operation is only allowed for numeric types of the same size. For lower bits numbers, you can safely use the cast operation.
Reinterpret the underlying bits as a signed/unsigned integer or float.
member Reinterpret(?signed: bool) : Expr
member Reinterpret(dtype: DataType) : ExprParameters
| Name | Type | Description |
|---|---|---|
signed | bool (optional) | If True, reinterpret as signed integer. Otherwise, reinterpret as unsigned integer. |
dtype | DataType | DataType to reinterpret to. |
Rem
Alias for Mod.
member Rem(other: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
other | Expr | - |
RepeatBy
Repeat the elements in this Series as specified in the given expression. The repeated elements are expanded into a List.
member RepeatBy(by: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
by | Expr | Numeric column that determines how often the values will be repeated. The column will be coerced to UInt32. Give this dtype to make the coercion a no-op. |
Returns: Expression/Series of data type List, where the inner data type is equal to the original data type.
Replace
Replace the given values by different values of the same data type.
Replace scalar values where matched with a new scalar value.
member Replace(old: Expr, newExpr: Expr) : Expr
member Replace(oldVal: 'Old, newVal: 'New) : ExprParameters
| Name | Type | Description |
|---|---|---|
old | Expr | Value or sequence of values to replace. Accepts expression input. |
newExpr | Expr | Value or sequence of values to replace by. Accepts expression input. |
oldVal | 'Old | - |
newVal | 'New | - |
Replace$W
member Replace$W(
op_Dollar1: (LitMechanism -> ('New -> Expr)),
this: Expr,
oldVal: 'Old,
newVal: 'New
) : ExprParameters
| Name | Type | Description |
|---|---|---|
op_Dollar1 | (LitMechanism -> ('New -> Expr)) | - |
this | Expr | - |
oldVal | 'Old | - |
newVal | 'New | - |
ReplaceStrict
Replace all values by different values.
member ReplaceStrict(
old: Expr,
newExpr: Expr,
?defaultExpr: Expr,
?returnDataType: DataTypeExpr
) : ExprParameters
| Name | Type | Description |
|---|---|---|
old | Expr | Value or sequence of values to replace. Accepts expression input. Sequences are parsed as Series, other non-expression inputs are parsed as literals. |
newExpr | Expr | Value or sequence of values to replace by. Accepts expression input. Sequences are parsed as Series, other non-expression inputs are parsed as literals. Length must match the length of old or have length 1. |
defaultExpr | Expr (optional) | Set values that were not replaced to this value. If no default is specified, (default), an error is raised if any values were not replaced. Accepts expression input. Non-expression inputs are parsed as literals. |
returnDataType | DataTypeExpr (optional) | The data type of the resulting expression. If set to null (default), the data type is determined automatically based on the other inputs. |
Reshape
Reshape the column into a multi-dimensional array.
member Reshape(dimensions: seq<int64>) : ExprParameters
| Name | Type | Description |
|---|---|---|
dimensions | seq<int64> | Tuple of the dimension sizes. If a -1 is used, that dimension is inferred. |
Reverse
Reverse the selection.
This is useful in a GroupBy context to reverse the order of the group.
member Reverse : unit -> ExprReturns: A new expression with the order reversed.
Rle
Compress the column data using run-length encoding. Run-length encoding (RLE) encodes data by storing each run of identical values as a single value and its length.
member Rle : unit -> ExprReturns: Expression/Series of data type Struct with fields len of data type UInt32 and value of the original data type.
RleId
Get a distinct integer ID for each run of identical values. The ID starts at 0 and increases by one each time the value of the column changes.
member RleId : unit -> ExprReturns: Expression/Series of data type UInt32.
RollingKurtosis
Apply a rolling Kurtosis over a window.
member RollingKurtosis(
windowSize: Dur,
?minPeriod: int,
?weights: float[],
?center: bool,
?fisher: bool,
?bias: bool
) : ExprParameters
| Name | Type | Description |
|---|---|---|
windowSize | Dur | The size of the window formatted as a string duration. Examples: "3i" (3 index rows), "1d" (1 day), "1h" (1 hour). |
minPeriod | int (optional) | The minimum number of observations in the window required to have a value (otherwise null). |
weights | float[] (optional) | Optional weights to apply to the window. The length of the array should match the window size (if using fixed row windows). Default is null (unweighted). |
center | bool (optional) | If true, the window is centered on the current observation. Default is false (right-aligned window, [i-window, i]). |
fisher | bool (optional) | If True, Fisher’s definition is used (normal ==> 0.0). If False, Pearson’s definition is used (normal ==> 3.0). |
bias | bool (optional) | If False, the calculations are corrected for statistical bias. |
Returns: A new Expr with the rolling skew.
RollingMax
Apply a rolling max (moving max) over a window.
member RollingMax(
windowSize: Dur,
?minPeriod: int,
?weights: float[],
?center: bool
) : ExprParameters
| Name | Type | Description |
|---|---|---|
windowSize | Dur | The size of the window formatted as a string duration. Examples: "3i" (3 index rows), "1d" (1 day), "1h" (1 hour). |
minPeriod | int (optional) | The minimum number of observations in the window required to have a value (otherwise null). |
weights | float[] (optional) | Optional weights to apply to the window. The length of the array should match the window size (if using fixed row windows). Default is null (unweighted). |
center | bool (optional) | If true, the window is centered on the current observation. Default is false (right-aligned window, [i-window, i]). |
Returns: A new Expr with the rolling maximum.
RollingMaxBy
Apply a rolling max (moving max) over a dynamic window defined by the values in the by column.
Unlike standard fixed-size rolling windows (which operate on row counts), this operates on values (typically time).
member RollingMaxBy(
windowSize: Dur,
by: Expr,
?closed: ClosedInterval,
?minPeriod: int
) : ExprParameters
| Name | Type | Description |
|---|---|---|
windowSize | Dur | The size of the dynamic window. Supported duration strings: "1d", "2h", "10s", "500ms", etc. |
by | Expr | The column used to define the window (the "time" axis). Typically a Date or DateTime column, but can also be monotonic integers. |
closed | ClosedInterval (optional) | Defines how the window interval is closed. Default is ClosedWindow.Left``[t - window, t). |
minPeriod | int (optional) | The minimum number of observations in the window required to have a non-null result. |
Returns: A new Expr representing the dynamic rolling max.
NOTE
The by column must be sorted in ascending order.
RollingMean
Apply a rolling average (moving average) over a window.
member RollingMean(
windowSize: Dur,
?minPeriod: int,
?weights: float[],
?center: bool
) : ExprParameters
| Name | Type | Description |
|---|---|---|
windowSize | Dur | The size of the window formatted as a string duration. Examples: "3i" (3 index rows), "1d" (1 day), "1h" (1 hour). |
minPeriod | int (optional) | The minimum number of observations in the window required to have a value (otherwise null). |
weights | float[] (optional) | Optional weights to apply to the window. The length of the array should match the window size (if using fixed row windows). Default is null (unweighted). |
center | bool (optional) | If true, the window is centered on the current observation. Default is false (right-aligned window, [i-window, i]). |
Returns: A new Expr with the rolling average.
RollingMeanBy
Apply a rolling mean (moving average) over a dynamic window defined by the values in the by column.
Unlike standard fixed-size rolling windows (which operate on row counts), this operates on values (typically time).
member RollingMeanBy(
windowSize: Dur,
by: Expr,
?closed: ClosedInterval,
?minPeriod: int
) : ExprParameters
| Name | Type | Description |
|---|---|---|
windowSize | Dur | The size of the dynamic window. Supported duration strings: "1d", "2h", "10s", "500ms", etc. |
by | Expr | The column used to define the window (the "time" axis). Typically a Date or DateTime column, but can also be monotonic integers. |
closed | ClosedInterval (optional) | Defines how the window interval is closed. Default is ClosedWindow.Left``[t - window, t). |
minPeriod | int (optional) | The minimum number of observations in the window required to have a non-null result. |
Returns: A new Expr representing the dynamic rolling mean.
NOTE
The by column must be sorted in ascending order.
RollingMedian
Apply a rolling median (moving median) over a window.
member RollingMedian(
windowSize: Dur,
?minPeriod: int,
?weights: float[],
?center: bool
) : ExprParameters
| Name | Type | Description |
|---|---|---|
windowSize | Dur | The size of the window formatted as a string duration. Examples: "3i" (3 index rows), "1d" (1 day), "1h" (1 hour). |
minPeriod | int (optional) | The minimum number of observations in the window required to have a value (otherwise null). |
weights | float[] (optional) | Optional weights to apply to the window. The length of the array should match the window size (if using fixed row windows). Default is null (unweighted). |
center | bool (optional) | If true, the window is centered on the current observation. Default is false (right-aligned window, [i-window, i]). |
Returns: A new Expr with the rolling median.
RollingMedianBy
Apply a rolling median (moving median) over a dynamic window defined by the values in the by column.
Unlike standard fixed-size rolling windows (which operate on row counts), this operates on values (typically time).
member RollingMedianBy(
windowSize: Dur,
by: Expr,
?closed: ClosedInterval,
?minPeriod: int
) : ExprParameters
| Name | Type | Description |
|---|---|---|
windowSize | Dur | The size of the time window as a TimeSpan. This will be automatically converted to a Polars duration string (e.g., 01:30:00 -> "1h30m"). |
by | Expr | The column used to define the window (the "time" axis). Typically a Date or DateTime column, but can also be monotonic integers. |
closed | ClosedInterval (optional) | Defines how the window interval is closed. Default is ClosedWindow.Left``[t - window, t). |
minPeriod | int (optional) | The minimum number of observations in the window required to have a non-null result. |
Returns: A new Expr representing the dynamic rolling max.
NOTE
The by column must be sorted in ascending order.
RollingMin
Apply a rolling min (moving min) over a window.
member RollingMin(
windowSize: Dur,
?minPeriod: int,
?weights: float[],
?center: bool
) : ExprParameters
| Name | Type | Description |
|---|---|---|
windowSize | Dur | The size of the window formatted as a string duration. Examples: "3i" (3 index rows), "1d" (1 day), "1h" (1 hour). |
minPeriod | int (optional) | The minimum number of observations in the window required to have a value (otherwise null). |
weights | float[] (optional) | Optional weights to apply to the window. The length of the array should match the window size (if using fixed row windows). Default is null (unweighted). |
center | bool (optional) | If true, the window is centered on the current observation. Default is false (right-aligned window, [i-window, i]). |
Returns: A new Expr with the rolling minimum.
RollingMinBy
Apply a rolling min (moving min) over a dynamic window defined by the values in the by column.
Unlike standard fixed-size rolling windows (which operate on row counts), this operates on values (typically time).
member RollingMinBy(
windowSize: Dur,
by: Expr,
?closed: ClosedInterval,
?minPeriod: int
) : ExprParameters
| Name | Type | Description |
|---|---|---|
windowSize | Dur | The size of the dynamic window. Supported duration strings: "1d", "2h", "10s", "500ms", etc. |
by | Expr | The column used to define the window (the "time" axis). Typically a Date or DateTime column, but can also be monotonic integers. |
closed | ClosedInterval (optional) | Defines how the window interval is closed. Default is ClosedWindow.Left``[t - window, t). |
minPeriod | int (optional) | The minimum number of observations in the window required to have a non-null result. |
Returns: A new Expr representing the dynamic rolling min.
NOTE
The by column must be sorted in ascending order.
RollingQuantile
Apply a rolling quantile over a fixed window.
member RollingQuantile(
quantile: float,
method: QuantileMethod,
windowSize: Dur,
?minPeriod: int,
?weights: float[],
?center: bool
) : ExprParameters
| Name | Type | Description |
|---|---|---|
quantile | float | Quantile between 0.0 and 1.0 (e.g., 0.5 for median). |
method | QuantileMethod | Interpolation method when the quantile lies between two data points. |
windowSize | Dur | The size of the window. Format: "3i" (3 rows) or just a number string "3".For time-based windows (e.g. "2h"), use RollingQuantileBy instead. |
minPeriod | int (optional) | The minimum number of observations in the window required to have a value (otherwise null). |
weights | float[] (optional) | Optional weights for the window. The length must match the parsed window size. If null, equal weights are used. |
center | bool (optional) | If true, the window is centered on the current observation. Default is false (right-aligned window, [i-window, i]). |
Returns: A new Expr representing the rolling quantile.
RollingQuantileBy
Apply a rolling quantile (moving quantile) over a dynamic window defined by the values in the by column.
Unlike standard fixed-size rolling windows (which operate on row counts), this operates on values (typically time).
member RollingQuantileBy(
quantile: float,
method: QuantileMethod,
windowSize: Dur,
by: Expr,
?closed: ClosedInterval,
?minPeriod: int
) : ExprParameters
| Name | Type | Description |
|---|---|---|
quantile | float | Quantile between 0.0 and 1.0 (e.g., 0.5 for median). |
method | QuantileMethod | Interpolation method when the quantile lies between two data points. |
windowSize | Dur | The size of the time window as a TimeSpan. This will be automatically converted to a Polars duration string (e.g., 01:30:00 -> "1h30m"). |
by | Expr | The column used to define the window (the "time" axis). Typically a Date or DateTime column, but can also be monotonic integers. |
closed | ClosedInterval (optional) | Defines how the window interval is closed. Default is ClosedWindow.Left``[t - window, t). |
minPeriod | int (optional) | The minimum number of observations in the window required to have a non-null result. |
Returns: A new Expr representing the dynamic rolling quantile.
NOTE
The by column must be sorted in ascending order.
RollingRank
Apply a rolling rank (moving rank) over a window.
member RollingRank(
windowSize: Dur,
?minPeriod: int,
?method: RankMethod,
?seed: uint64,
?weights: float[],
?center: bool
) : ExprParameters
| Name | Type | Description |
|---|---|---|
windowSize | Dur | The size of the time window as a TimeSpan. This will be automatically converted to a Polars duration string (e.g., 01:30:00 -> "1h30m"). |
minPeriod | int (optional) | The minimum number of observations in the window required to have a value (otherwise null). |
method | RankMethod (optional) | The method used to assign ranks to tied elements. See RankMethod for details. Default is RankMethod.Average. |
seed | uint64 (optional) | If method="random", use this as seed. |
weights | float[] (optional) | Optional weights to apply to the window. The length of the array should match the window size (if using fixed row windows). Default is null (unweighted). |
center | bool (optional) | If true, the window is centered on the current observation. Default is false (right-aligned window, [i-window, i]). |
RollingRankBy
Apply a rolling rank (moving rank) over a dynamic window defined by the values in the by column.
Unlike standard fixed-size rolling windows (which operate on row counts), this operates on values (typically time).
member RollingRankBy(
windowSize: Dur,
by: Expr,
?method: RollingRankMethod,
?seed: uint64,
?closed: ClosedInterval,
?minPeriod: int
) : ExprParameters
| Name | Type | Description |
|---|---|---|
windowSize | Dur | The size of the dynamic window. Supported duration strings: "1d", "2h", "10s", "500ms", etc. |
by | Expr | The column used to define the window (the "time" axis). Typically a Date or DateTime column, but can also be monotonic integers. |
method | RollingRankMethod (optional) | The method used to assign ranks to tied elements. |
seed | uint64 (optional) | Seed for the random method (only relevant when method is Random). |
closed | ClosedInterval (optional) | Defines how the window interval is closed. Default is ClosedWindow.Left``[t - window, t). |
minPeriod | int (optional) | The minimum number of observations in the window required to have a non-null result. |
Returns: A new Expr representing the dynamic rolling rank.
NOTE
The by column must be sorted in ascending order.
RollingSkew
Apply a rolling skew (moving skew) over a window.
member RollingSkew(
windowSize: Dur,
?minPeriod: int,
?weights: float[],
?center: bool,
?bias: bool
) : ExprParameters
| Name | Type | Description |
|---|---|---|
windowSize | Dur | The size of the window formatted as a string duration. Examples: "3i" (3 index rows), "1d" (1 day), "1h" (1 hour). |
minPeriod | int (optional) | The minimum number of observations in the window required to have a value (otherwise null). |
weights | float[] (optional) | Optional weights to apply to the window. The length of the array should match the window size (if using fixed row windows). Default is null (unweighted). |
center | bool (optional) | If true, the window is centered on the current observation. Default is false (right-aligned window, [i-window, i]). |
bias | bool (optional) | If False, the calculations are corrected for statistical bias. |
Returns: A new Expr with the rolling skew.
RollingStd
Apply a rolling standard deviation (moving standard deviation) over a window.
member RollingStd(
windowSize: Dur,
?minPeriod: int,
?weights: float[],
?center: bool
) : ExprParameters
| Name | Type | Description |
|---|---|---|
windowSize | Dur | The size of the window formatted as a string duration. Examples: "3i" (3 index rows), "1d" (1 day), "1h" (1 hour). |
minPeriod | int (optional) | The minimum number of observations in the window required to have a value (otherwise null). |
weights | float[] (optional) | Optional weights to apply to the window. The length of the array should match the window size (if using fixed row windows). Default is null (unweighted). |
center | bool (optional) | If true, the window is centered on the current observation. Default is false (right-aligned window, [i-window, i]). |
Returns: A new Expr with the rolling standard deviation.
RollingStdBy
Apply a rolling standard deviation (moving standard deviation) over a dynamic window defined by the values in the by column.
Unlike standard fixed-size rolling windows (which operate on row counts), this operates on values (typically time).
member RollingStdBy(
windowSize: Dur,
by: Expr,
?closed: ClosedInterval,
?minPeriod: int
) : ExprParameters
| Name | Type | Description |
|---|---|---|
windowSize | Dur | The size of the dynamic window. Supported duration strings: "1d", "2h", "10s", "500ms", etc. |
by | Expr | The column used to define the window (the "time" axis). Typically a Date or DateTime column, but can also be monotonic integers. |
closed | ClosedInterval (optional) | Defines how the window interval is closed. Default is ClosedWindow.Left``[t - window, t). |
minPeriod | int (optional) | The minimum number of observations in the window required to have a non-null result. |
Returns: A new Expr representing the dynamic rolling standard deviation.
NOTE
The by column must be sorted in ascending order.
RollingSum
Apply a rolling sum (moving sum) over a window.
member RollingSum(
windowSize: Dur,
?minPeriod: int,
?weights: float[],
?center: bool
) : ExprParameters
| Name | Type | Description |
|---|---|---|
windowSize | Dur | The size of the window formatted as a string duration. Examples: "3i" (3 index rows), "1d" (1 day), "1h" (1 hour). |
minPeriod | int (optional) | The minimum number of observations in the window required to have a value (otherwise null). |
weights | float[] (optional) | Optional weights to apply to the window. The length of the array should match the window size (if using fixed row windows). Default is null (unweighted). |
center | bool (optional) | If true, the window is centered on the current observation. Default is false (right-aligned window, [i-window, i]). |
Returns: A new Expr with the rolling sum.
RollingSumBy
Apply a rolling sum (moving sum) over a dynamic window defined by the values in the by column.
Unlike standard fixed-size rolling windows (which operate on row counts), this operates on values (typically time).
member RollingSumBy(
windowSize: Dur,
by: Expr,
?closed: ClosedInterval,
?minPeriod: int
) : ExprParameters
| Name | Type | Description |
|---|---|---|
windowSize | Dur | The size of the dynamic window. Supported duration strings: "1d", "2h", "10s", "500ms", etc. |
by | Expr | The column used to define the window (the "time" axis). Typically a Date or DateTime column, but can also be monotonic integers. |
closed | ClosedInterval (optional) | Defines how the window interval is closed. Default is ClosedWindow.Left``[t - window, t). |
minPeriod | int (optional) | The minimum number of observations in the window required to have a non-null result. |
Returns: A new Expr representing the dynamic rolling sum.
NOTE
The by column must be sorted in ascending order.
RollingVar
Apply a rolling variance (moving variance) over a window.
member RollingVar(
windowSize: Dur,
?minPeriod: int,
?weights: float[],
?center: bool,
?ddof: byte
) : ExprParameters
| Name | Type | Description |
|---|---|---|
windowSize | Dur | The size of the window formatted as a string duration. Examples: "3i" (3 index rows), "1d" (1 day), "1h" (1 hour). |
minPeriod | int (optional) | The minimum number of observations in the window required to have a value (otherwise null). |
weights | float[] (optional) | Optional weights to apply to the window. The length of the array should match the window size (if using fixed row windows). Default is null (unweighted). |
center | bool (optional) | If true, the window is centered on the current observation. Default is false (right-aligned window, [i-window, i]). |
ddof | byte (optional) | - |
Returns: A new Expr with the rolling variance.
RollingVarBy
Apply a rolling variance (moving variance) over a dynamic window defined by the values in the by column.
Unlike standard fixed-size rolling windows (which operate on row counts), this operates on values (typically time).
member RollingVarBy(
windowSize: Dur,
by: Expr,
?closed: ClosedInterval,
?minPeriod: int,
?ddof: byte
) : ExprParameters
| Name | Type | Description |
|---|---|---|
windowSize | Dur | The size of the dynamic window. Supported duration strings: "1d", "2h", "10s", "500ms", etc. |
by | Expr | The column used to define the window (the "time" axis). Typically a Date or DateTime column, but can also be monotonic integers. |
closed | ClosedInterval (optional) | Defines how the window interval is closed. Default is ClosedWindow.Left``[t - window, t). |
minPeriod | int (optional) | The minimum number of observations in the window required to have a non-null result. |
ddof | byte (optional) | “Delta Degrees of Freedom”: the divisor used in the calculation is N - ddof, where N represents the number of elements. By default ddof is 1. |
Returns: A new Expr representing the dynamic rolling variance.
NOTE
The by column must be sorted in ascending order.
Round
Round underlying floating point data by decimals digits.
member Round(?decimals: uint32, ?mode: RoundMode) : ExprParameters
| Name | Type | Description |
|---|---|---|
decimals | uint32 (optional) | Number of decimals to round by. |
mode | RoundMode (optional) | The rounding strategy used. A “rounded value” is a value with at most decimals decimal places (e.g. integers when decimals=0, multiples of 0.1 when decimals=1, 0.01 when decimals=2, and so on). Strategies that start with half_ round all values to the nearest rounded value, only using the strategy to break ties when a value falls exactly between two rounded values (e.g. 0.5 when decimals=0, 0.05 when decimals=1). Other rounding strategies specify explicitly which rounded value is chosen and always apply (not just for tiebreaks). |
RoundSigFigs
Round to a number of significant figures.
member RoundSigFigs(digits: int) : ExprParameters
| Name | Type | Description |
|---|---|---|
digits | int | Number of significant figures to round to. |
SampleFrac
Sample from this expression.
member SampleFrac(
fraction: Expr,
?withReplacement: bool,
?shuffle: bool,
?seed: uint64
) : ExprParameters
| Name | Type | Description |
|---|---|---|
fraction | Expr | Fraction of items to return. |
withReplacement | bool (optional) | Allow values to be sampled more than once. |
shuffle | bool (optional) | Shuffle the order of sampled data points. |
seed | uint64 (optional) | Seed for the random number generator. If set to None (default), a random seed is generated for each sample operation. |
SampleN
Sample from this expression.
member SampleN(
?n: Expr,
?withReplacement: bool,
?shuffle: bool,
?seed: uint64
) : ExprParameters
| Name | Type | Description |
|---|---|---|
n | Expr (optional) | Number of items to return. Default to 1 |
withReplacement | bool (optional) | Allow values to be sampled more than once. |
shuffle | bool (optional) | Shuffle the order of sampled data points. |
seed | uint64 (optional) | Seed for the random number generator. If set to None (default), a random seed is generated for each sample operation. |
SearchSorted
Find indices where elements should be inserted to maintain order (Binary Search).
member SearchSorted(element: Expr, ?side: SearchSortedSide, ?descending: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
element | Expr | The element expression to insert/search. |
side | SearchSortedSide (optional) | The insertion side (Any, Left, Right). Default is Any. |
descending | bool (optional) | Whether the target column is sorted in descending order. Default is false. |
SetSorted
Indicate that the expression is sorted. This is a hint to the optimizer and does not actually sort the data.
member SetSorted(?descending: bool, ?nullsLast: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
descending | bool (optional) | Whether the column is sorted in descending order. |
nullsLast | bool (optional) | Whether null values appear last. (Placeholder for Polars 0.54+) |
Returns: A new expression with the sorted flag set.
Shift
Shift values by the given number of indices. Positive values shift downstream, negative values shift upstream.
member Shift(n: int64) : Expr
member Shift : unit -> ExprParameters
| Name | Type | Description |
|---|---|---|
n | int64 | - |
Shuffle
Shuffle the contents of this expression.Note this is shuffled independently of any other column or Expression. If you want each row to stay the same use df.sample(shuffle=True)
member Shuffle(?seed: uint64) : ExprParameters
| Name | Type | Description |
|---|---|---|
seed | uint64 (optional) | Seed for the random number generator. If set to None (default), a random seed is generated each time the shuffle is called. |
Sign
Compute the element-wise sign (-1, 0, 1).
member Sign : unit -> ExprSin
Compute the sine of each element.
member Sin : unit -> ExprSinh
Compute the sinh of each element.
member Sinh : unit -> ExprSkew
Compute the sample skewness of a data set.
member Skew(?bias: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
bias | bool (optional) | If False, the calculations are corrected for statistical bias. |
Slice
Slice the expression.
member Slice(offset: int64, ?length: uint64) : ExprParameters
| Name | Type | Description |
|---|---|---|
offset | int64 | The offset of the slice. |
length | uint64 (optional) | The length of the slice. |
Sort
Sort the expression.
member Sort(
?descending: bool,
?nullsLast: bool,
?multithreaded: bool,
?maintainOrder: bool,
?limit: uint32
) : ExprParameters
| Name | Type | Description |
|---|---|---|
descending | bool (optional) | If true, sort in descending order. Default is false. |
nullsLast | bool (optional) | Whether to place null values last. Default is false. |
multithreaded | bool (optional) | If true, sort in multiple threads. Default is true. |
maintainOrder | bool (optional) | If true, maintain the order of equal elements. Default is false. |
limit | uint32 (optional) | Limit the sort output (for optimization purposes). |
SortBy
Sort this column by the ordering of other columns using uniform sorting options.
member SortBy(
by: seq<Expr>,
?descending: seq<bool>,
?nullsLast: seq<bool>,
?multithreaded: bool,
?maintainOrder: bool
) : Expr
member SortBy(
by: seq<Expr>,
?descending: bool,
?nullsLast: bool,
?multithreaded: 'g,
?maintainOrder: 'h
) : 'iParameters
| Name | Type | Description |
|---|---|---|
by | seq<Expr> | Column(s) to sort by. |
descending | seq<bool> (optional) / bool (optional) | Sort in descending order for all columns. |
nullsLast | seq<bool> (optional) / bool (optional) | Place null values last for all columns. |
multithreaded | bool (optional) / 'g (optional) | Sort using multiple threads. |
maintainOrder | bool (optional) / 'h (optional) | Whether the order should be maintained if elements are equal. |
Sqrt
Calculate the square root of the expression.
member Sqrt : unit -> ExprStd
Get the standard deviation value.
member Std(?ddof: byte) : ExprParameters
| Name | Type | Description |
|---|---|---|
ddof | byte (optional) | Delta Degrees of Freedom. Default is 1. |
Sum
Calculate the sum of the values in the group or column.
member Sum : unit -> ExprTail
Get the last n rows.
member Tail(?n: int) : ExprParameters
| Name | Type | Description |
|---|---|---|
n | int (optional) | Number of rows to return. |
Take
LINQ-like alias for Gather.
member Take(indices: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
indices | Expr | - |
Tan
Compute the tangent of each element.
member Tan : unit -> ExprTanh
Compute the tanh of each element.
member Tanh : unit -> ExprToHtml
Generates a rich HTML view of the expression including its compact string representation and AST tree.
member ToHtml : unit -> string
member ToHtml(schema: PolarsSchema) : stringParameters
| Name | Type | Description |
|---|---|---|
schema | PolarsSchema | Schema context to resolve field types. |
Returns: An HTML representation formatted for interactive environments.
ToPhysical
Cast to physical representation of the logical dtype.
member ToPhysical : unit -> ExprToSelector
Convert an expression to a selector.
member ToSelector : unit -> SelectorTopK
Get the k largest elements. Result is sorted descending.
member TopK(k: int) : ExprParameters
| Name | Type | Description |
|---|---|---|
k | int | - |
TopKBy
Get the top k elements determined by the values in the 'by' columns.
member TopKBy(k: int, by: seq<'f>, ?reverse: seq<bool>) : Expr
member TopKBy(k: int, by: 'd, reverse: bool) : Expr
member TopKBy(k: int, by: 'c) : ExprParameters
| Name | Type | Description |
|---|---|---|
k | int | Number of elements to return. |
by | seq<'f> / 'd / 'c | Columns to sort by. |
reverse | seq<bool> (optional) | Reverse the sort order for each by column. Default false. |
Truediv
Perform true division with another expression. Result is always a float.
member Truediv(other: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
other | Expr | - |
Truncate
Truncate numeric data toward zero to decimals number of decimal places.
member Truncate(?decimals: uint32) : ExprParameters
| Name | Type | Description |
|---|---|---|
decimals | uint32 (optional) | Number of decimal places to truncate to. |
Unique
Get unique values of this expression.
member Unique(?maintainOrder: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
maintainOrder | bool (optional) | - |
UniqueCounts
Return a count of the unique values in the order of appearance. This method differs from value_counts in that it does not return the values, only the counts and might be faster
member UniqueCounts : unit -> ExprUpperBound
Calculate the upper bound. Returns a unit Series with the highest value possible for the dtype of this expression.
member UpperBound : unit -> ExprValueCounts
Count the occurrence of unique values.
member ValueCounts(
?sort: bool,
?parallelOn: bool,
?name: string,
?normalize: bool
) : ExprParameters
| Name | Type | Description |
|---|---|---|
sort | bool (optional) | Sort the output by count, in descending order. If set to False (default), the order is non-deterministic. |
parallelOn | bool (optional) | Execute the computation in parallel.This option should likely not be enabled in a group by context, as the computation will already be parallelized per group. |
name | string (optional) | Give the resulting count column a specific name; if normalize is True this defaults to “proportion”, otherwise defaults to “count”. |
normalize | bool (optional) | If True, the count is returned as the relative frequency of unique values normalized to 1.0. |
Returns: Expression of type Struct, mapping unique values to their count (or proportion).
Var
Get the variance value.
member Var(?ddof: byte) : ExprParameters
| Name | Type | Description |
|---|---|---|
ddof | byte (optional) | Delta Degrees of Freedom. Default is 1. |