pub enum Expr {
Show 31 variants Alias(Box<Expr, Global>, Arc<str>), Column(Arc<str>), Columns(Vec<String, Global>), DtypeColumn(Vec<DataType, Global>), Literal(LiteralValue), BinaryExpr { left: Box<Expr, Global>, op: Operator, right: Box<Expr, Global>, }, Not(Box<Expr, Global>), IsNotNull(Box<Expr, Global>), IsNull(Box<Expr, Global>), Cast { expr: Box<Expr, Global>, data_type: DataType, strict: bool, }, Sort { expr: Box<Expr, Global>, options: SortOptions, }, Take { expr: Box<Expr, Global>, idx: Box<Expr, Global>, }, SortBy { expr: Box<Expr, Global>, by: Vec<Expr, Global>, reverse: Vec<bool, Global>, }, Agg(AggExpr), Ternary { predicate: Box<Expr, Global>, truthy: Box<Expr, Global>, falsy: Box<Expr, Global>, }, AnonymousFunction { input: Vec<Expr, Global>, function: SpecialEq<Arc<dyn SeriesUdf + 'static>>, output_type: SpecialEq<Arc<dyn FunctionOutputField + 'static>>, options: FunctionOptions, }, Function { input: Vec<Expr, Global>, function: FunctionExpr, options: FunctionOptions, }, Shift { input: Box<Expr, Global>, periods: i64, }, Reverse(Box<Expr, Global>), Duplicated(Box<Expr, Global>), IsUnique(Box<Expr, Global>), Explode(Box<Expr, Global>), Filter { input: Box<Expr, Global>, by: Box<Expr, Global>, }, Window { function: Box<Expr, Global>, partition_by: Vec<Expr, Global>, order_by: Option<Box<Expr, Global>>, options: WindowOptions, }, Wildcard, Slice { input: Box<Expr, Global>, offset: Box<Expr, Global>, length: Box<Expr, Global>, }, Exclude(Box<Expr, Global>, Vec<Excluded, Global>), KeepName(Box<Expr, Global>), RenameAlias { function: SpecialEq<Arc<dyn RenameAliasFn + 'static>>, expr: Box<Expr, Global>, }, Count, Nth(i64),
}
Expand description

Queries consists of multiple ex pressions.

Variants

Alias(Box<Expr, Global>, Arc<str>)

Column(Arc<str>)

Columns(Vec<String, Global>)

DtypeColumn(Vec<DataType, Global>)

Literal(LiteralValue)

BinaryExpr

Fields

left: Box<Expr, Global>
right: Box<Expr, Global>

Not(Box<Expr, Global>)

IsNotNull(Box<Expr, Global>)

IsNull(Box<Expr, Global>)

Cast

Fields

expr: Box<Expr, Global>
data_type: DataType
strict: bool

Sort

Fields

expr: Box<Expr, Global>
options: SortOptions

Take

Fields

expr: Box<Expr, Global>
idx: Box<Expr, Global>

SortBy

Fields

expr: Box<Expr, Global>
by: Vec<Expr, Global>
reverse: Vec<bool, Global>

Agg(AggExpr)

Ternary

Fields

predicate: Box<Expr, Global>
truthy: Box<Expr, Global>
falsy: Box<Expr, Global>

A ternary operation if true then “foo” else “bar”

AnonymousFunction

Fields

input: Vec<Expr, Global>

function arguments

function: SpecialEq<Arc<dyn SeriesUdf + 'static>>

function to apply

output_type: SpecialEq<Arc<dyn FunctionOutputField + 'static>>

output dtype of the function

options: FunctionOptions

Function

Fields

input: Vec<Expr, Global>

function arguments

function: FunctionExpr

function to apply

options: FunctionOptions

Shift

Fields

input: Box<Expr, Global>
periods: i64

Reverse(Box<Expr, Global>)

Duplicated(Box<Expr, Global>)

IsUnique(Box<Expr, Global>)

Explode(Box<Expr, Global>)

Filter

Fields

input: Box<Expr, Global>
by: Box<Expr, Global>

Window

Fields

function: Box<Expr, Global>

Also has the input. i.e. avg(“foo”)

partition_by: Vec<Expr, Global>
order_by: Option<Box<Expr, Global>>
options: WindowOptions

See postgres window functions

Wildcard

Slice

Fields

input: Box<Expr, Global>
offset: Box<Expr, Global>

length is not yet known so we accept negative offsets

length: Box<Expr, Global>

Exclude(Box<Expr, Global>, Vec<Excluded, Global>)

Can be used in a select statement to exclude a column from selection

KeepName(Box<Expr, Global>)

Set root name as Alias

RenameAlias

Fields

function: SpecialEq<Arc<dyn RenameAliasFn + 'static>>
expr: Box<Expr, Global>

Count

Special case that does not need columns

Nth(i64)

Take the nth column in the DataFrame

Implementations

Get a dot language representation of the Expression.

Run an expression over a sliding window that increases 1 slot every iteration.

Warning

this can be really slow as it can have O(n^2) complexity. Don’t use this for operations that visit all elements.

Compare Expr with other Expr on equality

Compare Expr with other Expr on non-equality

Check if Expr < Expr

Check if Expr > Expr

Check if Expr >= Expr

Check if Expr <= Expr

Negate Expr

Rename Column.

Run is_null operation on Expr.

Run is_not_null operation on Expr.

Drop null values

Drop NaN values

Reduce groups to minimal value.

Reduce groups to maximum value.

Reduce groups to the mean value.

Reduce groups to the median value.

Reduce groups to the sum of all the values.

Get the number of unique values in the groups.

Get the first value in the group.

Get the last value in the group.

Aggregate the group to a Series

Compute the quantile per group.

Get the group indexes of the group by operation.

Alias for explode

Explode the utf8/ list column

Slice the Series. offset may be negative.

Append expressions. This is done by adding the chunks of other to this Series.

Get the first n elements of the Expr result

Get the last n elements of the Expr result

Get unique values of this expression.

Get unique values of this expression, while maintaining order. This requires more work than Expr::unique.

Get the first index of unique values of this expression.

Get the index value that has the minimum value

Get the index value that has the maximum value

Get the index values that would sort this expression.

Cast expression to another data type. Throws an error if conversion had overflows

Cast expression to another data type.

Take the values by idx.

Sort in increasing order. See the eager implementation.

Sort with given options.

Reverse column

Apply a function/closure once the logical plan get executed.

This function is very similar to Expr::apply, but differs in how it handles aggregations.

  • map should be used for operations that are independent of groups, e.g. multiply * 2, or raise to the power
  • apply should be used for operations that work on a group of data. e.g. sum, count, etc.

It is the responsibility of the caller that the schema is correct by giving the correct output_type. If None given the output type of the input expr is used.

Apply a function/closure once the logical plan get executed with many arguments

See the Expr::map function for the differences between map and apply.

Apply a function/closure once the logical plan get executed.

This function is very similar to apply, but differs in how it handles aggregations.

  • map should be used for operations that are independent of groups, e.g. multiply * 2, or raise to the power
  • apply should be used for operations that work on a group of data. e.g. sum, count, etc.
  • map_list should be used when the function expects a list aggregated series.

A function that cannot be expressed with map or apply and requires extra settings.

Apply a function/closure over the groups. This should only be used in a groupby aggregation.

It is the responsibility of the caller that the schema is correct by giving the correct output_type. If None given the output type of the input expr is used.

This difference with map is that apply will create a separate Series per group.

  • map should be used for operations that are independent of groups, e.g. multiply * 2, or raise to the power
  • apply should be used for operations that work on a group of data. e.g. sum, count, etc.

Apply a function/closure over the groups with many arguments. This should only be used in a groupby aggregation.

See the Expr::apply function for the differences between map and apply.

Get mask of finite values if dtype is Float

Get mask of infinite values if dtype is Float

Get mask of NaN values if dtype is Float

Get inverse mask of NaN values if dtype is Float

Shift the values in the array by some period. See the eager implementation.

Shift the values in the array by some period and fill the resulting empty values.

Get an array with the cumulative sum computed at every element

Get an array with the cumulative product computed at every element

Get an array with the cumulative min computed at every element

Get an array with the cumulative max computed at every element

Get the product aggregation of an expression

Fill missing value with next non-null.

Fill missing value with previous non-null.

Round underlying floating point array to given decimal numbers.

Floor underlying floating point array to the lowest integers smaller or equal to the float value.

Ceil underlying floating point array to the highest integers smaller or equal to the float value.

Clip underlying values to a set boundary.

Convert all values to their absolute/positive value.

Apply window function over a subgroup. This is similar to a groupby + aggregation + self join. Or similar to window functions in Postgres.

Example
#[macro_use] extern crate polars_core;
use polars_core::prelude::*;
use polars_lazy::prelude::*;

fn example() -> Result<()> {
    let df = df! {
            "groups" => &[1, 1, 2, 2, 1, 2, 3, 3, 1],
            "values" => &[1, 2, 3, 4, 5, 6, 7, 8, 8]
        }?;

    let out = df
     .lazy()
     .select(&[
         col("groups"),
         sum("values").over([col("groups")]),
     ])
     .collect()?;
    dbg!(&out);
    Ok(())
}

Outputs:

╭────────┬────────╮
│ groups ┆ values │
│ ---    ┆ ---    │
│ i32    ┆ i32    │
╞════════╪════════╡
│ 1      ┆ 16     │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 1      ┆ 16     │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 2      ┆ 13     │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 2      ┆ 13     │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ ...    ┆ ...    │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 1      ┆ 16     │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 2      ┆ 13     │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 3      ┆ 15     │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 3      ┆ 15     │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 1      ┆ 16     │
╰────────┴────────╯

Replace the null values by a value.

Replace the floating point NaN values by a value.

Count the values of the Series or Get counts of the group by operation.

Standard deviation of the values of the Series

Variance of the values of the Series

Get a mask of duplicated values

Get a mask of unique values

and operation

or operation

Raise expression to the power exponent

Filter a single column Should be used in aggregation context. If you want to filter on a DataFrame level, use LazyFrame::filter

Check if the values of the left expression are in the lists of the right expr.

Sort this column by the ordering of another column. Can also be used in a groupby context to sort the groups.

Repeat the column n times, where n is determined by the values in by. This yields an Expr of dtype List

Get a mask of the first unique value.

Compute the mode(s) of this column. This is the most occurring value.

Keep the original root name

use polars_core::prelude::*;
use polars_lazy::prelude::*;

fn example(df: LazyFrame) -> LazyFrame {
    df.select([
// even thought the alias yields a different column name,
// `keep_name` will make sure that the original column name is used
        col("*").alias("foo").keep_name()
])
}

Define an alias by mapping a function over the original root column name.

Add a suffix to the root column name.

Add a prefix to the root column name.

Exclude a column from a wildcard/regex selection.

You may also use regexes in the exclude as long as they start with ^ and end with $/

Example
use polars_core::prelude::*;
use polars_lazy::prelude::*;

// Select all columns except foo.
fn example(df: DataFrame) -> LazyFrame {
      df.lazy()
        .select(&[
                col("*").exclude(&["foo"])
                ])
}

Apply a rolling min See: [ChunkedArray::rolling_min]

Apply a rolling max See: [ChunkedArray::rolling_max]

Apply a rolling mean See: [ChunkedArray::rolling_mean]

Apply a rolling sum See: [ChunkedArray::rolling_sum]

Apply a rolling median See: [ChunkedArray::rolling_median]

Apply a rolling quantile See: [ChunkedArray::rolling_quantile]

Apply a rolling variance

Apply a rolling std-dev

Apply a custom function over a rolling/ moving window of the array. This has quite some dynamic dispatch, so prefer rolling_min, max, mean, sum over this.

Apply a custom function over a rolling/ moving window of the array. Prefer this over rolling_apply in case of floating point numbers as this is faster. This has quite some dynamic dispatch, so prefer rolling_min, max, mean, sum over this.

Get maximal value that could be hold by this dtype.

Get minimal value that could be hold by this dtype.

Cumulatively count values from 0 to len.

Check if any boolean value is true

Check if all boolean values are true

This is useful if an apply function needs a floating point type. Because this cast is done on a map level, it will be faster.

Count all unique values and create a struct mapping value to count Note that it is better to turn multithreaded off in the aggregation context

Get the null count of the column/group

Set this Series as sorted so that downstream code can use fast paths for sorted arrays.

Warning

This can lead to incorrect results if this Series is not sorted!! Use with care!

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

Converts this type into a shared reference of the (usually inferred) input type.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The resulting type after applying the % operator.

Performs the % operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.