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>, }, Udf { input: Box<Expr>, function: NoEq<Arc<dyn SeriesUdf>>, output_type: Option<DataType>, }, 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: Box<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>),
}

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>
Udf
Show fields

Fields of Udf

input: Box<Expr>function: NoEq<Arc<dyn SeriesUdf>>output_type: Option<DataType>
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: Box<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

impl Expr[src]

pub fn eq(self, other: Expr) -> Expr[src]

Compare Expr with other Expr on equality

pub fn neq(self, other: Expr) -> Expr[src]

Compare Expr with other Expr on non-equality

pub fn lt(self, other: Expr) -> Expr[src]

Check if Expr < Expr

pub fn gt(self, other: Expr) -> Expr[src]

Check if Expr > Expr

pub fn gt_eq(self, other: Expr) -> Expr[src]

Check if Expr >= Expr

pub fn lt_eq(self, other: Expr) -> Expr[src]

Check if Expr <= Expr

pub fn not(self) -> Expr[src]

Negate Expr

pub fn alias(self, name: &str) -> Expr[src]

Rename Column.

pub fn is_null(self) -> Self[src]

Run is_null operation on Expr.

pub fn is_not_null(self) -> Self[src]

Run is_not_null operation on Expr.

pub fn min(self) -> Self[src]

Reduce groups to minimal value.

pub fn max(self) -> Self[src]

Reduce groups to maximum value.

pub fn mean(self) -> Self[src]

Reduce groups to the mean value.

pub fn median(self) -> Self[src]

Reduce groups to the median value.

pub fn sum(self) -> Self[src]

Reduce groups to the sum of all the values.

pub fn n_unique(self) -> Self[src]

Get the number of unique values in the groups.

pub fn first(self) -> Self[src]

Get the first value in the group.

pub fn last(self) -> Self[src]

Get the last value in the group.

pub fn list(self) -> Self[src]

Aggregate the group to a Series

pub fn quantile(self, quantile: f64) -> Self[src]

Compute the quantile per group.

pub fn agg_groups(self) -> Self[src]

Get the group indexes of the group by operation.

pub fn explode(self) -> Self[src]

Explode the utf8/ list column

pub fn slice(self, offset: i64, length: usize) -> Self[src]

Slice the Series.

pub fn head(self, length: Option<usize>) -> Self[src]

Get the first n elements of the Expr result

pub fn tail(self, length: Option<usize>) -> Self[src]

Get the last n elements of the Expr result

pub fn unique(self) -> Self[src]

Get unique values of this expression.

pub fn arg_unique(self) -> Self[src]

Get the first index of unique values of this expression.

pub fn cast(self, data_type: DataType) -> Self[src]

Cast expression to another data type.

pub fn take(self, idx: Expr) -> Self[src]

Take the values by idx.

pub fn sort(self, reverse: bool) -> Self[src]

Sort in increasing order. See the eager implementation.

Can be used in default and aggregation context.

pub fn reverse(self) -> Self[src]

Reverse column

pub fn map<F>(self, function: F, output_type: Option<DataType>) -> Self where
    F: SeriesUdf + 'static, 
[src]

Apply a function/closure once the logical plan get executed. 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.

pub fn is_finite(self) -> Self[src]

Get mask of finite values if dtype is Float

pub fn is_infinite(self) -> Self[src]

Get mask of infinite values if dtype is Float

pub fn is_nan(self) -> Self[src]

Get mask of NaN values if dtype is Float

pub fn is_not_nan(self) -> Self[src]

Get inverse mask of NaN values if dtype is Float

pub fn shift(self, periods: i64) -> Self[src]

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

pub fn shift_and_fill(self, periods: i64, fill_value: Expr) -> Self[src]

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

pub fn cum_sum(self, reverse: bool) -> Self[src]

Get an array with the cumulative sum computed at every element

pub fn cum_min(self, reverse: bool) -> Self[src]

Get an array with the cumulative min computed at every element

pub fn cum_max(self, reverse: bool) -> Self[src]

Get an array with the cumulative max computed at every element

pub fn over(self, partition_by: Expr) -> Self[src]

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     │
╰────────┴────────╯

pub fn fill_none(self, fill_value: Expr) -> Self[src]

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

pub fn count(self) -> Self[src]

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

pub fn std(self) -> Self[src]

Standard deviation of the values of the Series

pub fn var(self) -> Self[src]

Variance of the values of the Series

pub fn is_duplicated(self) -> Self[src]

Get a mask of duplicated values

pub fn is_unique(self) -> Self[src]

Get a mask of unique values

pub fn and(self, expr: Expr) -> Self[src]

and operation

pub fn or(self, expr: Expr) -> Self[src]

or operation

pub fn pow(self, exponent: f64) -> Self[src]

Raise expression to the power exponent

pub fn filter(self, predicate: Expr) -> Self[src]

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

pub fn is_in(self, list_expr: Expr) -> Self[src]

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

pub fn year(self) -> Expr[src]

Get the year of a Date32/Date64

pub fn month(self) -> Expr[src]

Get the month of a Date32/Date64

pub fn day(self) -> Expr[src]

Get the month of a Date32/Date64

pub fn ordinal_day(self) -> Expr[src]

Get the ordinal_day of a Date32/Date64

pub fn hour(self) -> Expr[src]

Get the hour of a Date64/Time64

pub fn minute(self) -> Expr[src]

Get the minute of a Date64/Time64

pub fn second(self) -> Expr[src]

Get the second of a Date64/Time64

pub fn nanosecond(self) -> Expr[src]

Get the nanosecond of a Time64

pub fn sort_by(self, by: Expr, reverse: bool) -> Expr[src]

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

Trait Implementations

impl Add<Expr> for Expr[src]

type Output = Expr

The resulting type after applying the + operator.

impl AsRef<Expr> for AggExpr[src]

impl Clone for Expr[src]

impl Debug for Expr[src]

impl Div<Expr> for Expr[src]

type Output = Expr

The resulting type after applying the / operator.

impl From<AggExpr> for Expr[src]

impl<'a> IntoIterator for &'a Expr[src]

type Item = &'a Expr

The type of the elements being iterated over.

type IntoIter = ExprIter<'a>

Which kind of iterator are we turning this into?

impl Mul<Expr> for Expr[src]

type Output = Expr

The resulting type after applying the * operator.

impl PartialEq<Expr> for Expr[src]

impl Rem<Expr> for Expr[src]

type Output = Expr

The resulting type after applying the % operator.

impl StructuralPartialEq for Expr[src]

impl Sub<Expr> for Expr[src]

type Output = Expr

The resulting type after applying the - operator.

Auto Trait Implementations

impl !RefUnwindSafe for Expr

impl Send for Expr

impl Sync for Expr

impl Unpin for Expr

impl !UnwindSafe for Expr

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, Rhs, Output> NumOps<Rhs, Output> for T where
    T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,