Enum polars_lazy::dsl::Expr [−][src]
pub enum Expr {
Show 29 variants
Alias(Box<Expr>, Arc<String>),
Column(Arc<String>),
Columns(Vec<String>),
DtypeColumn(Vec<DataType>),
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,
strict: bool,
},
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: GetOutput,
options: FunctionOptions,
},
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>>,
options: WindowOptions,
},
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>>,
},
Exclude(Box<Expr>, Vec<Arc<String>>),
KeepName(Box<Expr>),
SufPreFix {
is_suffix: bool,
value: String,
expr: Box<Expr>,
},
}
compile
only.Expand description
Queries consists of multiple expressions.
Variants
Literal(LiteralValue)
Tuple Fields of Literal
0: LiteralValue
Agg(AggExpr)
Tuple Fields of Agg
0: AggExpr
A ternary operation if true then “foo” else “bar”
Fields of Function
See postgres window functions
Fields of Window
Fields of Slice
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.
Can be used in a select statement to exclude a column from selection
Set root name as Alias
Implementations
Run is_not_null operation on Expr
.
Get the group indexes of the group by operation.
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. Throws an error if conversion had overflows
Sort in increasing order. See the eager implementation.
Can be used in default
and aggregation
context.
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
, orraise 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.
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
, orraise 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.
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
, orraise to the power
apply
should be used for operations that work on a group of data. e.g.sum
,count
, etc.
Get mask of infinite 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.
This is supported on crate feature cum_agg
only.
cum_agg
only.Get an array with the cumulative sum computed at every element
This is supported on crate feature cum_agg
only.
cum_agg
only.Get an array with the cumulative product computed at every element
This is supported on crate feature cum_agg
only.
cum_agg
only.Get an array with the cumulative min computed at every element
This is supported on crate feature cum_agg
only.
cum_agg
only.Get an array with the cumulative max computed at every element
Fill missing value with next non-null.
Fill missing value with previous non-null.
This is supported on crate feature round_series
only.
round_series
only.Round underlying floating point array to given decimal numbers.
This is supported on crate feature round_series
only.
round_series
only.Floor underlying floating point array to the lowest integers smaller or equal to the float 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 floating point NaN
values by a value.
Count the values of the Series or Get counts of the group by operation.
Get a mask of duplicated values
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.
is_in
only.Check if the values of the left expression are in the lists of the right expr.
This is supported on crate feature temporal
only.
temporal
only.Get the year of a Date/Datetime
This is supported on crate feature temporal
only.
temporal
only.Get the month of a Date/Datetime
This is supported on crate feature temporal
only.
temporal
only.Extract the week from the underlying Date representation. Can be performed on Date and Datetime Returns the ISO week number starting from 1. The return value ranges from 1 to 53. (The last week of year differs by years.)
This is supported on crate feature temporal
only.
temporal
only.Extract the week day from the underlying Date representation. Can be performed on Date and Datetime. Returns the weekday number where monday = 0 and sunday = 6
This is supported on crate feature temporal
only.
temporal
only.Get the month of a Date/Datetime
This is supported on crate feature temporal
only.
temporal
only.Get the ordinal_day of a Date/Datetime
This is supported on crate feature temporal
only.
temporal
only.Get the hour of a Datetime/Time64
This is supported on crate feature temporal
only.
temporal
only.Get the minute of a Datetime/Time64
This is supported on crate feature temporal
only.
temporal
only.Get the second of a Datetime/Time64
This is supported on crate feature temporal
only.
temporal
only.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.
repeat_by
only.This is supported on crate feature is_first
only.
is_first
only.Get a mask of the first unique value.
dot_product
only.This is supported on crate feature mode
only.
mode
only.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()
])
}
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"])
])
}
interpolate
only.This is supported on crate feature rolling_window
only.
rolling_window
only.Apply a rolling min See: ChunkedArray::rolling_min.
This is supported on crate feature rolling_window
only.
rolling_window
only.Apply a rolling max See: ChunkedArray::rolling_max.
This is supported on crate feature rolling_window
only.
rolling_window
only.Apply a rolling mean See: ChunkedArray::rolling_mean.
This is supported on crate feature rolling_window
only.
rolling_window
only.Apply a rolling sum See: ChunkedArray::rolling_sum.
This is supported on crate feature rolling_window
only.
rolling_window
only.Apply a rolling variance
This is supported on crate feature rolling_window
only.
rolling_window
only.Apply a rolling std-dev
pub fn rolling_apply(
self,
window_size: usize,
f: Arc<dyn Fn(&Series) -> Series + Send + Sync>,
output_type: GetOutput
) -> Expr
This is supported on crate feature rolling_window
only.
pub fn rolling_apply(
self,
window_size: usize,
f: Arc<dyn Fn(&Series) -> Series + Send + Sync>,
output_type: GetOutput
) -> Expr
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.
pub fn rolling_apply_float<F>(self, window_size: usize, f: F) -> Expr where
F: 'static + Fn(&Float64Chunked) -> Option<f64> + Send + Sync + Copy,
This is supported on crate feature rolling_window
only.
pub fn rolling_apply_float<F>(self, window_size: usize, f: F) -> Expr where
F: 'static + Fn(&Float64Chunked) -> Option<f64> + Send + Sync + Copy,
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.
rank
only.diff
only.moment
only.moment
only.This is supported on crate feature concat_str
only.
concat_str
only.Concat the values into a string array.
Arguments
delimiter
- A string that will act as delimiter between values.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Expr
impl !UnwindSafe for Expr
Blanket Implementations
Mutably borrows from an owned value. Read more