Enum polars::prelude::Expr[][src]

pub enum Expr {
    Alias(Box<Expr, Global>, Arc<String>),
    Column(Arc<String>),
    Literal(ScalarValue),
    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,
    },
    Sort {
        expr: Box<Expr, Global>,
        reverse: bool,
    },
    Agg(AggExpr),
    Ternary {
        predicate: Box<Expr, Global>,
        truthy: Box<Expr, Global>,
        falsy: Box<Expr, Global>,
    },
    Udf {
        input: Box<Expr, Global>,
        function: Arc<dyn SeriesUdf + 'static>,
        output_type: Option<DataType>,
    },
    Shift {
        input: Box<Expr, Global>,
        periods: i32,
    },
    Reverse(Box<Expr, Global>),
    Duplicated(Box<Expr, Global>),
    Unique(Box<Expr, Global>),
    Explode(Box<Expr, Global>),
    Window {
        function: Box<Expr, Global>,
        partition_by: Box<Expr, Global>,
        order_by: Option<Box<Expr, Global>>,
    },
    Wildcard,
    Slice {
        input: Box<Expr, Global>,
        offset: isize,
        length: usize,
    },
    BinaryFunction {
        input_a: Box<Expr, Global>,
        input_b: Box<Expr, Global>,
        function: Arc<dyn SeriesBinaryUdf + 'static>,
        output_field: Arc<dyn BinaryUdfOutputField + 'static>,
    },
}

Queries consists of multiple expressions.

Variants

Alias(Box<Expr, Global>, Arc<String>)
Column(Arc<String>)
Literal(ScalarValue)
BinaryExpr

Fields of BinaryExpr

left: Box<Expr, Global>op: Operatorright: Box<Expr, Global>
Not(Box<Expr, Global>)
IsNotNull(Box<Expr, Global>)
IsNull(Box<Expr, Global>)
Cast

Fields of Cast

expr: Box<Expr, Global>data_type: DataType
Sort

Fields of Sort

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

Fields of Ternary

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

Fields of Udf

input: Box<Expr, Global>function: Arc<dyn SeriesUdf + 'static>output_type: Option<DataType>
Shift

Fields of Shift

input: Box<Expr, Global>periods: i32
Reverse(Box<Expr, Global>)
Duplicated(Box<Expr, Global>)
Unique(Box<Expr, Global>)
Explode(Box<Expr, Global>)
Window

See postgres window functions

Fields of Window

function: Box<Expr, Global>

Also has the input. i.e. avg("foo")

partition_by: Box<Expr, Global>order_by: Option<Box<Expr, Global>>
Wildcard
Slice

Fields of Slice

input: Box<Expr, Global>offset: isize

length is not yet known so we accept negative offsets

length: usize
BinaryFunction

Fields of BinaryFunction

input_a: Box<Expr, Global>input_b: Box<Expr, Global>function: Arc<dyn SeriesBinaryUdf + 'static>output_field: Arc<dyn BinaryUdfOutputField + 'static>

Delays output type evaluation until input schema is known.

Implementations

impl Expr[src]

pub fn get_type(
    &self,
    schema: &Schema,
    context: Context
) -> Result<DataType, PolarsError>
[src]

Get DataType result of the expression. The schema is the input data.

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) -> Expr[src]

Run is_null operation on Expr.

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

Run is_not_null operation on Expr.

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

Reduce groups to minimal value.

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

Reduce groups to maximum value.

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

Reduce groups to the mean value.

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

Reduce groups to the median value.

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

Reduce groups to the sum of all the values.

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

Get the number of unique values in the groups.

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

Get the first value in the group.

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

Get the last value in the group.

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

Aggregate the group to a Series

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

Compute the quantile per group.

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

Get the group indexes of the group by operation.

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

Explode the utf8/ list column

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

Slice the Series.

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

Get the first n elements of the Expr result

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

Get the last n elements of the Expr result

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

Cast expression to another data type.

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

Sort expression. See the eager implementation.

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

Reverse column

pub fn map<F>(self, function: F, output_type: Option<DataType>) -> Expr 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) -> Expr[src]

Get mask of finite values if dtype is Float

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

Get mask of infinite values if dtype is Float

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

Get mask of NaN values if dtype is Float

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

Get inverse mask of NaN values if dtype is Float

pub fn shift(self, periods: i32) -> Expr[src]

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

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

Get an array with the cumulative sum computed at every element

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

Get an array with the cumulative min computed at every element

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

Get an array with the cumulative max computed at every element

pub fn over(self, partition_by: Expr) -> Expr[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) -> Expr[src]

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

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

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

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

Standard deviation of the values of the Series

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

Variance of the values of the Series

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

Get a mask of duplicated values

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

Get a mask of unique values

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

and operation

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

or operation

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

Raise expression to the power exponent

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

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 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 Sub<Expr> for Expr[src]

type Output = Expr

The resulting type after applying the - operator.

Auto Trait Implementations

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, U> Cast<U> for T where
    U: FromCast<T>, 

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

impl<T> FromCast<T> for T

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