Skip to content

Expr.List (ListOps) ​

Namespace: Polars.FSharp

Instance Methods ​

Agg ​

Run any polars aggregation expression against the list’ elements.

fsharp
member Agg(expr: Expr) : Expr

Parameters

NameTypeDescription
exprExprExpression to run. Note that you can select an element with Pl.Element().

All ​

Evaluate whether all boolean values in a list are true.

fsharp
member All(?ignoreNulls: bool) : Expr

Parameters

NameTypeDescription
ignoreNullsbool (optional)-

Any ​

Evaluate whether any boolean value in a list is true.

fsharp
member Any(?ignoreNulls: bool) : Expr

Parameters

NameTypeDescription
ignoreNullsbool (optional)-

ArgMax ​

Retrieve the index of the maximum value in every sublist.

fsharp
member ArgMax : unit -> Expr

ArgMin ​

Retrieve the index of the minimum value in every sublist.

fsharp
member ArgMin : unit -> Expr

Concat ​

Combine the current expression with other expressions into a List. Result: [parent_val, other_val_1, other_val_2, ...] Equivalent to: pl.concatList([parent, others...])

Overload: Concat a single expression/column.

fsharp
member Concat(others: seq<'b>) : Expr
member Concat(other: 'a) : Expr

Parameters

NameTypeDescription
othersseq<'b>-
other'a-

Contains ​

Check if the list contains the given item.

fsharp
member Contains(item: Expr, ?nullsEqual: bool) : Expr
member Contains(item: int, ?nullsEqual: bool) : Expr
member Contains(item: string, ?nullsEqual: bool) : Expr

Parameters

NameTypeDescription
itemExpr / int / string-
nullsEqualbool (optional)-

Diff ​

Calculate the first discrete difference between shifted items of every sublist.

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

Parameters

NameTypeDescription
nint64 (optional)Number of slots to shift.
nullBehaviorNullBehavior (optional)How to handle null values.

DropNulls ​

Drop all null values in the list. The original order of the remaining elements is preserved.

fsharp
member DropNulls : unit -> Expr

Eval ​

Run any polars expression against the lists’ elements.

fsharp
member Eval(expr: Expr) : Expr

Parameters

NameTypeDescription
exprExprExpression to run. Note that you can select an element with Pl.Element().

Explode ​

Explode a list expression.

This turns a list column into a long column (flattening).

Warning: When used in DataFrame.Select with other columns, it may cause a length mismatch error if the other columns are not broadcasted. Use DataFrame.Explode for safely exploding columns while repeating others.

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

Parameters

NameTypeDescription
emptyAsNullbool (optional)-
keepNullsbool (optional)-

First ​

Get the first element of the list.

fsharp
member First : unit -> Expr

Gather ​

Take sublists by multiple indices.The indices may be defined in a single column, or by sublists in another column of dtype List.

fsharp
member Gather(indices: Expr, ?nullOnOob: bool) : Expr

Parameters

NameTypeDescription
indicesExprIndices to return per sublist
nullOnOobbool (optional)Behavior if an index is out of bounds: True -> set as null False -> raise an error Note that defaulting to raising an error is much cheaper

GatherEvery ​

Take every n-th value start from offset in sublists.

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

Parameters

NameTypeDescription
nExprGather every n-th element.
offsetExpr (optional)Starting Index

Get ​

Get element at index.

fsharp
member Get(index: int, ?nullOnOob: bool) : Expr

Parameters

NameTypeDescription
indexint-
nullOnOobbool (optional)-

Slice the first n values of every sublist.

fsharp
member Head(?n: Expr) : Expr

Parameters

NameTypeDescription
nExpr (optional)Number of values to return for each sublist.

Join ​

Join list elements with separator.

fsharp
member Join(separator: string, ?ignoreNulls: bool) : Expr

Parameters

NameTypeDescription
separatorstring-
ignoreNullsbool (optional)-

Last ​

Get the Last element of the list.

fsharp
member Last : unit -> Expr

Len ​

Return the number of elements in each list.

fsharp
member Len : unit -> Expr

Max ​

Calculate the max of the list elements.

fsharp
member Max : unit -> Expr

Mean ​

Calculate the mean of the list elements.

fsharp
member Mean : unit -> Expr

Median ​

Calculate the median of the list elements.

fsharp
member Median : unit -> Expr

Min ​

Calculate the min of the list elements.

fsharp
member Min : unit -> Expr

NUnique ​

Count the number of unique values in every sub-lists.

fsharp
member NUnique : unit -> Expr

Reverse ​

Reverse the list.

fsharp
member Reverse : unit -> Expr

SampleFrac ​

Sample from this list.

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

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

Parameters

NameTypeDescription
nExpr (optional)Number of items to return.Defaults 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.

SetDifference ​

Compute the SET DIFFERENCE between the elements in this list and the elements of other.

fsharp
member SetDifference(other: Expr) : Expr

Parameters

NameTypeDescription
otherExprRight hand side of the set operation.

SetIntersection ​

Compute the SET INTERSECTION between the elements in this list and the elements of other.

fsharp
member SetIntersection(other: Expr) : Expr

Parameters

NameTypeDescription
otherExprRight hand side of the set operation.

SetSymmetricDifference ​

Compute the SET SYMMETRIC DIFFERENCE between the elements in this list and the elements of other.

fsharp
member SetSymmetricDifference(other: Expr) : Expr

Parameters

NameTypeDescription
otherExprRight hand side of the set operation.

SetUnion ​

Compute the SET UNION between the elements in this list and the elements of other.

fsharp
member SetUnion(other: Expr) : Expr

Parameters

NameTypeDescription
otherExprRight hand side of the set operation.

Shift ​

Shift list values by the given number of indices.

fsharp
member Shift(?n: Expr) : Expr

Parameters

NameTypeDescription
nExpr (optional)Number of indices to shift forward. If a negative value is passed, values are shifted in the opposite direction instead.

Slice ​

Slice every sublist.

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

Parameters

NameTypeDescription
offsetExprStart index. Negative indexing is supported.
lengthExpr (optional)Length of the slice. If null, the slice is taken to the end of the list.

Sort ​

Sort the lists in this column.

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

Parameters

NameTypeDescription
descendingbool (optional)Sort in descending order.
nullsLastbool (optional)Place null values last.
maintainOrderbool (optional)-

Std ​

Get the standard deviation.

fsharp
member Std(?ddof: byte) : Expr

Parameters

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

Sum ​

Calculate the sum of the values in the list (row-wise).

fsharp
member Sum : unit -> Expr

Tail ​

Slice the last n values of every sublist.

fsharp
member Tail(?n: Expr) : Expr

Parameters

NameTypeDescription
nExpr (optional)Number of values to return for each sublist.

ToArray ​

Convert a List column into an Array column with the same inner data type.

fsharp
member ToArray(width: int64) : Expr

Parameters

NameTypeDescription
widthint64Width of the resulting Array column.

ToStruct ​

Convert the list to a struct type with explicitly named fields.

Convert the list to a struct type using a function to generate field names.

Convert the list to a struct type up to a maximum number of fields, using default naming ("field_0", "field_1", ...).

fsharp
member ToStruct(fields: seq<string>) : Expr
member ToStruct(nameGenerator: (int -> string), fieldCount: int) : Expr
member ToStruct(upperBound: int) : Expr

Parameters

NameTypeDescription
fieldsseq<string>A sequence of names for the struct fields.
nameGenerator(int -> string)A function that takes a field index and returns the field name.
fieldCountintThe number of struct fields to create.
upperBoundintThe maximum number of struct fields to create. Used for compile-time schema inference.

Returns: A new Expr representing the struct conversion.


Unique ​

Get the unique/distinct values in the list.

fsharp
member Unique(?maintainOrder: bool) : Expr

Parameters

NameTypeDescription
maintainOrderbool (optional)Maintain order of data. This requires more work.

Var ​

Get the variance.

fsharp
member Var(?ddof: byte) : Expr

Parameters

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

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