polars_lazy::dsl

Enum Expr

Source
pub enum Expr {
Show 28 variants Alias(Arc<Expr>, PlSmallStr), Column(PlSmallStr), Columns(Arc<[PlSmallStr]>), DtypeColumn(Vec<DataType>), IndexColumn(Arc<[i64]>), Literal(LiteralValue), BinaryExpr { left: Arc<Expr>, op: Operator, right: Arc<Expr>, }, Cast { expr: Arc<Expr>, dtype: DataType, options: CastOptions, }, Sort { expr: Arc<Expr>, options: SortOptions, }, Gather { expr: Arc<Expr>, idx: Arc<Expr>, returns_scalar: bool, }, SortBy { expr: Arc<Expr>, by: Vec<Expr>, sort_options: SortMultipleOptions, }, Agg(AggExpr), Ternary { predicate: Arc<Expr>, truthy: Arc<Expr>, falsy: Arc<Expr>, }, Function { input: Vec<Expr>, function: FunctionExpr, options: FunctionOptions, }, Explode(Arc<Expr>), Filter { input: Arc<Expr>, by: Arc<Expr>, }, Window { function: Arc<Expr>, partition_by: Vec<Expr>, order_by: Option<(Arc<Expr>, SortOptions)>, options: WindowType, }, Wildcard, Slice { input: Arc<Expr>, offset: Arc<Expr>, length: Arc<Expr>, }, Exclude(Arc<Expr>, Vec<Excluded>), KeepName(Arc<Expr>), Len, Nth(i64), RenameAlias { function: SpecialEq<Arc<dyn RenameAliasFn>>, expr: Arc<Expr>, }, Field(Arc<[PlSmallStr]>), AnonymousFunction { input: Vec<Expr>, function: LazySerde<SpecialEq<Arc<dyn ColumnsUdf>>>, output_type: SpecialEq<Arc<dyn FunctionOutputField>>, options: FunctionOptions, }, SubPlan(SpecialEq<Arc<DslPlan>>, Vec<String>), Selector(Selector),
}
Expand description

Expressions that can be used in various contexts.

Queries consist of multiple expressions. When using the polars lazy API, don’t construct an Expr directly; instead, create one using the functions in the polars_lazy::dsl module. See that module’s docs for more info.

Variants§

§

Alias(Arc<Expr>, PlSmallStr)

§

Column(PlSmallStr)

§

Columns(Arc<[PlSmallStr]>)

§

DtypeColumn(Vec<DataType>)

§

IndexColumn(Arc<[i64]>)

§

Literal(LiteralValue)

§

BinaryExpr

Fields

§left: Arc<Expr>
§right: Arc<Expr>
§

Cast

Fields

§expr: Arc<Expr>
§dtype: DataType
§options: CastOptions
§

Sort

Fields

§expr: Arc<Expr>
§options: SortOptions
§

Gather

Fields

§expr: Arc<Expr>
§idx: Arc<Expr>
§returns_scalar: bool
§

SortBy

Fields

§expr: Arc<Expr>
§by: Vec<Expr>
§sort_options: SortMultipleOptions
§

Agg(AggExpr)

§

Ternary

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

Fields

§predicate: Arc<Expr>
§truthy: Arc<Expr>
§falsy: Arc<Expr>
§

Function

Fields

§input: Vec<Expr>

function arguments

§function: FunctionExpr

function to apply

§

Explode(Arc<Expr>)

§

Filter

Fields

§input: Arc<Expr>
§by: Arc<Expr>
§

Window

Polars flavored window functions.

Fields

§function: Arc<Expr>

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

§partition_by: Vec<Expr>
§order_by: Option<(Arc<Expr>, SortOptions)>
§options: WindowType
§

Wildcard

§

Slice

Fields

§input: Arc<Expr>
§offset: Arc<Expr>

length is not yet known so we accept negative offsets

§length: Arc<Expr>
§

Exclude(Arc<Expr>, Vec<Excluded>)

Can be used in a select statement to exclude a column from selection TODO: See if we can replace Vec<Excluded> with Arc<Excluded>

§

KeepName(Arc<Expr>)

Set root name as Alias

§

Len

§

Nth(i64)

Take the nth column in the DataFrame

§

RenameAlias

Fields

§function: SpecialEq<Arc<dyn RenameAliasFn>>
§expr: Arc<Expr>
§

Field(Arc<[PlSmallStr]>)

Available on crate feature dtype-struct only.
§

AnonymousFunction

Fields

§input: Vec<Expr>

function arguments

§function: LazySerde<SpecialEq<Arc<dyn ColumnsUdf>>>

function to apply

§output_type: SpecialEq<Arc<dyn FunctionOutputField>>

output dtype of the function

§

SubPlan(SpecialEq<Arc<DslPlan>>, Vec<String>)

§

Selector(Selector)

Expressions in this node should only be expanding e.g. Expr::Columns Expr::Dtypes Expr::Wildcard Expr::Exclude

Implementations§

Source§

impl Expr

Source

pub fn floor_div(self, rhs: Expr) -> Expr

Floor divide self by rhs.

Source

pub fn pow<E>(self, exponent: E) -> Expr
where E: Into<Expr>,

Raise expression to the power exponent

Source

pub fn sqrt(self) -> Expr

Compute the square root of the given expression

Source

pub fn cbrt(self) -> Expr

Compute the cube root of the given expression

Source

pub fn cos(self) -> Expr

Available on crate feature trigonometry only.

Compute the cosine of the given expression

Source

pub fn cot(self) -> Expr

Available on crate feature trigonometry only.

Compute the cotangent of the given expression

Source

pub fn sin(self) -> Expr

Available on crate feature trigonometry only.

Compute the sine of the given expression

Source

pub fn tan(self) -> Expr

Available on crate feature trigonometry only.

Compute the tangent of the given expression

Source

pub fn arccos(self) -> Expr

Available on crate feature trigonometry only.

Compute the inverse cosine of the given expression

Source

pub fn arcsin(self) -> Expr

Available on crate feature trigonometry only.

Compute the inverse sine of the given expression

Source

pub fn arctan(self) -> Expr

Available on crate feature trigonometry only.

Compute the inverse tangent of the given expression

Source

pub fn arctan2(self, x: Expr) -> Expr

Available on crate feature trigonometry only.

Compute the inverse tangent of the given expression, with the angle expressed as the argument of a complex number

Source

pub fn cosh(self) -> Expr

Available on crate feature trigonometry only.

Compute the hyperbolic cosine of the given expression

Source

pub fn sinh(self) -> Expr

Available on crate feature trigonometry only.

Compute the hyperbolic sine of the given expression

Source

pub fn tanh(self) -> Expr

Available on crate feature trigonometry only.

Compute the hyperbolic tangent of the given expression

Source

pub fn arccosh(self) -> Expr

Available on crate feature trigonometry only.

Compute the inverse hyperbolic cosine of the given expression

Source

pub fn arcsinh(self) -> Expr

Available on crate feature trigonometry only.

Compute the inverse hyperbolic sine of the given expression

Source

pub fn arctanh(self) -> Expr

Available on crate feature trigonometry only.

Compute the inverse hyperbolic tangent of the given expression

Source

pub fn degrees(self) -> Expr

Available on crate feature trigonometry only.

Convert from radians to degrees

Source

pub fn radians(self) -> Expr

Available on crate feature trigonometry only.

Convert from degrees to radians

Source

pub fn sign(self) -> Expr

Available on crate feature sign only.

Compute the sign of the given expression

Source§

impl Expr

Source

pub fn to_field( &self, schema: &Schema<DataType>, ctxt: Context, ) -> Result<Field, PolarsError>

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

Source§

impl Expr

Source

pub fn shuffle(self, seed: Option<u64>) -> Expr

Source

pub fn sample_n( self, n: Expr, with_replacement: bool, shuffle: bool, seed: Option<u64>, ) -> Expr

Source

pub fn sample_frac( self, frac: Expr, with_replacement: bool, shuffle: bool, seed: Option<u64>, ) -> Expr

Source§

impl Expr

Source

pub fn std(self, ddof: u8) -> Expr

Standard deviation of the values of the Series.

Source

pub fn var(self, ddof: u8) -> Expr

Variance of the values of the Series.

Source

pub fn min(self) -> Expr

Reduce groups to minimal value.

Source

pub fn max(self) -> Expr

Reduce groups to maximum value.

Source

pub fn nan_min(self) -> Expr

Reduce groups to minimal value.

Source

pub fn nan_max(self) -> Expr

Reduce groups to maximum value.

Source

pub fn mean(self) -> Expr

Reduce groups to the mean value.

Source

pub fn median(self) -> Expr

Reduce groups to the median value.

Source

pub fn sum(self) -> Expr

Reduce groups to the sum of all the values.

Source

pub fn hist( self, bins: Option<Expr>, bin_count: Option<usize>, include_category: bool, include_breakpoint: bool, ) -> Expr

Available on crate feature hist only.

Compute the histogram of a dataset.

Source§

impl Expr

Source

pub fn eq<E>(self, other: E) -> Expr
where E: Into<Expr>,

Compare Expr with other Expr on equality.

Source

pub fn eq_missing<E>(self, other: E) -> Expr
where E: Into<Expr>,

Compare Expr with other Expr on equality where None == None.

Source

pub fn neq<E>(self, other: E) -> Expr
where E: Into<Expr>,

Compare Expr with other Expr on non-equality.

Source

pub fn neq_missing<E>(self, other: E) -> Expr
where E: Into<Expr>,

Compare Expr with other Expr on non-equality where None == None.

Source

pub fn lt<E>(self, other: E) -> Expr
where E: Into<Expr>,

Check if Expr < Expr.

Source

pub fn gt<E>(self, other: E) -> Expr
where E: Into<Expr>,

Check if Expr > Expr.

Source

pub fn gt_eq<E>(self, other: E) -> Expr
where E: Into<Expr>,

Check if Expr >= Expr.

Source

pub fn lt_eq<E>(self, other: E) -> Expr
where E: Into<Expr>,

Check if Expr <= Expr.

Source

pub fn not(self) -> Expr

Negate Expr.

Source

pub fn alias<S>(self, name: S) -> Expr
where S: Into<PlSmallStr>,

Rename Column.

Source

pub fn is_null(self) -> Expr

Run is_null operation on Expr.

Source

pub fn is_not_null(self) -> Expr

Run is_not_null operation on Expr.

Source

pub fn drop_nulls(self) -> Expr

Drop null values.

Source

pub fn drop_nans(self) -> Expr

Drop NaN values.

Source

pub fn n_unique(self) -> Expr

Get the number of unique values in the groups.

Source

pub fn first(self) -> Expr

Get the first value in the group.

Source

pub fn last(self) -> Expr

Get the last value in the group.

Source

pub fn implode(self) -> Expr

GroupBy the group to a Series.

Source

pub fn quantile(self, quantile: Expr, method: QuantileMethod) -> Expr

Compute the quantile per group.

Source

pub fn agg_groups(self) -> Expr

Get the group indexes of the group by operation.

Source

pub fn flatten(self) -> Expr

Alias for explode.

Source

pub fn explode(self) -> Expr

Explode the String/List column.

Source

pub fn slice<E, F>(self, offset: E, length: F) -> Expr
where E: Into<Expr>, F: Into<Expr>,

Slice the Series. offset may be negative.

Source

pub fn append<E>(self, other: E, upcast: bool) -> Expr
where E: Into<Expr>,

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

Source

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

Get the first n elements of the Expr result.

Source

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

Get the last n elements of the Expr result.

Source

pub fn unique(self) -> Expr

Get unique values of this expression.

Source

pub fn unique_stable(self) -> Expr

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

Source

pub fn arg_unique(self) -> Expr

Get the first index of unique values of this expression.

Source

pub fn arg_min(self) -> Expr

Get the index value that has the minimum value.

Source

pub fn arg_max(self) -> Expr

Get the index value that has the maximum value.

Source

pub fn arg_sort(self, sort_options: SortOptions) -> Expr

Get the index values that would sort this expression.

Source

pub fn search_sorted<E>(self, element: E, side: SearchSortedSide) -> Expr
where E: Into<Expr>,

Available on crate feature search_sorted only.

Find indices where elements should be inserted to maintain order.

Source

pub fn strict_cast(self, dtype: DataType) -> Expr

Cast expression to another data type. Throws an error if conversion had overflows. Returns an Error if cast is invalid on rows after predicates are pushed down.

Source

pub fn cast(self, dtype: DataType) -> Expr

Cast expression to another data type.

Source

pub fn cast_with_options( self, dtype: DataType, cast_options: CastOptions, ) -> Expr

Cast expression to another data type.

Source

pub fn gather<E>(self, idx: E) -> Expr
where E: Into<Expr>,

Take the values by idx.

Source

pub fn get<E>(self, idx: E) -> Expr
where E: Into<Expr>,

Take the values by a single index.

Source

pub fn sort(self, options: SortOptions) -> Expr

Sort with given options.

§Example
let lf = df! {
   "a" => [Some(5), Some(4), Some(3), Some(2), None]
}?
.lazy();

let sorted = lf
    .select(
        vec![col("a").sort(SortOptions::default())],
    )
    .collect()?;

assert_eq!(
    sorted,
    df! {
        "a" => [None, Some(2), Some(3), Some(4), Some(5)]
    }?
);

See SortOptions for more options.

Source

pub fn top_k(self, k: Expr) -> Expr

Available on crate feature top_k only.

Returns the k largest elements.

This has time complexity O(n + k log(n)).

Source

pub fn top_k_by<K, E, IE>(self, k: K, by: E, descending: Vec<bool>) -> Expr
where K: Into<Expr>, E: AsRef<[IE]>, IE: Into<Expr> + Clone,

Available on crate feature top_k only.

Returns the k largest rows by given column.

For single column, use Expr::top_k.

Source

pub fn bottom_k(self, k: Expr) -> Expr

Available on crate feature top_k only.

Returns the k smallest elements.

This has time complexity O(n + k log(n)).

Source

pub fn bottom_k_by<K, E, IE>(self, k: K, by: E, descending: Vec<bool>) -> Expr
where K: Into<Expr>, E: AsRef<[IE]>, IE: Into<Expr> + Clone,

Available on crate feature top_k only.

Returns the k smallest rows by given column.

For single column, use Expr::bottom_k.

Source

pub fn reverse(self) -> Expr

Reverse column

Source

pub fn map<F>( self, function: F, output_type: SpecialEq<Arc<dyn FunctionOutputField>>, ) -> Expr
where F: Fn(Column) -> Result<Option<Column>, PolarsError> + 'static + Send + Sync,

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.

Source

pub fn map_many<F>( self, function: F, arguments: &[Expr], output_type: SpecialEq<Arc<dyn FunctionOutputField>>, ) -> Expr
where F: Fn(&mut [Column]) -> Result<Option<Column>, PolarsError> + 'static + Send + Sync,

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.

Source

pub fn map_list<F>( self, function: F, output_type: SpecialEq<Arc<dyn FunctionOutputField>>, ) -> Expr
where F: Fn(Column) -> Result<Option<Column>, PolarsError> + 'static + Send + Sync,

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

pub fn function_with_options<F>( self, function: F, output_type: SpecialEq<Arc<dyn FunctionOutputField>>, options: FunctionOptions, ) -> Expr
where F: Fn(Column) -> Result<Option<Column>, PolarsError> + 'static + Send + Sync,

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

Source

pub fn apply<F>( self, function: F, output_type: SpecialEq<Arc<dyn FunctionOutputField>>, ) -> Expr
where F: Fn(Column) -> Result<Option<Column>, PolarsError> + 'static + Send + Sync,

Apply a function/closure over the groups. This should only be used in a group_by 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.
Source

pub fn apply_many<F>( self, function: F, arguments: &[Expr], output_type: SpecialEq<Arc<dyn FunctionOutputField>>, ) -> Expr
where F: Fn(&mut [Column]) -> Result<Option<Column>, PolarsError> + 'static + Send + Sync,

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

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

Source

pub fn apply_many_private( self, function_expr: FunctionExpr, arguments: &[Expr], returns_scalar: bool, cast_to_supertypes: bool, ) -> Expr

Source

pub fn map_many_private( self, function_expr: FunctionExpr, arguments: &[Expr], returns_scalar: bool, cast_to_supertypes: Option<SuperTypeOptions>, ) -> Expr

Source

pub fn is_finite(self) -> Expr

Get mask of finite values if dtype is Float.

Source

pub fn is_infinite(self) -> Expr

Get mask of infinite values if dtype is Float.

Source

pub fn is_nan(self) -> Expr

Get mask of NaN values if dtype is Float.

Source

pub fn is_not_nan(self) -> Expr

Get inverse mask of NaN values if dtype is Float.

Source

pub fn shift(self, n: Expr) -> Expr

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

Source

pub fn shift_and_fill<E, IE>(self, n: E, fill_value: IE) -> Expr
where E: Into<Expr>, IE: Into<Expr>,

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

Source

pub fn cum_count(self, reverse: bool) -> Expr

Available on crate feature cum_agg only.

Cumulatively count values from 0 to len.

Source

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

Available on crate feature cum_agg only.

Get an array with the cumulative sum computed at every element.

Source

pub fn cum_prod(self, reverse: bool) -> Expr

Available on crate feature cum_agg only.

Get an array with the cumulative product computed at every element.

Source

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

Available on crate feature cum_agg only.

Get an array with the cumulative min computed at every element.

Source

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

Available on crate feature cum_agg only.

Get an array with the cumulative max computed at every element.

Source

pub fn product(self) -> Expr

Get the product aggregation of an expression.

Source

pub fn backward_fill(self, limit: Option<u64>) -> Expr

Fill missing value with next non-null.

Source

pub fn forward_fill(self, limit: Option<u64>) -> Expr

Fill missing value with previous non-null.

Source

pub fn round(self, decimals: u32) -> Expr

Available on crate feature round_series only.

Round underlying floating point array to given decimal numbers.

Source

pub fn round_sig_figs(self, digits: i32) -> Expr

Available on crate feature round_series only.

Round to a number of significant figures.

Source

pub fn floor(self) -> Expr

Available on crate feature round_series only.

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

Source

pub fn pi() -> Expr

Available on crate feature round_series only.

Constant Pi

Source

pub fn ceil(self) -> Expr

Available on crate feature round_series only.

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

Source

pub fn clip(self, min: Expr, max: Expr) -> Expr

Available on crate feature round_series only.

Clip underlying values to a set boundary.

Source

pub fn clip_max(self, max: Expr) -> Expr

Available on crate feature round_series only.

Clip underlying values to a set boundary.

Source

pub fn clip_min(self, min: Expr) -> Expr

Available on crate feature round_series only.

Clip underlying values to a set boundary.

Source

pub fn abs(self) -> Expr

Available on crate feature abs only.

Convert all values to their absolute/positive value.

Source

pub fn over<E, IE>(self, partition_by: E) -> Expr
where E: AsRef<[IE]>, IE: Into<Expr> + Clone,

Apply window function over a subgroup. This is similar to a group_by + 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() -> PolarsResult<()> {
    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()?;
    println!("{}", &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     │
╰────────┴────────╯
Source

pub fn over_with_options<E, IE>( self, partition_by: E, order_by: Option<(E, SortOptions)>, options: WindowMapping, ) -> Expr
where E: AsRef<[IE]>, IE: Into<Expr> + Clone,

Source

pub fn rolling(self, options: RollingGroupOptions) -> Expr

Available on crate feature dynamic_group_by only.
Source

pub fn fill_null<E>(self, fill_value: E) -> Expr
where E: Into<Expr>,

Replace the null values by a value.

Source

pub fn fill_null_with_strategy(self, strategy: FillNullStrategy) -> Expr

Source

pub fn fill_nan<E>(self, fill_value: E) -> Expr
where E: Into<Expr>,

Replace the floating point NaN values by a value.

Source

pub fn count(self) -> Expr

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

Source

pub fn len(self) -> Expr

Source

pub fn is_duplicated(self) -> Expr

Available on crate feature is_unique only.

Get a mask of duplicated values.

Source

pub fn is_unique(self) -> Expr

Available on crate feature is_unique only.

Get a mask of unique values.

Source

pub fn approx_n_unique(self) -> Expr

Available on crate feature approx_unique only.

Get the approximate count of unique values.

Source

pub fn and<E>(self, expr: E) -> Expr
where E: Into<Expr>,

Bitwise “and” operation.

Source

pub fn xor<E>(self, expr: E) -> Expr
where E: Into<Expr>,

Bitwise “xor” operation.

Source

pub fn or<E>(self, expr: E) -> Expr
where E: Into<Expr>,

Bitwise “or” operation.

Source

pub fn logical_or<E>(self, expr: E) -> Expr
where E: Into<Expr>,

Logical “or” operation.

Source

pub fn logical_and<E>(self, expr: E) -> Expr
where E: Into<Expr>,

Logical “and” operation.

Source

pub fn filter<E>(self, predicate: E) -> Expr
where E: Into<Expr>,

Filter a single column.

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

Source

pub fn is_in<E>(self, other: E) -> Expr
where E: Into<Expr>,

Available on crate feature is_in only.

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

Source

pub fn sort_by<E, IE>(self, by: E, sort_options: SortMultipleOptions) -> Expr
where E: AsRef<[IE]>, IE: Into<Expr> + Clone,

Sort this column by the ordering of another column evaluated from given expr. Can also be used in a group_by context to sort the groups.

§Example
let lf = df! {
    "a" => [1, 2, 3, 4, 5],
    "b" => [5, 4, 3, 2, 1]
}?.lazy();

let sorted = lf
    .select(
        vec![col("a").sort_by(col("b"), SortOptions::default())],
    )
    .collect()?;

assert_eq!(
    sorted,
    df! { "a" => [5, 4, 3, 2, 1] }?
);
Source

pub fn repeat_by<E>(self, by: E) -> Expr
where E: Into<Expr>,

Available on crate feature repeat_by only.

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

Source

pub fn is_first_distinct(self) -> Expr

Available on crate feature is_first_distinct only.

Get a mask of the first unique value.

Source

pub fn is_last_distinct(self) -> Expr

Available on crate feature is_last_distinct only.

Get a mask of the last unique value.

Source

pub fn dot<E>(self, other: E) -> Expr
where E: Into<Expr>,

Compute the dot/inner product between two expressions.

Source

pub fn mode(self) -> Expr

Available on crate feature mode only.

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

Source

pub fn exclude(self, columns: impl IntoVec<PlSmallStr>) -> Expr

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

Source

pub fn exclude_dtype<D>(self, dtypes: D) -> Expr
where D: AsRef<[DataType]>,

Source

pub fn interpolate(self, method: InterpolationMethod) -> Expr

Available on crate feature interpolate only.

Fill null values using interpolation.

Source

pub fn interpolate_by(self, by: Expr) -> Expr

Available on crate feature interpolate_by only.

Fill null values using interpolation.

Source

pub fn rolling_min_by( self, by: Expr, options: RollingOptionsDynamicWindow, ) -> Expr

Available on crate feature rolling_window_by only.

Apply a rolling minimum based on another column.

Source

pub fn rolling_max_by( self, by: Expr, options: RollingOptionsDynamicWindow, ) -> Expr

Available on crate feature rolling_window_by only.

Apply a rolling maximum based on another column.

Source

pub fn rolling_mean_by( self, by: Expr, options: RollingOptionsDynamicWindow, ) -> Expr

Available on crate feature rolling_window_by only.

Apply a rolling mean based on another column.

Source

pub fn rolling_sum_by( self, by: Expr, options: RollingOptionsDynamicWindow, ) -> Expr

Available on crate feature rolling_window_by only.

Apply a rolling sum based on another column.

Source

pub fn rolling_quantile_by( self, by: Expr, method: QuantileMethod, quantile: f64, options: RollingOptionsDynamicWindow, ) -> Expr

Available on crate feature rolling_window_by only.

Apply a rolling quantile based on another column.

Source

pub fn rolling_var_by( self, by: Expr, options: RollingOptionsDynamicWindow, ) -> Expr

Available on crate feature rolling_window_by only.

Apply a rolling variance based on another column.

Source

pub fn rolling_std_by( self, by: Expr, options: RollingOptionsDynamicWindow, ) -> Expr

Available on crate feature rolling_window_by only.

Apply a rolling std-dev based on another column.

Source

pub fn rolling_median_by( self, by: Expr, options: RollingOptionsDynamicWindow, ) -> Expr

Available on crate feature rolling_window_by only.

Apply a rolling median based on another column.

Source

pub fn rolling_min(self, options: RollingOptionsFixedWindow) -> Expr

Available on crate feature rolling_window only.

Apply a rolling minimum.

See: [RollingAgg::rolling_min]

Source

pub fn rolling_max(self, options: RollingOptionsFixedWindow) -> Expr

Available on crate feature rolling_window only.

Apply a rolling maximum.

See: [RollingAgg::rolling_max]

Source

pub fn rolling_mean(self, options: RollingOptionsFixedWindow) -> Expr

Available on crate feature rolling_window only.

Apply a rolling mean.

See: [RollingAgg::rolling_mean]

Source

pub fn rolling_sum(self, options: RollingOptionsFixedWindow) -> Expr

Available on crate feature rolling_window only.

Apply a rolling sum.

See: [RollingAgg::rolling_sum]

Source

pub fn rolling_median(self, options: RollingOptionsFixedWindow) -> Expr

Available on crate feature rolling_window only.

Apply a rolling median.

See: [RollingAgg::rolling_median]

Source

pub fn rolling_quantile( self, method: QuantileMethod, quantile: f64, options: RollingOptionsFixedWindow, ) -> Expr

Available on crate feature rolling_window only.

Apply a rolling quantile.

See: [RollingAgg::rolling_quantile]

Source

pub fn rolling_var(self, options: RollingOptionsFixedWindow) -> Expr

Available on crate feature rolling_window only.

Apply a rolling variance.

Source

pub fn rolling_std(self, options: RollingOptionsFixedWindow) -> Expr

Available on crate feature rolling_window only.

Apply a rolling std-dev.

Source

pub fn rolling_skew(self, window_size: usize, bias: bool) -> Expr

Available on crate features rolling_window and moment only.

Apply a rolling skew.

Source

pub fn rolling_map( self, f: Arc<dyn Fn(&Series) -> Series + Send + Sync>, output_type: SpecialEq<Arc<dyn FunctionOutputField>>, options: RollingOptionsFixedWindow, ) -> Expr

Available on crate feature rolling_window only.

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.

Source

pub fn rolling_map_float<F>(self, window_size: usize, f: F) -> Expr
where F: 'static + FnMut(&mut ChunkedArray<Float64Type>) -> Option<f64> + Send + Sync + Copy,

Available on crate feature rolling_window only.

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.

Source

pub fn peak_min(self) -> Expr

Available on crate feature peaks only.
Source

pub fn peak_max(self) -> Expr

Available on crate feature peaks only.
Source

pub fn rank(self, options: RankOptions, seed: Option<u64>) -> Expr

Available on crate feature rank only.

Assign ranks to data, dealing with ties appropriately.

Source

pub fn replace<E>(self, old: E, new: E) -> Expr
where E: Into<Expr>,

Available on crate feature replace only.

Replace the given values with other values.

Source

pub fn replace_strict<E>( self, old: E, new: E, default: Option<E>, return_dtype: Option<DataType>, ) -> Expr
where E: Into<Expr>,

Available on crate feature replace only.

Replace the given values with other values.

Source

pub fn cut( self, breaks: Vec<f64>, labels: Option<impl IntoVec<PlSmallStr>>, left_closed: bool, include_breaks: bool, ) -> Expr

Available on crate feature cutqcut only.

Bin continuous values into discrete categories.

Source

pub fn qcut( self, probs: Vec<f64>, labels: Option<impl IntoVec<PlSmallStr>>, left_closed: bool, allow_duplicates: bool, include_breaks: bool, ) -> Expr

Available on crate feature cutqcut only.

Bin continuous values into discrete categories based on their quantiles.

Source

pub fn qcut_uniform( self, n_bins: usize, labels: Option<impl IntoVec<PlSmallStr>>, left_closed: bool, allow_duplicates: bool, include_breaks: bool, ) -> Expr

Available on crate feature cutqcut only.

Bin continuous values into discrete categories using uniform quantile probabilities.

Source

pub fn rle(self) -> Expr

Available on crate feature rle only.

Get the lengths of runs of identical values.

Source

pub fn rle_id(self) -> Expr

Available on crate feature rle only.

Similar to rle, but maps values to run IDs.

Source

pub fn diff(self, n: i64, null_behavior: NullBehavior) -> Expr

Available on crate feature diff only.

Calculate the n-th discrete difference between values.

Source

pub fn pct_change(self, n: Expr) -> Expr

Available on crate feature pct_change only.

Computes percentage change between values.

Source

pub fn skew(self, bias: bool) -> Expr

Available on crate feature moment only.

Compute the sample skewness of a data set.

For normally distributed data, the skewness should be about zero. For uni-modal continuous distributions, a skewness value greater than zero means that there is more weight in the right tail of the distribution. The function skewtest can be used to determine if the skewness value is close enough to zero, statistically speaking.

see: scipy

Source

pub fn kurtosis(self, fisher: bool, bias: bool) -> Expr

Available on crate feature moment only.

Compute the kurtosis (Fisher or Pearson).

Kurtosis is the fourth central moment divided by the square of the variance. If Fisher’s definition is used, then 3.0 is subtracted from the result to give 0.0 for a normal distribution. If bias is False then the kurtosis is calculated using k statistics to eliminate bias coming from biased moment estimators.

Source

pub fn upper_bound(self) -> Expr

Get maximal value that could be hold by this dtype.

Source

pub fn lower_bound(self) -> Expr

Get minimal value that could be hold by this dtype.

Source

pub fn reshape(self, dimensions: &[i64]) -> Expr

Available on crate feature dtype-array only.
Source

pub fn ewm_mean(self, options: EWMOptions) -> Expr

Available on crate feature ewma only.

Calculate the exponentially-weighted moving average.

Source

pub fn ewm_std(self, options: EWMOptions) -> Expr

Available on crate feature ewma only.

Calculate the exponentially-weighted moving standard deviation.

Source

pub fn ewm_var(self, options: EWMOptions) -> Expr

Available on crate feature ewma only.

Calculate the exponentially-weighted moving variance.

Source

pub fn any(self, ignore_nulls: bool) -> Expr

Returns whether any of the values in the column are true.

If ignore_nulls is False, Kleene logic is used to deal with nulls: if the column contains any null values and no true values, the output is null.

Source

pub fn all(self, ignore_nulls: bool) -> Expr

Returns whether all values in the column are true.

If ignore_nulls is False, Kleene logic is used to deal with nulls: if the column contains any null values and no true values, the output is null.

Source

pub fn shrink_dtype(self) -> Expr

Shrink numeric columns to the minimal required datatype needed to fit the extrema of this Series. This can be used to reduce memory pressure.

Source

pub fn value_counts( self, sort: bool, parallel: bool, name: &str, normalize: bool, ) -> Expr

Available on crate feature dtype-struct only.

Count all unique values and create a struct mapping value to count. (Note that it is better to turn parallel off in the aggregation context). The name of the struct field with the counts is given by the parameter name.

Source

pub fn unique_counts(self) -> Expr

Available on crate feature unique_counts only.

Returns a count of the unique values in the order of appearance. This method differs from Expr::value_counts in that it does not return the values, only the counts and might be faster.

Source

pub fn log(self, base: f64) -> Expr

Available on crate feature log only.

Compute the logarithm to a given base.

Source

pub fn log1p(self) -> Expr

Available on crate feature log only.

Compute the natural logarithm of all elements plus one in the input array.

Source

pub fn exp(self) -> Expr

Available on crate feature log only.

Calculate the exponential of all elements in the input array.

Source

pub fn entropy(self, base: f64, normalize: bool) -> Expr

Available on crate feature log only.

Compute the entropy as -sum(pk * log(pk). where pk are discrete probabilities.

Source

pub fn null_count(self) -> Expr

Get the null count of the column/group.

Source

pub fn set_sorted_flag(self, sorted: IsSorted) -> Expr

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!

Source

pub fn hash(self, k0: u64, k1: u64, k2: u64, k3: u64) -> Expr

Available on crate feature row_hash only.

Compute the hash of every element.

Source

pub fn to_physical(self) -> Expr

Source

pub fn gather_every(self, n: usize, offset: usize) -> Expr

Source

pub fn extend_constant(self, value: Expr, n: Expr) -> Expr

Source

pub fn str(self) -> StringNameSpace

Available on crate feature strings only.
Source

pub fn binary(self) -> BinaryNameSpace

Source

pub fn dt(self) -> DateLikeNameSpace

Available on crate feature temporal only.
Source

pub fn list(self) -> ListNameSpace

Source

pub fn name(self) -> ExprNameNameSpace

Source

pub fn arr(self) -> ArrayNameSpace

Available on crate feature dtype-array only.
Source

pub fn cat(self) -> CategoricalNameSpace

Available on crate feature dtype-categorical only.
Source

pub fn struct_(self) -> StructNameSpace

Available on crate feature dtype-struct only.
Source

pub fn meta(self) -> MetaNameSpace

Available on crate feature meta only.
Source§

impl Expr

Source

pub fn nodes<'a>(&'a self, container: &mut UnitVec<&'a Expr>)

Source

pub fn nodes_owned(self, container: &mut UnitVec<Expr>)

Source

pub fn map_expr<F>(self, f: F) -> Expr
where F: FnMut(Expr) -> Expr,

Source

pub fn try_map_expr<F>(self, f: F) -> Result<Expr, PolarsError>
where F: FnMut(Expr) -> Result<Expr, PolarsError>,

Trait Implementations§

Source§

impl Add for Expr

Source§

type Output = Expr

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Expr) -> <Expr as Add>::Output

Performs the + operation. Read more
Source§

impl AsRef<Expr> for AggExpr

Source§

fn as_ref(&self) -> &Expr

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

impl Clone for Expr

Source§

fn clone(&self) -> Expr

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Expr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Expr

Source§

fn default() -> Expr

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

impl<'de> Deserialize<'de> for Expr

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Expr, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Expr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Div for Expr

Source§

type Output = Expr

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Expr) -> <Expr as Div>::Output

Performs the / operation. Read more
Source§

impl ExprEvalExtension for Expr

Available on crate features cumulative_eval or list_eval only.
Source§

fn cumulative_eval(self, expr: Expr, min_periods: usize, parallel: bool) -> Expr

Run an expression over a sliding window that increases 1 slot every iteration. Read more
Source§

impl From<&str> for Expr

Source§

fn from(s: &str) -> Expr

Converts to this type from the input type.
Source§

impl From<AggExpr> for Expr

Source§

fn from(agg: AggExpr) -> Expr

Converts to this type from the input type.
Source§

impl From<Expr> for Selector

Source§

fn from(value: Expr) -> Selector

Converts to this type from the input type.
Source§

impl From<bool> for Expr

Source§

fn from(val: bool) -> Expr

Converts to this type from the input type.
Source§

impl From<f32> for Expr

Source§

fn from(val: f32) -> Expr

Converts to this type from the input type.
Source§

impl From<f64> for Expr

Source§

fn from(val: f64) -> Expr

Converts to this type from the input type.
Source§

impl From<i16> for Expr

Source§

fn from(val: i16) -> Expr

Converts to this type from the input type.
Source§

impl From<i32> for Expr

Source§

fn from(val: i32) -> Expr

Converts to this type from the input type.
Source§

impl From<i64> for Expr

Source§

fn from(val: i64) -> Expr

Converts to this type from the input type.
Source§

impl From<i8> for Expr

Source§

fn from(val: i8) -> Expr

Converts to this type from the input type.
Source§

impl From<u16> for Expr

Source§

fn from(val: u16) -> Expr

Converts to this type from the input type.
Source§

impl From<u32> for Expr

Source§

fn from(val: u32) -> Expr

Converts to this type from the input type.
Source§

impl From<u64> for Expr

Source§

fn from(val: u64) -> Expr

Converts to this type from the input type.
Source§

impl From<u8> for Expr

Source§

fn from(val: u8) -> Expr

Converts to this type from the input type.
Source§

impl Hash for Expr

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl<'a> IntoIterator for &'a Expr

Source§

type Item = &'a Expr

The type of the elements being iterated over.
Source§

type IntoIter = ExprIter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <&'a Expr as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl Mul for Expr

Source§

type Output = Expr

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Expr) -> <Expr as Mul>::Output

Performs the * operation. Read more
Source§

impl Neg for Expr

Source§

type Output = Expr

The resulting type after applying the - operator.
Source§

fn neg(self) -> <Expr as Neg>::Output

Performs the unary - operation. Read more
Source§

impl PartialEq for Expr

Source§

fn eq(&self, other: &Expr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Rem for Expr

Source§

type Output = Expr

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Expr) -> <Expr as Rem>::Output

Performs the % operation. Read more
Source§

impl Serialize for Expr

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Sub for Expr

Source§

type Output = Expr

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Expr) -> <Expr as Sub>::Output

Performs the - operation. Read more
Source§

impl TreeWalker for Expr

Source§

type Arena = ()

Source§

fn apply_children<F>( &self, op: &mut F, arena: &<Expr as TreeWalker>::Arena, ) -> Result<VisitRecursion, PolarsError>

Source§

fn map_children<F>( self, f: &mut F, _arena: &mut <Expr as TreeWalker>::Arena, ) -> Result<Expr, PolarsError>
where F: FnMut(Expr, &mut <Expr as TreeWalker>::Arena) -> Result<Expr, PolarsError>,

Source§

fn visit<V>( &self, visitor: &mut V, arena: &Self::Arena, ) -> Result<VisitRecursion, PolarsError>
where V: Visitor<Node = Self, Arena = Self::Arena>,

Walks all nodes in depth-first-order.
Source§

fn rewrite<R>( self, rewriter: &mut R, arena: &mut Self::Arena, ) -> Result<Self, PolarsError>
where R: RewritingVisitor<Node = Self, Arena = Self::Arena>,

Source§

impl Eq for Expr

Source§

impl StructuralPartialEq for Expr

Auto Trait Implementations§

§

impl !Freeze for Expr

§

impl !RefUnwindSafe for Expr

§

impl Send for Expr

§

impl Sync for Expr

§

impl Unpin for Expr

§

impl !UnwindSafe for Expr

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T

Source§

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