Skip to content

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-namespacePageDescription
.ArrayExpr.ArrayAccess array operations.
.BinExpr.BinAccess binary operations.
.CatExpr.CatAccess categorical operations.
.DtExpr.DtAccess temporal (date/time) operations.
.ExtExpr.ExtAccess extension datatype operations.
.ListExpr.ListAccess list operations.
.MetaExpr.MetaAccess meta operations.
.NameExpr.NameAccess naming operations (prefix/suffix).
.StrExpr.StrAccess string manipulation operations.
.StructExpr.StructAccess struct operations.

Constructors & Static Methods ​

AsStruct ​

Create a Struct expression from a list of expressions.

fsharp
static member AsStruct(exprs: seq<Expr>) : Expr

Parameters

NameTypeDescription
exprsseq<Expr>-

ConcatExpr ​

Concat multiple expressions into a single expression.

fsharp
static member ConcatExpr(exprs: seq<Expr>, ?rechunk: bool) : Expr

Parameters

NameTypeDescription
exprsseq<Expr>-
rechunkbool (optional)-

ConcatString ​

Concat multiple string expressions into a single string expression.

fsharp
static member ConcatString(exprs: seq<Expr>, ?separator: string, ?ignoreNulls: bool) : Expr

Parameters

NameTypeDescription
exprsseq<Expr>-
separatorstring (optional)-
ignoreNullsbool (optional)-

FormatString ​

Format multiple string expressions into a single formated string expression.

fsharp
static member FormatString(format: string, exprs: seq<Expr>) : Expr

Parameters

NameTypeDescription
formatstring-
exprsseq<Expr>-

SqlExpr ​

Create a Polars Expr from a SQL string.

fsharp
static member SqlExpr(sql: string) : Expr

Parameters

NameTypeDescription
sqlstringThe SQL expression string.

Returns: A Polars Expr representing the SQL logic.


SqlExprs ​

Create an array of Polars Exprs from a collection of SQL strings.

fsharp
static member SqlExprs(sqls: seq<string>) : Expr[]

Parameters

NameTypeDescription
sqlsseq<string>The collection of SQL expression strings.

Returns: An array of Polars Expr objects.


Operators ​

( + ) Addition ​

fsharp
static member op_Addition(lhs: Expr, rhs: Expr) : Expr

Parameters

NameTypeDescription
lhsExpr-
rhsExpr-

( ! ) Logical NOT ​

Logical NOT.

fsharp
static member op_Dereference(e: Expr) : Expr

Parameters

NameTypeDescription
eExpr-

( / ) Division ​

fsharp
static member op_Division(lhs: Expr, rhs: Expr) : Expr

Parameters

NameTypeDescription
lhsExpr-
rhsExpr-

( .&& ) Logical AND ​

Logical AND.

fsharp
static member op_DotAmpAmp(lhs: Expr, rhs: Expr) : Expr

Parameters

NameTypeDescription
lhsExpr-
rhsExpr-

( .!= ) Not Equal ​

Not equal comparison.

fsharp
static member op_DotBangEquals(lhs: Expr, rhs: Expr) : Expr

Parameters

NameTypeDescription
lhsExpr-
rhsExpr-

( .|| ) Logical OR ​

Logical OR.

fsharp
static member op_DotBarBar(lhs: Expr, rhs: Expr) : Expr

Parameters

NameTypeDescription
lhsExpr-
rhsExpr-

( .== ) Equal ​

Equal comparison.

fsharp
static member op_DotEqualsEquals(lhs: Expr, rhs: Expr) : Expr

Parameters

NameTypeDescription
lhsExpr-
rhsExpr-

( .> ) Greater Than ​

Greater than comparison.

fsharp
static member op_DotGreater(lhs: Expr, rhs: Expr) : Expr

Parameters

NameTypeDescription
lhsExpr-
rhsExpr-

( .>= ) Greater Or Equal ​

Greater than or equal comparison.

fsharp
static member op_DotGreaterEquals(lhs: Expr, rhs: Expr) : Expr

Parameters

NameTypeDescription
lhsExpr-
rhsExpr-

( .^ ) Bitwise XOR ​

fsharp
static member op_DotHat(lhs: Expr, rhs: Expr) : Expr

Parameters

NameTypeDescription
lhsExpr-
rhsExpr-

( .< ) Less Than ​

Less than comparison.

fsharp
static member op_DotLess(lhs: Expr, rhs: Expr) : Expr

Parameters

NameTypeDescription
lhsExpr-
rhsExpr-

( .<= ) Less Or Equal ​

Less than or equal comparison.

fsharp
static member op_DotLessEquals(lhs: Expr, rhs: Expr) : Expr

Parameters

NameTypeDescription
lhsExpr-
rhsExpr-

( .** ) Power ​

Power / Exponentiation.

fsharp
static member op_DotMultiplyMultiply(baseExpr: Expr, exponent: Expr) : Expr

Parameters

NameTypeDescription
baseExprExpr-
exponentExpr-

( <<< ) Left Shift ​

Bitwise left shift operator (expr <<< n).

fsharp
static member op_LeftShift(lhs: Expr, rhs: int) : Expr

Parameters

NameTypeDescription
lhsExpr-
rhsint-

( % ) Modulus ​

fsharp
static member op_Modulus(lhs: Expr, rhs: Expr) : Expr

Parameters

NameTypeDescription
lhsExpr-
rhsExpr-

( * ) Multiply ​

fsharp
static member op_Multiply(lhs: Expr, rhs: Expr) : Expr

Parameters

NameTypeDescription
lhsExpr-
rhsExpr-

( >>> ) Right Shift ​

Bitwise right shift operator (expr >>> n).

fsharp
static member op_RightShift(lhs: Expr, rhs: int) : Expr

Parameters

NameTypeDescription
lhsExpr-
rhsint-

( - ) Subtraction ​

fsharp
static member op_Subtraction(lhs: Expr, rhs: Expr) : Expr

Parameters

NameTypeDescription
lhsExpr-
rhsExpr-

( ~- ) UnaryNegation ​

Negates the expression numerically.

fsharp
static member op_UnaryNegation(e: Expr) : Expr

Parameters

NameTypeDescription
eExpr-

Instance Methods ​

Abs ​

Calculate the absolute value of the expression.

fsharp
member Abs : unit -> Expr

Alias ​

Rename the output column.

fsharp
member Alias(name: string) : Expr

Parameters

NameTypeDescription
namestring-

All ​

Check if all values in the boolean expression are true.

This is a boolean aggregation.

fsharp
member All(?ignoreNulls: bool) : Expr

Parameters

NameTypeDescription
ignoreNullsbool (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.

fsharp
member Any(?ignoreNulls: bool) : Expr

Parameters

NameTypeDescription
ignoreNullsbool (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.

fsharp
member Append(other: Expr, ?execUpcast: bool) : Expr

Parameters

NameTypeDescription
otherExprExpression to append.
execUpcastbool (optional)Cast both Series to the same supertype.

ApproxNUnique ​

Approximate count of unique values. This is done using the HyperLogLog++ algorithm for cardinality estimation.

fsharp
member ApproxNUnique : unit -> Expr

ArcCos ​

Compute the arccos of each element.

fsharp
member ArcCos : unit -> Expr

ArcCosh ​

Compute the arccosh of each element.

fsharp
member ArcCosh : unit -> Expr

ArcSin ​

Compute the arcsin of each element.

fsharp
member ArcSin : unit -> Expr

ArcSinh ​

Compute the arcsinh of each element.

fsharp
member ArcSinh : unit -> Expr

ArcTan ​

Compute the arctan of each element.

fsharp
member ArcTan : unit -> Expr

ArcTanh ​

Compute the arctanh of each element.

fsharp
member ArcTanh : unit -> Expr

ArgMax ​

Get the index of the maximum value.

fsharp
member ArgMax : unit -> Expr

ArgMin ​

Get the index of the minimum value.

fsharp
member ArgMin : unit -> Expr

ArgSort ​

Get the index values that would sort this expression.

fsharp
member ArgSort(?descending: bool, ?nullsLast: bool) : Expr

Parameters

NameTypeDescription
descendingbool (optional)If true, sort in descending order. Default is false.
nullsLastbool (optional)If true, place null values last. Default is false.

ArgTrue ​

Return indices where expression evaluates True.

fsharp
member ArgTrue : unit -> Expr

Returns: Expression of data type UInt32.


ArgUnique ​

Get the index of the unique values.

fsharp
member ArgUnique : unit -> Expr

BackwardFill ​

Fill null values with a specific strategy (Backward).

fsharp
member BackwardFill(?limit: int) : Expr

Parameters

NameTypeDescription
limitint (optional)-

BitLeftShift ​

Bitwise left shift (<<).

fsharp
member BitLeftShift(n: int) : Expr

Parameters

NameTypeDescription
nint-

BitRightShift ​

Bitwise right shift (>>).

fsharp
member BitRightShift(n: int) : Expr

Parameters

NameTypeDescription
nint-

BitwiseAnd ​

Perform an aggregation of bitwise ANDs.

fsharp
member BitwiseAnd : unit -> Expr

BitwiseCountOnes ​

Evaluate the number of set bits.

fsharp
member BitwiseCountOnes : unit -> Expr

BitwiseCountZeros ​

Evaluate the number of unset bits.

fsharp
member BitwiseCountZeros : unit -> Expr

BitwiseLeadingOnes ​

Evaluate the number most-significant set bits before seeing an unset bit.

fsharp
member BitwiseLeadingOnes : unit -> Expr

BitwiseLeadingZeros ​

Evaluate the number most-significant unset bits before seeing a set bit.

fsharp
member BitwiseLeadingZeros : unit -> Expr

BitwiseOr ​

Perform an aggregation of bitwise Ors.

fsharp
member BitwiseOr : unit -> Expr

BitwiseTrailingOnes ​

Evaluate the number least-significant set bits before seeing an unset bit.

fsharp
member BitwiseTrailingOnes : unit -> Expr

BitwiseTrailingZeros ​

Evaluate the number least-significant unset bits before seeing a set bit.

fsharp
member BitwiseTrailingZeros : unit -> Expr

BitwiseXor ​

Perform an aggregation of bitwise Xors.

fsharp
member BitwiseXor : unit -> Expr

BottomK ​

Get the k smallest elements. Result is sorted ascending.

fsharp
member BottomK(k: int) : Expr

Parameters

NameTypeDescription
kint-

BottomKBy ​

Get the bottom k elements determined by the values in the 'by' columns.

fsharp
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) : Expr

Parameters

NameTypeDescription
kintNumber of elements to return.
byseq<'e> / 'b / 'aColumn to sort by.
reverseseq<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.

fsharp
member Cast(?strict: bool, ?wrapNumerical: bool) : Expr
member Cast(dtype: DataType, ?strict: bool, ?wrapNumerical: bool) : Expr
member Cast(dtype: DataTypeExpr, ?strict: bool, ?wrapNumerical: bool) : Expr

Parameters

NameTypeDescription
strictbool (optional)-
wrapNumericalbool (optional)-
dtypeDataType / DataTypeExpr-

Cbrt ​

Calculate the cube root of the expression.

fsharp
member Cbrt : unit -> Expr

Ceil ​

Round up to the nearest integer.

fsharp
member Ceil : unit -> Expr

Clip ​

Set values outside the given boundaries to the boundary value.

fsharp
member Clip(?lowerBound: Expr, ?upperBound: Expr) : Expr

Parameters

NameTypeDescription
lowerBoundExpr (optional)Lower bound. Accepts expression input.
upperBoundExpr (optional)Upper bound. Accepts expression input.

Clone ​

fsharp
member Clone : unit -> Expr

Coalesce ​

Returns the first non-null value between this expression and other expressions. Syntactic sugar for pl.coalesce(this, others).

fsharp
member Coalesce(others: seq<Expr>) : Expr

Parameters

NameTypeDescription
othersseq<Expr>Fallback expressions, column names, or literals.

Returns: A new coalesced expression.


Cos ​

Compute the cosine of each element.

fsharp
member Cos : unit -> Expr

Cosh ​

Compute the cosh of each element.

fsharp
member Cosh : unit -> Expr

Cot ​

Compute the cotangent of each element.

fsharp
member Cot : unit -> Expr

Count ​

Count the number of valid (non-null) values.

fsharp
member Count : unit -> Expr

CumCount ​

Get an array with the cumulative count computed at every element.

fsharp
member CumCount(?reverse: bool) : Expr

Parameters

NameTypeDescription
reversebool (optional)Reverse the operation.

CumMax ​

Get an array with the cumulative max computed at every element.

fsharp
member CumMax(?reverse: bool) : Expr

Parameters

NameTypeDescription
reversebool (optional)Reverse the operation.

CumMin ​

Get an array with the cumulative min computed at every element.

fsharp
member CumMin(?reverse: bool) : Expr

Parameters

NameTypeDescription
reversebool (optional)Reverse the operation.

CumProd ​

Get an array with the cumulative prod computed at every element.

fsharp
member CumProd(?reverse: bool) : Expr

Parameters

NameTypeDescription
reversebool (optional)Reverse the operation.

CumSum ​

Get an array with the cumulative sum computed at every element.

fsharp
member CumSum(?reverse: bool) : Expr

Parameters

NameTypeDescription
reversebool (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.

fsharp
member CumulativeEval(expr: Expr, ?minSamples: int) : Expr

Parameters

NameTypeDescription
exprExprExpression to evaluate
minSamplesint (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.

fsharp
member Cut(
    breaks: seq<float>,
    ?labels: seq<string>,
    ?leftClosed: bool,
    ?includeBreaks: bool
) : Expr

Parameters

NameTypeDescription
breaksseq<float>List of unique cut points.
labelsseq<string> (optional)Names of the categories. The number of labels must be equal to the number of cut points plus one.
leftClosedbool (optional)Set the intervals to be left-closed instead of right-closed.
includeBreaksbool (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.

fsharp
member Degrees : unit -> Expr

Diff ​

Calculate the difference with the previous value (n-th lag). Null values are propagated.

fsharp
member Diff(?n: int64, ?nullBehavior: NullBehavior) : Expr

Parameters

NameTypeDescription
nint64 (optional)-
nullBehaviorNullBehavior (optional)-

Dot ​

Compute the dot/inner product between two expressions.

fsharp
member Dot(other: Expr) : Expr

Parameters

NameTypeDescription
otherExpr-

DropNans ​

Drop NaN values.

fsharp
member DropNans : unit -> Expr

DropNulls ​

Drop null values.

fsharp
member DropNulls : unit -> Expr

Entropy ​

Computes the entropy. Uses the formula -sum(pk * log(pk)) where pk are discrete probabilities.

fsharp
member Entropy(?baseVal: float, ?normalize: bool) : Expr

Parameters

NameTypeDescription
baseValfloat (optional)Given base, defaults to e
normalizebool (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)

fsharp
member EqMissing(other: Expr) : Expr

Parameters

NameTypeDescription
otherExpr-

EwmMean ​

Compute exponentially-weighted moving average.

fsharp
member EwmMean(
    alpha: float,
    ?adjust: bool,
    ?bias: bool,
    ?minPeriods: int,
    ?ignoreNulls: bool
) : Expr

Parameters

NameTypeDescription
alphafloatSpecify smoothing factor alpha directly.
Constraint: 0 < alpha <= 1
adjustbool (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.
biasbool (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.
minPeriodsint (optional)Minimum number of observations in window required to have a value (otherwise result is null).
ignoreNullsbool (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.

fsharp
member EwmMeanBy(by: Expr, halfLife: string) : Expr

Parameters

NameTypeDescription
byExprThe column used to determine the distance between observations.
Supported data types: Date, DateTime, UInt64, UInt32, Int64, or Int32.
halfLifestringThe unit over which an observation decays to half its value.
Supported string formats:

- Time unitsns (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.

fsharp
member EwmStd(
    alpha: float,
    ?adjust: bool,
    ?bias: bool,
    ?minPeriods: int,
    ?ignoreNulls: bool
) : Expr

Parameters

NameTypeDescription
alphafloatSpecify smoothing factor alpha directly.
Constraint: 0 < alpha <= 1
adjustbool (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.
biasbool (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.
minPeriodsint (optional)Minimum number of observations in window required to have a value (otherwise result is null).
ignoreNullsbool (optional)Ignore missing values when calculating weights.

Returns: A new expression representing the EWM standard deviation.


EwmSum ​

Compute exponentially-weighted moving sum.

fsharp
member EwmSum(
    alpha: float,
    ?adjust: bool,
    ?bias: bool,
    ?minPeriods: int,
    ?ignoreNulls: bool
) : Expr

Parameters

NameTypeDescription
alphafloat-
adjustbool (optional)-
biasbool (optional)-
minPeriodsint (optional)-
ignoreNullsbool (optional)-

EwmSumBy ​

Compute exponentially-weighted moving sum based on a temporal or index column.

fsharp
member EwmSumBy(by: Expr, halfLife: string) : Expr

Parameters

NameTypeDescription
byExpr-
halfLifestring-

EwmVar ​

Compute exponentially-weighted moving variance.

fsharp
member EwmVar(
    alpha: float,
    ?adjust: bool,
    ?bias: bool,
    ?minPeriods: int,
    ?ignoreNulls: bool
) : Expr

Parameters

NameTypeDescription
alphafloatSpecify smoothing factor alpha directly.
Constraint: 0 < alpha <= 1
adjustbool (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.
biasbool (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.
minPeriodsint (optional)Minimum number of observations in window required to have a value (otherwise result is null).
ignoreNullsbool (optional)Ignore missing values when calculating weights.

Returns: A new expression representing the EWM variance.


Exclude ​

fsharp
member Exclude(names: seq<string>) : Expr
member Exclude(dtypes: seq<DataType>) : Expr

Parameters

NameTypeDescription
namesseq<string>-
dtypesseq<DataType>-

Exp ​

Calculate the power of the Euler's number.

fsharp
member Exp : unit -> Expr

Explode ​

Explode a list column into multiple rows.

fsharp
member Explode(?emptyAsNull: bool, ?keepNulls: bool) : Expr

Parameters

NameTypeDescription
emptyAsNullbool (optional)-
keepNullsbool (optional)-

ExtendConstant ​

Extending the Series with ‘n’ copies of a value.

fsharp
member ExtendConstant(value: Expr, n: Expr) : Expr

Parameters

NameTypeDescription
valueExprA constant literal value or a unit expression with which to extend the expression result Series; can pass None to extend with nulls.
nExprThe number of additional values that will be added.

FillNan ​

Fill NaN values with the given fill value.

fsharp
member FillNan(fillValue: Expr) : Expr

Parameters

NameTypeDescription
fillValueExprThe 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.

fsharp
member FillNull(value: Expr) : Expr
member FillNull(strategy: FillNullStrategy, ?limit: int) : Expr
member FillNull(value: 'T) : Expr

Parameters

NameTypeDescription
valueExpr / 'TValue to fill null values with.
strategyFillNullStrategyStrategy to use for filling null values.
limitint (optional)Max number of consecutive nulls to fill. (Default null = infinite)

FillNull$W ​

fsharp
member FillNull$W(this: Expr, value: 'T) : Expr

Parameters

NameTypeDescription
thisExpr-
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.

fsharp
member Filter(predicate: Expr) : Expr

Parameters

NameTypeDescription
predicateExprBoolean expression used to filter the current expression.

Returns: A new expression with filtered values.


First ​

Get the first value of the group/series.

fsharp
member First(?ignoreNulls: bool) : Expr

Parameters

NameTypeDescription
ignoreNullsbool (optional)-

Returns: A new expression representing the first value.


Floor ​

Round down to the nearest integer.

fsharp
member Floor : unit -> Expr

FloorDiv ​

Integer division (floor division).

fsharp
member FloorDiv(other: Expr) : Expr

Parameters

NameTypeDescription
otherExpr-

ForwardFill ​

Fill null values with a specific strategy (Forward).

fsharp
member ForwardFill(?limit: int) : Expr

Parameters

NameTypeDescription
limitint (optional)Max number of consecutive nulls to fill. (Default null = infinite)

Gather ​

Gather values by an index expression.

fsharp
member Gather(indices: Expr) : Expr

Parameters

NameTypeDescription
indicesExpr-

GatherEvery ​

Take every nth value starting from an offset.

fsharp
member GatherEvery(n: uint64, ?offset: uint64) : Expr

Parameters

NameTypeDescription
nuint64-
offsetuint64 (optional)-

Get ​

Get a single value by index. Returns a scalar.

fsharp
member Get(index: Expr, ?nullOnOutOfBounds: bool) : Expr
member Get(index: uint64, ?nullOnOutOfBounds: bool) : Expr

Parameters

NameTypeDescription
indexExpr / uint64The index expression.
nullOnOutOfBoundsbool (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.

fsharp
member HasNulls : unit -> Expr

Hash ​

Hash the elements in the selection.The hash value is of type UInt64.

fsharp
member Hash(
    ?seed: uint64,
    ?seed1: uint64,
    ?seed2: uint64,
    ?seed3: uint64
) : Expr

Parameters

NameTypeDescription
seeduint64 (optional)Random seed parameter. Defaults to 0.
seed1uint64 (optional)Random seed parameter. Defaults to seed if not set.
seed2uint64 (optional)Random seed parameter. Defaults to seed if not set.
seed3uint64 (optional)Random seed parameter. Defaults to seed if not set.

Get the first n rows.

fsharp
member Head(?n: int) : Expr

Parameters

NameTypeDescription
nint (optional)Number of rows to return.

Hist ​

Bin values into buckets and count their occurrences.

fsharp
member Hist(
    ?bins: Expr,
    ?binCount: int,
    ?includeCategory: bool,
    ?includeBreakPoint: bool
) : Expr

Parameters

NameTypeDescription
binsExpr (optional)Bin edges. If None given, we determine the edges based on the data.
binCountint (optional)If bins is not provided, binCount uniform bins are created that fully encompass the data.
includeCategorybool (optional)Include a column that indicates the upper breakpoint.
includeBreakPointbool (optional)Include a column that shows the intervals as categories.

Implode ​

Implode multiple rows to a list.

fsharp
member Implode(?maintainOrder: bool) : Expr

Parameters

NameTypeDescription
maintainOrderbool (optional)-

IndexOf ​

Find the index of the first occurrence of a specific value.

fsharp
member IndexOf(element: Expr) : Expr

Parameters

NameTypeDescription
elementExprThe element expression to search for.

Inspect ​

Print the value that this expression evaluates to and pass on the value.

fsharp
member Inspect(?format: string) : Expr

Parameters

NameTypeDescription
formatstring (optional)-

Interpolate ​

Interpolate intermediate values. The interpolation method can be configured.

Nulls at the beginning and end of the series remain null.

fsharp
member Interpolate(?method: InterpolationMethod) : Expr

Parameters

NameTypeDescription
methodInterpolationMethod (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.

fsharp
member InterpolateBy(by: Expr) : Expr

Parameters

NameTypeDescription
byExprThe 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).

fsharp
member IsBetween(lower: Expr, upper: Expr, ?closedInterval: ClosedInterval) : Expr

Parameters

NameTypeDescription
lowerExpr-
upperExpr-
closedIntervalClosedInterval (optional)-

IsClose ​

Check if this expression is close, i.e. almost equal, to the other expression.

fsharp
member IsClose(
    other: Expr,
    ?absTol: float,
    ?relTol: float,
    ?nansEqual: bool
) : Expr

Parameters

NameTypeDescription
otherExprA literal or expression value to compare with.
absTolfloat (optional)Absolute tolerance. This is the maximum allowed absolute difference betweentwo values. Must be non-negative.
relTolfloat (optional)Relative tolerance. This is the maximum allowed difference between two values, relative to the larger absolute value. Must be non-negative.
nansEqualbool (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.

fsharp
member IsDuplicated : unit -> Expr

IsEmpty ​

Return whether the column is empty.

fsharp
member IsEmpty(?ignoreNulls: bool) : Expr

Parameters

NameTypeDescription
ignoreNullsbool (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.

fsharp
member IsFinite : unit -> Expr

Returns: Expression of data type Boolean.


IsFirstDistinct ​

Return a boolean mask indicating the first occurrence of each distinct value.

fsharp
member IsFirstDistinct : unit -> Expr

Returns: Expression of data type Boolean.


IsIn ​

Check if the value is in given collection.

fsharp
member IsIn(other: Expr, ?nullsEqual: bool) : Expr

Parameters

NameTypeDescription
otherExpr-
nullsEqualbool (optional)-

IsInFinite ​

Returns a boolean Series indicating which values are infinite.

fsharp
member IsInFinite : unit -> Expr

Returns: Expression of data type Boolean.


IsLastDistinct ​

Return a boolean mask indicating the last occurrence of each distinct value.

fsharp
member IsLastDistinct : unit -> Expr

Returns: Expression of data type Boolean.


IsNan ​

Returns a boolean Series indicating which values are NaN.

fsharp
member IsNan : unit -> Expr

IsNotNan ​

Returns a boolean Series indicating which values are not NaN.

fsharp
member IsNotNan : unit -> Expr

IsNotNull ​

Evaluate whether the expression is not null.

fsharp
member IsNotNull : unit -> Expr

IsNull ​

Evaluate whether the expression is null.

fsharp
member IsNull : unit -> Expr

IsSorted ​

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.

fsharp
member IsSorted(?descending: bool, ?nullsLast: bool) : Expr

Parameters

NameTypeDescription
descendingbool (optional)Checks if the expression is sorted in descending order.Defaults to False.
nullsLastbool (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.

fsharp
member IsUnique : unit -> Expr

Item ​

Access one element in this array/list/tuple expression.

fsharp
member Item(?allowEmpty: bool) : Expr

Parameters

NameTypeDescription
allowEmptybool (optional)-

Kurtosis ​

Compute the kurtosis (Fisher or Pearson) of a dataset.

fsharp
member Kurtosis(?fisher: bool, ?bias: bool) : Expr

Parameters

NameTypeDescription
fisherbool (optional)If True, Fisher’s definition is used (normal ==> 0.0). If False, Pearson’s definition is used (normal ==> 3.0).
biasbool (optional)If False, the calculations are corrected for statistical bias.

Last ​

Get the last value of the group/series.

fsharp
member Last(?ignoreNulls: bool) : Expr

Parameters

NameTypeDescription
ignoreNullsbool (optional)-

Returns: A new expression representing the last value.


Len ​

Return the number of elements in the column. Null values count towards the total.

fsharp
member Len : unit -> Expr

Ln ​

Calculate the natural logarithm (base e).

fsharp
member Ln : unit -> Expr

Log ​

Calculate the logarithm with the given base.

Compute the logarithm with base e.

Compute the logarithm with the given expression as base.

fsharp
member Log(baseVal: float) : Expr
member Log : unit -> Expr
member Log(baseExpr: Expr) : Expr

Parameters

NameTypeDescription
baseValfloat-
baseExprExpr-

Log10 ​

Compute the base 10 logarithm of the input array, element-wise.

fsharp
member Log10 : unit -> Expr

Log1p ​

Compute the natural logarithm of each element plus one.This computes log(1 + x) but is more numerically stable for x close to zero.

fsharp
member Log1p : unit -> Expr

LowerBound ​

Calculate the lower bound. Returns a unit Series with the lowest value possible for the dtype of this expression.

fsharp
member LowerBound : unit -> Expr

Map ​

Map values using a standard F# function. Automatically wraps it using Udf.map.

fsharp
member Map(f: ('T -> 'U)) : Expr

Parameters

NameTypeDescription
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.

fsharp
member MapArrow(mapping: (IArrowArray -> IArrowArray), ?outputType: DataType) : Expr

Parameters

NameTypeDescription
mapping(IArrowArray -> IArrowArray)Function mapping IArrowArray -> IArrowArray.
outputTypeDataType (optional)The expected output DataType (optional).

MapOption ​

Map values using an F# function that handles Options. Automatically wraps it using Udf.mapOption.

fsharp
member MapOption(f: ('T option -> 'U option)) : Expr

Parameters

NameTypeDescription
f('T option -> 'U option)-

MapValueOption ​

Map values using an F# function that handles Value Options. Automatically wraps it using Udf.mapValueOption.

fsharp
member MapValueOption(f: ('T voption -> 'U voption)) : Expr

Parameters

NameTypeDescription
f('T voption -> 'U voption)-

Max ​

Get the max value.

fsharp
member Max : unit -> Expr

MaxBy ​

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.

fsharp
member MaxBy(by: Expr) : Expr

Parameters

NameTypeDescription
byExpr-

Mean ​

Calculate the average of the values in the group or column.

fsharp
member Mean : unit -> Expr

Median ​

Get the median value.

fsharp
member Median : unit -> Expr

Min ​

Get the min value.

fsharp
member Min : unit -> Expr

MinBy ​

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.

fsharp
member MinBy(by: Expr) : Expr

Parameters

NameTypeDescription
byExpr-

Mod ​

Modulo operator (remainder).

fsharp
member Mod(other: Expr) : Expr

Parameters

NameTypeDescription
otherExpr-

Mode ​

Get the mode value.

fsharp
member Mode : unit -> Expr

NUnique ​

Count unique values. Notes: Null is considered to be a unique value for the purposes of this operation.

fsharp
member NUnique : unit -> Expr

NanMax ​

Get maximum value, but propagate/poison encountered NaN values.

fsharp
member NanMax : unit -> Expr

NanMin ​

Get minimum value, but propagate/poison encountered NaN values.

fsharp
member NanMin : unit -> Expr

NeqMissing ​

Check if this expression is NOT equal to another, treating nulls as valid values. (e.g., Null != Null is False, 5 != Null is True)

fsharp
member NeqMissing(other: Expr) : Expr

Parameters

NameTypeDescription
otherExpr-

NullCount ​

Count the number of null.

fsharp
member NullCount : unit -> Expr

Over ​

Apply a window function over specific partition columns.

fsharp
member Over(
    ?partitionBy: seq<Expr>,
    ?orderBy: seq<Expr>,
    ?descending: bool,
    ?nullsLast: bool,
    ?multithreaded: bool,
    ?maintainOrder: bool,
    ?mapping: WindowMappingStrategy
) : Expr

member Over(partitionCol: Expr) : Expr

Parameters

NameTypeDescription
partitionByseq<Expr> (optional)-
orderByseq<Expr> (optional)-
descendingbool (optional)-
nullsLastbool (optional)-
multithreadedbool (optional)-
maintainOrderbool (optional)-
mappingWindowMappingStrategy (optional)-
partitionColExprColumn to partition by.

Example

fsharp
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.

fsharp
member PctChange(?n: int) : Expr

Parameters

NameTypeDescription
nint (optional)periods to shift for forming percent change.

PeakMax ​

Get a boolean mask of the local maximum peaks.

fsharp
member PeakMax : unit -> Expr

PeakMin ​

Get a boolean mask of the local minimum peaks.

fsharp
member PeakMin : unit -> Expr

Pipe ​

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.

fsharp
member Pipe(func: (Expr -> 'T)) : 'T

Parameters

NameTypeDescription
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.

fsharp
member Pow(exponent: Expr) : Expr
member Pow(exponent: float) : Expr
member Pow(exponent: int) : Expr
member Pow(exponent: float32) : Expr
member Pow(exponent: int64) : Expr

Parameters

NameTypeDescription
exponentExpr / float / int / float32 / int64-

Product ​

Compute the product of an expression

fsharp
member Product : unit -> Expr

QCut ​

Bin continuous values into discrete categories based on their quantiles.

fsharp
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
) : Expr

Parameters

NameTypeDescription
quantilesseq<float> / intEither a list of quantile probabilities between 0 and 1 or a positive integer determining the number of bins with uniform probability.
labelsseq<string> (optional)Names of the categories. The number of labels must be equal to the number of categories.
leftClosedbool (optional)Set the intervals to be left-closed instead of right-closed.
allowDuplicatesbool (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.
includeBreaksbool (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.

fsharp
member Quantile(quantile: float, ?interpolation: QuantileMethod) : Expr

Parameters

NameTypeDescription
quantilefloatQuantile between 0.0 and 1.0.
interpolationQuantileMethod (optional)['nearest’, ‘higher’, ‘lower’, ‘midpoint’, ‘linear’] Interpolation method.

Radians ​

Convert from degrees to radians.

fsharp
member Radians : unit -> Expr

Rank ​

Assign ranks to data, dealing with ties appropriately.

fsharp
member Rank(?method: RankMethod, ?descending: bool, ?seed: uint64) : Expr

Parameters

NameTypeDescription
methodRankMethod (optional)The method used to assign ranks to tied elements. See RankMethod for details. Default is RankMethod.Average.
descendingbool (optional)Rank in descending order.
seeduint64 (optional)If method="random", use this as seed.

Rechunk ​

Create a single chunk of memory for this Series.

fsharp
member Rechunk : unit -> Expr

Reinterpret ​

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.

fsharp
member Reinterpret(?signed: bool) : Expr
member Reinterpret(dtype: DataType) : Expr

Parameters

NameTypeDescription
signedbool (optional)If True, reinterpret as signed integer. Otherwise, reinterpret as unsigned integer.
dtypeDataTypeDataType to reinterpret to.

Rem ​

Alias for Mod.

fsharp
member Rem(other: Expr) : Expr

Parameters

NameTypeDescription
otherExpr-

RepeatBy ​

Repeat the elements in this Series as specified in the given expression. The repeated elements are expanded into a List.

fsharp
member RepeatBy(by: Expr) : Expr

Parameters

NameTypeDescription
byExprNumeric 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.

fsharp
member Replace(old: Expr, newExpr: Expr) : Expr
member Replace(oldVal: 'Old, newVal: 'New) : Expr

Parameters

NameTypeDescription
oldExprValue or sequence of values to replace. Accepts expression input.
newExprExprValue or sequence of values to replace by. Accepts expression input.
oldVal'Old-
newVal'New-

Replace$W ​

fsharp
member Replace$W(
    op_Dollar1: (LitMechanism -> ('New -> Expr)),
    this: Expr,
    oldVal: 'Old,
    newVal: 'New
) : Expr

Parameters

NameTypeDescription
op_Dollar1(LitMechanism -> ('New -> Expr))-
thisExpr-
oldVal'Old-
newVal'New-

ReplaceStrict ​

Replace all values by different values.

fsharp
member ReplaceStrict(
    old: Expr,
    newExpr: Expr,
    ?defaultExpr: Expr,
    ?returnDataType: DataTypeExpr
) : Expr

Parameters

NameTypeDescription
oldExprValue or sequence of values to replace. Accepts expression input. Sequences are parsed as Series, other non-expression inputs are parsed as literals.
newExprExprValue 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.
defaultExprExpr (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.
returnDataTypeDataTypeExpr (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.

fsharp
member Reshape(dimensions: seq<int64>) : Expr

Parameters

NameTypeDescription
dimensionsseq<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.

fsharp
member Reverse : unit -> Expr

Returns: 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.

fsharp
member Rle : unit -> Expr

Returns: 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.

fsharp
member RleId : unit -> Expr

Returns: Expression/Series of data type UInt32.


RollingKurtosis ​

Apply a rolling Kurtosis over a window.

fsharp
member RollingKurtosis(
    windowSize: Dur,
    ?minPeriod: int,
    ?weights: float[],
    ?center: bool,
    ?fisher: bool,
    ?bias: bool
) : Expr

Parameters

NameTypeDescription
windowSizeDurThe size of the window formatted as a string duration.
Examples: "3i" (3 index rows), "1d" (1 day), "1h" (1 hour).
minPeriodint (optional)The minimum number of observations in the window required to have a value (otherwise null).
weightsfloat[] (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).
centerbool (optional)If true, the window is centered on the current observation.
Default is false (right-aligned window, [i-window, i]).
fisherbool (optional)If True, Fisher’s definition is used (normal ==> 0.0). If False, Pearson’s definition is used (normal ==> 3.0).
biasbool (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.

fsharp
member RollingMax(
    windowSize: Dur,
    ?minPeriod: int,
    ?weights: float[],
    ?center: bool
) : Expr

Parameters

NameTypeDescription
windowSizeDurThe size of the window formatted as a string duration.
Examples: "3i" (3 index rows), "1d" (1 day), "1h" (1 hour).
minPeriodint (optional)The minimum number of observations in the window required to have a value (otherwise null).
weightsfloat[] (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).
centerbool (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).

fsharp
member RollingMaxBy(
    windowSize: Dur,
    by: Expr,
    ?closed: ClosedInterval,
    ?minPeriod: int
) : Expr

Parameters

NameTypeDescription
windowSizeDurThe size of the dynamic window.
Supported duration strings: "1d", "2h", "10s", "500ms", etc.
byExprThe column used to define the window (the "time" axis).
Typically a Date or DateTime column, but can also be monotonic integers.
closedClosedInterval (optional)Defines how the window interval is closed. Default is ClosedWindow.Left``[t - window, t).
minPeriodint (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.

fsharp
member RollingMean(
    windowSize: Dur,
    ?minPeriod: int,
    ?weights: float[],
    ?center: bool
) : Expr

Parameters

NameTypeDescription
windowSizeDurThe size of the window formatted as a string duration.
Examples: "3i" (3 index rows), "1d" (1 day), "1h" (1 hour).
minPeriodint (optional)The minimum number of observations in the window required to have a value (otherwise null).
weightsfloat[] (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).
centerbool (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).

fsharp
member RollingMeanBy(
    windowSize: Dur,
    by: Expr,
    ?closed: ClosedInterval,
    ?minPeriod: int
) : Expr

Parameters

NameTypeDescription
windowSizeDurThe size of the dynamic window.
Supported duration strings: "1d", "2h", "10s", "500ms", etc.
byExprThe column used to define the window (the "time" axis).
Typically a Date or DateTime column, but can also be monotonic integers.
closedClosedInterval (optional)Defines how the window interval is closed. Default is ClosedWindow.Left``[t - window, t).
minPeriodint (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.

fsharp
member RollingMedian(
    windowSize: Dur,
    ?minPeriod: int,
    ?weights: float[],
    ?center: bool
) : Expr

Parameters

NameTypeDescription
windowSizeDurThe size of the window formatted as a string duration.
Examples: "3i" (3 index rows), "1d" (1 day), "1h" (1 hour).
minPeriodint (optional)The minimum number of observations in the window required to have a value (otherwise null).
weightsfloat[] (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).
centerbool (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).

fsharp
member RollingMedianBy(
    windowSize: Dur,
    by: Expr,
    ?closed: ClosedInterval,
    ?minPeriod: int
) : Expr

Parameters

NameTypeDescription
windowSizeDurThe size of the time window as a TimeSpan.
This will be automatically converted to a Polars duration string (e.g., 01:30:00 -> "1h30m").
byExprThe column used to define the window (the "time" axis).
Typically a Date or DateTime column, but can also be monotonic integers.
closedClosedInterval (optional)Defines how the window interval is closed. Default is ClosedWindow.Left``[t - window, t).
minPeriodint (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.

fsharp
member RollingMin(
    windowSize: Dur,
    ?minPeriod: int,
    ?weights: float[],
    ?center: bool
) : Expr

Parameters

NameTypeDescription
windowSizeDurThe size of the window formatted as a string duration.
Examples: "3i" (3 index rows), "1d" (1 day), "1h" (1 hour).
minPeriodint (optional)The minimum number of observations in the window required to have a value (otherwise null).
weightsfloat[] (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).
centerbool (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).

fsharp
member RollingMinBy(
    windowSize: Dur,
    by: Expr,
    ?closed: ClosedInterval,
    ?minPeriod: int
) : Expr

Parameters

NameTypeDescription
windowSizeDurThe size of the dynamic window.
Supported duration strings: "1d", "2h", "10s", "500ms", etc.
byExprThe column used to define the window (the "time" axis).
Typically a Date or DateTime column, but can also be monotonic integers.
closedClosedInterval (optional)Defines how the window interval is closed. Default is ClosedWindow.Left``[t - window, t).
minPeriodint (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.

fsharp
member RollingQuantile(
    quantile: float,
    method: QuantileMethod,
    windowSize: Dur,
    ?minPeriod: int,
    ?weights: float[],
    ?center: bool
) : Expr

Parameters

NameTypeDescription
quantilefloatQuantile between 0.0 and 1.0 (e.g., 0.5 for median).
methodQuantileMethodInterpolation method when the quantile lies between two data points.
windowSizeDurThe size of the window.
Format: "3i" (3 rows) or just a number string "3".

For time-based windows (e.g. "2h"), use RollingQuantileBy instead.
minPeriodint (optional)The minimum number of observations in the window required to have a value (otherwise null).
weightsfloat[] (optional)Optional weights for the window. The length must match the parsed window size.
If null, equal weights are used.
centerbool (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).

fsharp
member RollingQuantileBy(
    quantile: float,
    method: QuantileMethod,
    windowSize: Dur,
    by: Expr,
    ?closed: ClosedInterval,
    ?minPeriod: int
) : Expr

Parameters

NameTypeDescription
quantilefloatQuantile between 0.0 and 1.0 (e.g., 0.5 for median).
methodQuantileMethodInterpolation method when the quantile lies between two data points.
windowSizeDurThe size of the time window as a TimeSpan.
This will be automatically converted to a Polars duration string (e.g., 01:30:00 -> "1h30m").
byExprThe column used to define the window (the "time" axis).
Typically a Date or DateTime column, but can also be monotonic integers.
closedClosedInterval (optional)Defines how the window interval is closed. Default is ClosedWindow.Left``[t - window, t).
minPeriodint (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.

fsharp
member RollingRank(
    windowSize: Dur,
    ?minPeriod: int,
    ?method: RankMethod,
    ?seed: uint64,
    ?weights: float[],
    ?center: bool
) : Expr

Parameters

NameTypeDescription
windowSizeDurThe size of the time window as a TimeSpan.
This will be automatically converted to a Polars duration string (e.g., 01:30:00 -> "1h30m").
minPeriodint (optional)The minimum number of observations in the window required to have a value (otherwise null).
methodRankMethod (optional)The method used to assign ranks to tied elements. See RankMethod for details. Default is RankMethod.Average.
seeduint64 (optional)If method="random", use this as seed.
weightsfloat[] (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).
centerbool (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).

fsharp
member RollingRankBy(
    windowSize: Dur,
    by: Expr,
    ?method: RollingRankMethod,
    ?seed: uint64,
    ?closed: ClosedInterval,
    ?minPeriod: int
) : Expr

Parameters

NameTypeDescription
windowSizeDurThe size of the dynamic window.
Supported duration strings: "1d", "2h", "10s", "500ms", etc.
byExprThe column used to define the window (the "time" axis).
Typically a Date or DateTime column, but can also be monotonic integers.
methodRollingRankMethod (optional)The method used to assign ranks to tied elements.
seeduint64 (optional)Seed for the random method (only relevant when method is Random).
closedClosedInterval (optional)Defines how the window interval is closed. Default is ClosedWindow.Left``[t - window, t).
minPeriodint (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.

fsharp
member RollingSkew(
    windowSize: Dur,
    ?minPeriod: int,
    ?weights: float[],
    ?center: bool,
    ?bias: bool
) : Expr

Parameters

NameTypeDescription
windowSizeDurThe size of the window formatted as a string duration.
Examples: "3i" (3 index rows), "1d" (1 day), "1h" (1 hour).
minPeriodint (optional)The minimum number of observations in the window required to have a value (otherwise null).
weightsfloat[] (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).
centerbool (optional)If true, the window is centered on the current observation.
Default is false (right-aligned window, [i-window, i]).
biasbool (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.

fsharp
member RollingStd(
    windowSize: Dur,
    ?minPeriod: int,
    ?weights: float[],
    ?center: bool
) : Expr

Parameters

NameTypeDescription
windowSizeDurThe size of the window formatted as a string duration.
Examples: "3i" (3 index rows), "1d" (1 day), "1h" (1 hour).
minPeriodint (optional)The minimum number of observations in the window required to have a value (otherwise null).
weightsfloat[] (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).
centerbool (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).

fsharp
member RollingStdBy(
    windowSize: Dur,
    by: Expr,
    ?closed: ClosedInterval,
    ?minPeriod: int
) : Expr

Parameters

NameTypeDescription
windowSizeDurThe size of the dynamic window.
Supported duration strings: "1d", "2h", "10s", "500ms", etc.
byExprThe column used to define the window (the "time" axis).
Typically a Date or DateTime column, but can also be monotonic integers.
closedClosedInterval (optional)Defines how the window interval is closed. Default is ClosedWindow.Left``[t - window, t).
minPeriodint (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.

fsharp
member RollingSum(
    windowSize: Dur,
    ?minPeriod: int,
    ?weights: float[],
    ?center: bool
) : Expr

Parameters

NameTypeDescription
windowSizeDurThe size of the window formatted as a string duration.
Examples: "3i" (3 index rows), "1d" (1 day), "1h" (1 hour).
minPeriodint (optional)The minimum number of observations in the window required to have a value (otherwise null).
weightsfloat[] (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).
centerbool (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).

fsharp
member RollingSumBy(
    windowSize: Dur,
    by: Expr,
    ?closed: ClosedInterval,
    ?minPeriod: int
) : Expr

Parameters

NameTypeDescription
windowSizeDurThe size of the dynamic window.
Supported duration strings: "1d", "2h", "10s", "500ms", etc.
byExprThe column used to define the window (the "time" axis).
Typically a Date or DateTime column, but can also be monotonic integers.
closedClosedInterval (optional)Defines how the window interval is closed. Default is ClosedWindow.Left``[t - window, t).
minPeriodint (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.

fsharp
member RollingVar(
    windowSize: Dur,
    ?minPeriod: int,
    ?weights: float[],
    ?center: bool,
    ?ddof: byte
) : Expr

Parameters

NameTypeDescription
windowSizeDurThe size of the window formatted as a string duration.
Examples: "3i" (3 index rows), "1d" (1 day), "1h" (1 hour).
minPeriodint (optional)The minimum number of observations in the window required to have a value (otherwise null).
weightsfloat[] (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).
centerbool (optional)If true, the window is centered on the current observation.
Default is false (right-aligned window, [i-window, i]).
ddofbyte (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).

fsharp
member RollingVarBy(
    windowSize: Dur,
    by: Expr,
    ?closed: ClosedInterval,
    ?minPeriod: int,
    ?ddof: byte
) : Expr

Parameters

NameTypeDescription
windowSizeDurThe size of the dynamic window.
Supported duration strings: "1d", "2h", "10s", "500ms", etc.
byExprThe column used to define the window (the "time" axis).
Typically a Date or DateTime column, but can also be monotonic integers.
closedClosedInterval (optional)Defines how the window interval is closed. Default is ClosedWindow.Left``[t - window, t).
minPeriodint (optional)The minimum number of observations in the window required to have a non-null result.
ddofbyte (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.

fsharp
member Round(?decimals: uint32, ?mode: RoundMode) : Expr

Parameters

NameTypeDescription
decimalsuint32 (optional)Number of decimals to round by.
modeRoundMode (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.

fsharp
member RoundSigFigs(digits: int) : Expr

Parameters

NameTypeDescription
digitsintNumber of significant figures to round to.

SampleFrac ​

Sample from this expression.

fsharp
member SampleFrac(
    fraction: Expr,
    ?withReplacement: bool,
    ?shuffle: bool,
    ?seed: uint64
) : Expr

Parameters

NameTypeDescription
fractionExprFraction of items to return.
withReplacementbool (optional)Allow values to be sampled more than once.
shufflebool (optional)Shuffle the order of sampled data points.
seeduint64 (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.

fsharp
member SampleN(
    ?n: Expr,
    ?withReplacement: bool,
    ?shuffle: bool,
    ?seed: uint64
) : Expr

Parameters

NameTypeDescription
nExpr (optional)Number of items to return. Default to 1
withReplacementbool (optional)Allow values to be sampled more than once.
shufflebool (optional)Shuffle the order of sampled data points.
seeduint64 (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).

fsharp
member SearchSorted(element: Expr, ?side: SearchSortedSide, ?descending: bool) : Expr

Parameters

NameTypeDescription
elementExprThe element expression to insert/search.
sideSearchSortedSide (optional)The insertion side (Any, Left, Right). Default is Any.
descendingbool (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.

fsharp
member SetSorted(?descending: bool, ?nullsLast: bool) : Expr

Parameters

NameTypeDescription
descendingbool (optional)Whether the column is sorted in descending order.
nullsLastbool (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.

fsharp
member Shift(n: int64) : Expr
member Shift : unit -> Expr

Parameters

NameTypeDescription
nint64-

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)

fsharp
member Shuffle(?seed: uint64) : Expr

Parameters

NameTypeDescription
seeduint64 (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).

fsharp
member Sign : unit -> Expr

Sin ​

Compute the sine of each element.

fsharp
member Sin : unit -> Expr

Sinh ​

Compute the sinh of each element.

fsharp
member Sinh : unit -> Expr

Skew ​

Compute the sample skewness of a data set.

fsharp
member Skew(?bias: bool) : Expr

Parameters

NameTypeDescription
biasbool (optional)If False, the calculations are corrected for statistical bias.

Slice ​

Slice the expression.

fsharp
member Slice(offset: int64, ?length: uint64) : Expr

Parameters

NameTypeDescription
offsetint64The offset of the slice.
lengthuint64 (optional)The length of the slice.

Sort ​

Sort the expression.

fsharp
member Sort(
    ?descending: bool,
    ?nullsLast: bool,
    ?multithreaded: bool,
    ?maintainOrder: bool,
    ?limit: uint32
) : Expr

Parameters

NameTypeDescription
descendingbool (optional)If true, sort in descending order. Default is false.
nullsLastbool (optional)Whether to place null values last. Default is false.
multithreadedbool (optional)If true, sort in multiple threads. Default is true.
maintainOrderbool (optional)If true, maintain the order of equal elements. Default is false.
limituint32 (optional)Limit the sort output (for optimization purposes).

SortBy ​

Sort this column by the ordering of other columns using uniform sorting options.

fsharp
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
) : 'i

Parameters

NameTypeDescription
byseq<Expr>Column(s) to sort by.
descendingseq<bool> (optional) / bool (optional)Sort in descending order for all columns.
nullsLastseq<bool> (optional) / bool (optional)Place null values last for all columns.
multithreadedbool (optional) / 'g (optional)Sort using multiple threads.
maintainOrderbool (optional) / 'h (optional)Whether the order should be maintained if elements are equal.

Sqrt ​

Calculate the square root of the expression.

fsharp
member Sqrt : unit -> Expr

Std ​

Get the standard deviation value.

fsharp
member Std(?ddof: byte) : Expr

Parameters

NameTypeDescription
ddofbyte (optional)Delta Degrees of Freedom. Default is 1.

Sum ​

Calculate the sum of the values in the group or column.

fsharp
member Sum : unit -> Expr

Tail ​

Get the last n rows.

fsharp
member Tail(?n: int) : Expr

Parameters

NameTypeDescription
nint (optional)Number of rows to return.

Take ​

LINQ-like alias for Gather.

fsharp
member Take(indices: Expr) : Expr

Parameters

NameTypeDescription
indicesExpr-

Tan ​

Compute the tangent of each element.

fsharp
member Tan : unit -> Expr

Tanh ​

Compute the tanh of each element.

fsharp
member Tanh : unit -> Expr

ToHtml ​

Generates a rich HTML view of the expression including its compact string representation and AST tree.

fsharp
member ToHtml : unit -> string
member ToHtml(schema: PolarsSchema) : string

Parameters

NameTypeDescription
schemaPolarsSchemaSchema context to resolve field types.

Returns: An HTML representation formatted for interactive environments.


ToPhysical ​

Cast to physical representation of the logical dtype.

fsharp
member ToPhysical : unit -> Expr

ToSelector ​

Convert an expression to a selector.

fsharp
member ToSelector : unit -> Selector

TopK ​

Get the k largest elements. Result is sorted descending.

fsharp
member TopK(k: int) : Expr

Parameters

NameTypeDescription
kint-

TopKBy ​

Get the top k elements determined by the values in the 'by' columns.

fsharp
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) : Expr

Parameters

NameTypeDescription
kintNumber of elements to return.
byseq<'f> / 'd / 'cColumns to sort by.
reverseseq<bool> (optional)Reverse the sort order for each by column. Default false.

Truediv ​

Perform true division with another expression. Result is always a float.

fsharp
member Truediv(other: Expr) : Expr

Parameters

NameTypeDescription
otherExpr-

Truncate ​

Truncate numeric data toward zero to decimals number of decimal places.

fsharp
member Truncate(?decimals: uint32) : Expr

Parameters

NameTypeDescription
decimalsuint32 (optional)Number of decimal places to truncate to.

Unique ​

Get unique values of this expression.

fsharp
member Unique(?maintainOrder: bool) : Expr

Parameters

NameTypeDescription
maintainOrderbool (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

fsharp
member UniqueCounts : unit -> Expr

UpperBound ​

Calculate the upper bound. Returns a unit Series with the highest value possible for the dtype of this expression.

fsharp
member UpperBound : unit -> Expr

ValueCounts ​

Count the occurrence of unique values.

fsharp
member ValueCounts(
    ?sort: bool,
    ?parallelOn: bool,
    ?name: string,
    ?normalize: bool
) : Expr

Parameters

NameTypeDescription
sortbool (optional)Sort the output by count, in descending order. If set to False (default), the order is non-deterministic.
parallelOnbool (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.
namestring (optional)Give the resulting count column a specific name; if normalize is True this defaults to “proportion”, otherwise defaults to “count”.
normalizebool (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.

fsharp
member Var(?ddof: byte) : Expr

Parameters

NameTypeDescription
ddofbyte (optional)Delta Degrees of Freedom. Default is 1.

Released under the MIT License. Powered by the Polars Rust core & Apache Arrow.