Enum polars_lazy::dsl::Expr[][src]

pub enum Expr {
Show variants Alias(Box<Expr>, Arc<String>), Column(Arc<String>), Literal(LiteralValue), BinaryExpr { left: Box<Expr>, op: Operator, right: Box<Expr>, }, Not(Box<Expr>), IsNotNull(Box<Expr>), IsNull(Box<Expr>), Cast { expr: Box<Expr>, data_type: DataType, }, Sort { expr: Box<Expr>, reverse: bool, }, Take { expr: Box<Expr>, idx: Box<Expr>, }, SortBy { expr: Box<Expr>, by: Box<Expr>, reverse: bool, }, Agg(AggExpr), Ternary { predicate: Box<Expr>, truthy: Box<Expr>, falsy: Box<Expr>, }, Function { input: Vec<Expr>, function: NoEq<Arc<dyn SeriesUdf>>, output_type: Option<DataType>, collect_groups: bool, }, Shift { input: Box<Expr>, periods: i64, }, Reverse(Box<Expr>), Duplicated(Box<Expr>), IsUnique(Box<Expr>), Explode(Box<Expr>), Filter { input: Box<Expr>, by: Box<Expr>, }, Window { function: Box<Expr>, partition_by: Vec<Expr>, order_by: Option<Box<Expr>>, }, Wildcard, Slice { input: Box<Expr>, offset: i64, length: usize, }, BinaryFunction { input_a: Box<Expr>, input_b: Box<Expr>, function: NoEq<Arc<dyn SeriesBinaryUdf>>, output_field: NoEq<Arc<dyn BinaryUdfOutputField>>, }, Except(Box<Expr>),
}
Expand description

Queries consists of multiple expressions.

Variants

Alias(Box<Expr>, Arc<String>)
Column(Arc<String>)
Literal(LiteralValue)
BinaryExpr
Show fields

Fields of BinaryExpr

left: Box<Expr>op: Operatorright: Box<Expr>
Not(Box<Expr>)
IsNotNull(Box<Expr>)
IsNull(Box<Expr>)
Cast
Show fields

Fields of Cast

expr: Box<Expr>data_type: DataType
Sort
Show fields

Fields of Sort

expr: Box<Expr>reverse: bool
Take
Show fields

Fields of Take

expr: Box<Expr>idx: Box<Expr>
SortBy
Show fields

Fields of SortBy

expr: Box<Expr>by: Box<Expr>reverse: bool
Agg(AggExpr)
Ternary

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

Show fields

Fields of Ternary

predicate: Box<Expr>truthy: Box<Expr>falsy: Box<Expr>
Function
Show fields

Fields of Function

input: Vec<Expr>

function arguments

function: NoEq<Arc<dyn SeriesUdf>>

function to apply

output_type: Option<DataType>

output dtype of the function

collect_groups: bool

if the groups should aggregated to list before execution of the function.

Shift
Show fields

Fields of Shift

input: Box<Expr>periods: i64
Reverse(Box<Expr>)
Duplicated(Box<Expr>)
IsUnique(Box<Expr>)
Explode(Box<Expr>)
Filter
Show fields

Fields of Filter

input: Box<Expr>by: Box<Expr>
Window

See postgres window functions

Show fields

Fields of Window

function: Box<Expr>

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

partition_by: Vec<Expr>order_by: Option<Box<Expr>>
Wildcard
Slice
Show fields

Fields of Slice

input: Box<Expr>offset: i64

length is not yet known so we accept negative offsets

length: usize
BinaryFunction
Show fields

Fields of BinaryFunction

input_a: Box<Expr>input_b: Box<Expr>function: NoEq<Arc<dyn SeriesBinaryUdf>>output_field: NoEq<Arc<dyn BinaryUdfOutputField>>

Delays output type evaluation until input schema is known.

Except(Box<Expr>)

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

Implementations

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.

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.

Explode the utf8/ list column

Slice the 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 the first index of unique values of this expression.

Get the index values that would sort this expression.

Cast expression to another data type.

Take the values by idx.

Sort in increasing order. See the eager implementation.

Can be used in default and aggregation context.

Reverse column

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.

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

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 valus 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 min computed at every element

Get an array with the cumulative max computed at every element

This is supported on crate feature round_series only.

Round underlying floating point array to given decimal numbers.

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(vec![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     │
╰────────┴────────╯

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

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

This is supported on crate feature is_in only.

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

Get the year of a Date32/Date64

Get the month of a Date32/Date64

Get the month of a Date32/Date64

Get the ordinal_day of a Date32/Date64

Get the hour of a Date64/Time64

Get the minute of a Date64/Time64

Get the second of a Date64/Time64

Get the nanosecond of a Time64

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

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the conversion.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

Performs the conversion.

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

Performs the conversion.

Performs the conversion.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. 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.