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: OpaqueColumnUdf,
output_type: GetOutput,
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
Cast
Sort
Gather
SortBy
Agg(AggExpr)
Ternary
A ternary operation if true then “foo” else “bar”
Function
Explode(Arc<Expr>)
Filter
Window
Polars flavored window functions.
Wildcard
Slice
Fields
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
Field(Arc<[PlSmallStr]>)
dtype-struct
only.AnonymousFunction
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
impl Expr
Sourcepub fn cos(self) -> Self
Available on crate feature trigonometry
only.
pub fn cos(self) -> Self
trigonometry
only.Compute the cosine of the given expression
Sourcepub fn cot(self) -> Self
Available on crate feature trigonometry
only.
pub fn cot(self) -> Self
trigonometry
only.Compute the cotangent of the given expression
Sourcepub fn sin(self) -> Self
Available on crate feature trigonometry
only.
pub fn sin(self) -> Self
trigonometry
only.Compute the sine of the given expression
Sourcepub fn tan(self) -> Self
Available on crate feature trigonometry
only.
pub fn tan(self) -> Self
trigonometry
only.Compute the tangent of the given expression
Sourcepub fn arccos(self) -> Self
Available on crate feature trigonometry
only.
pub fn arccos(self) -> Self
trigonometry
only.Compute the inverse cosine of the given expression
Sourcepub fn arcsin(self) -> Self
Available on crate feature trigonometry
only.
pub fn arcsin(self) -> Self
trigonometry
only.Compute the inverse sine of the given expression
Sourcepub fn arctan(self) -> Self
Available on crate feature trigonometry
only.
pub fn arctan(self) -> Self
trigonometry
only.Compute the inverse tangent of the given expression
Sourcepub fn arctan2(self, x: Self) -> Self
Available on crate feature trigonometry
only.
pub fn arctan2(self, x: Self) -> Self
trigonometry
only.Compute the inverse tangent of the given expression, with the angle expressed as the argument of a complex number
Sourcepub fn cosh(self) -> Self
Available on crate feature trigonometry
only.
pub fn cosh(self) -> Self
trigonometry
only.Compute the hyperbolic cosine of the given expression
Sourcepub fn sinh(self) -> Self
Available on crate feature trigonometry
only.
pub fn sinh(self) -> Self
trigonometry
only.Compute the hyperbolic sine of the given expression
Sourcepub fn tanh(self) -> Self
Available on crate feature trigonometry
only.
pub fn tanh(self) -> Self
trigonometry
only.Compute the hyperbolic tangent of the given expression
Sourcepub fn arccosh(self) -> Self
Available on crate feature trigonometry
only.
pub fn arccosh(self) -> Self
trigonometry
only.Compute the inverse hyperbolic cosine of the given expression
Sourcepub fn arcsinh(self) -> Self
Available on crate feature trigonometry
only.
pub fn arcsinh(self) -> Self
trigonometry
only.Compute the inverse hyperbolic sine of the given expression
Sourcepub fn arctanh(self) -> Self
Available on crate feature trigonometry
only.
pub fn arctanh(self) -> Self
trigonometry
only.Compute the inverse hyperbolic tangent of the given expression
Sourcepub fn degrees(self) -> Self
Available on crate feature trigonometry
only.
pub fn degrees(self) -> Self
trigonometry
only.Convert from radians to degrees
Source§impl Expr
impl Expr
Sourcepub fn bitwise_count_ones(self) -> Self
Available on crate feature bitwise
only.
pub fn bitwise_count_ones(self) -> Self
bitwise
only.Evaluate the number of set bits.
Sourcepub fn bitwise_count_zeros(self) -> Self
Available on crate feature bitwise
only.
pub fn bitwise_count_zeros(self) -> Self
bitwise
only.Evaluate the number of unset bits.
Sourcepub fn bitwise_leading_ones(self) -> Self
Available on crate feature bitwise
only.
pub fn bitwise_leading_ones(self) -> Self
bitwise
only.Evaluate the number most-significant set bits before seeing an unset bit.
Sourcepub fn bitwise_leading_zeros(self) -> Self
Available on crate feature bitwise
only.
pub fn bitwise_leading_zeros(self) -> Self
bitwise
only.Evaluate the number most-significant unset bits before seeing an set bit.
Sourcepub fn bitwise_trailing_ones(self) -> Self
Available on crate feature bitwise
only.
pub fn bitwise_trailing_ones(self) -> Self
bitwise
only.Evaluate the number least-significant set bits before seeing an unset bit.
Sourcepub fn bitwise_trailing_zeros(self) -> Self
Available on crate feature bitwise
only.
pub fn bitwise_trailing_zeros(self) -> Self
bitwise
only.Evaluate the number least-significant unset bits before seeing an set bit.
Sourcepub fn bitwise_and(self) -> Self
Available on crate feature bitwise
only.
pub fn bitwise_and(self) -> Self
bitwise
only.Perform an aggregation of bitwise ANDs
Sourcepub fn bitwise_or(self) -> Self
Available on crate feature bitwise
only.
pub fn bitwise_or(self) -> Self
bitwise
only.Perform an aggregation of bitwise ORs
Sourcepub fn bitwise_xor(self) -> Self
Available on crate feature bitwise
only.
pub fn bitwise_xor(self) -> Self
bitwise
only.Perform an aggregation of bitwise XORs
Source§impl Expr
impl Expr
pub fn map_python(self, func: PythonUdfExpression, agg_list: bool) -> Expr
python
only.Source§impl Expr
impl Expr
pub fn shuffle(self, seed: Option<u64>) -> Self
random
only.pub fn sample_n( self, n: Expr, with_replacement: bool, shuffle: bool, seed: Option<u64>, ) -> Self
random
only.pub fn sample_frac( self, frac: Expr, with_replacement: bool, shuffle: bool, seed: Option<u64>, ) -> Self
random
only.Source§impl Expr
impl Expr
Sourcepub fn eq_missing<E: Into<Expr>>(self, other: E) -> Expr
pub fn eq_missing<E: Into<Expr>>(self, other: E) -> Expr
Compare Expr
with other Expr
on equality where None == None
.
Sourcepub fn neq<E: Into<Expr>>(self, other: E) -> Expr
pub fn neq<E: Into<Expr>>(self, other: E) -> Expr
Compare Expr
with other Expr
on non-equality.
Sourcepub fn neq_missing<E: Into<Expr>>(self, other: E) -> Expr
pub fn neq_missing<E: Into<Expr>>(self, other: E) -> Expr
Compare Expr
with other Expr
on non-equality where None == None
.
Sourcepub fn alias<S>(self, name: S) -> Exprwhere
S: Into<PlSmallStr>,
pub fn alias<S>(self, name: S) -> Exprwhere
S: Into<PlSmallStr>,
Rename Column.
Sourcepub fn is_not_null(self) -> Self
pub fn is_not_null(self) -> Self
Run is_not_null operation on Expr
.
Sourcepub fn drop_nulls(self) -> Self
pub fn drop_nulls(self) -> Self
Drop null values.
Sourcepub fn quantile(self, quantile: Expr, method: QuantileMethod) -> Self
pub fn quantile(self, quantile: Expr, method: QuantileMethod) -> Self
Compute the quantile per group.
Sourcepub fn agg_groups(self) -> Self
pub fn agg_groups(self) -> Self
Get the group indexes of the group by operation.
Sourcepub fn slice<E: Into<Expr>, F: Into<Expr>>(self, offset: E, length: F) -> Self
pub fn slice<E: Into<Expr>, F: Into<Expr>>(self, offset: E, length: F) -> Self
Slice the Series.
offset
may be negative.
Sourcepub fn append<E: Into<Expr>>(self, other: E, upcast: bool) -> Self
pub fn append<E: Into<Expr>>(self, other: E, upcast: bool) -> Self
Append expressions. This is done by adding the chunks of other
to this Series
.
Sourcepub fn unique_stable(self) -> Self
pub fn unique_stable(self) -> Self
Get unique values of this expression, while maintaining order.
This requires more work than Expr::unique
.
Sourcepub fn arg_unique(self) -> Self
pub fn arg_unique(self) -> Self
Get the first index of unique values of this expression.
Sourcepub fn arg_sort(self, sort_options: SortOptions) -> Self
pub fn arg_sort(self, sort_options: SortOptions) -> Self
Get the index values that would sort this expression.
Sourcepub fn search_sorted<E: Into<Expr>>(
self,
element: E,
side: SearchSortedSide,
) -> Expr
Available on crate feature search_sorted
only.
pub fn search_sorted<E: Into<Expr>>( self, element: E, side: SearchSortedSide, ) -> Expr
search_sorted
only.Find indices where elements should be inserted to maintain order.
Sourcepub fn strict_cast(self, dtype: DataType) -> Self
pub fn strict_cast(self, dtype: DataType) -> Self
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.
Sourcepub fn cast_with_options(
self,
dtype: DataType,
cast_options: CastOptions,
) -> Self
pub fn cast_with_options( self, dtype: DataType, cast_options: CastOptions, ) -> Self
Cast expression to another data type.
Sourcepub fn sort(self, options: SortOptions) -> Self
pub fn sort(self, options: SortOptions) -> Self
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.
Sourcepub fn top_k(self, k: Expr) -> Self
Available on crate feature top_k
only.
pub fn top_k(self, k: Expr) -> Self
top_k
only.Returns the k
largest elements.
This has time complexity O(n + k log(n))
.
Sourcepub fn top_k_by<K: Into<Expr>, E: AsRef<[IE]>, IE: Into<Expr> + Clone>(
self,
k: K,
by: E,
descending: Vec<bool>,
) -> Self
Available on crate feature top_k
only.
pub fn top_k_by<K: Into<Expr>, E: AsRef<[IE]>, IE: Into<Expr> + Clone>( self, k: K, by: E, descending: Vec<bool>, ) -> Self
top_k
only.Returns the k
largest rows by given column.
For single column, use Expr::top_k
.
Sourcepub fn bottom_k(self, k: Expr) -> Self
Available on crate feature top_k
only.
pub fn bottom_k(self, k: Expr) -> Self
top_k
only.Returns the k
smallest elements.
This has time complexity O(n + k log(n))
.
Sourcepub fn bottom_k_by<K: Into<Expr>, E: AsRef<[IE]>, IE: Into<Expr> + Clone>(
self,
k: K,
by: E,
descending: Vec<bool>,
) -> Self
Available on crate feature top_k
only.
pub fn bottom_k_by<K: Into<Expr>, E: AsRef<[IE]>, IE: Into<Expr> + Clone>( self, k: K, by: E, descending: Vec<bool>, ) -> Self
top_k
only.Returns the k
smallest rows by given column.
For single column, use Expr::bottom_k
.
Sourcepub fn map<F>(self, function: F, output_type: GetOutput) -> Self
pub fn map<F>(self, function: F, output_type: GetOutput) -> Self
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
, 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.
Sourcepub fn map_list<F>(self, function: F, output_type: GetOutput) -> Self
pub fn map_list<F>(self, function: F, output_type: GetOutput) -> Self
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.
Sourcepub fn function_with_options<F>(
self,
function: F,
output_type: GetOutput,
options: FunctionOptions,
) -> Self
pub fn function_with_options<F>( self, function: F, output_type: GetOutput, options: FunctionOptions, ) -> Self
A function that cannot be expressed with map
or apply
and requires extra settings.
Sourcepub fn apply<F>(self, function: F, output_type: GetOutput) -> Self
pub fn apply<F>(self, function: F, output_type: GetOutput) -> Self
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
, orraise to the power
apply
should be used for operations that work on a group of data. e.g.sum
,count
, etc.
Sourcepub fn apply_many<F>(
self,
function: F,
arguments: &[Expr],
output_type: GetOutput,
) -> Self
pub fn apply_many<F>( self, function: F, arguments: &[Expr], output_type: GetOutput, ) -> Self
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
.
pub fn apply_many_private( self, function_expr: FunctionExpr, arguments: &[Expr], returns_scalar: bool, cast_to_supertypes: bool, ) -> Self
pub fn map_many_private( self, function_expr: FunctionExpr, arguments: &[Expr], returns_scalar: bool, cast_to_supertypes: Option<SuperTypeOptions>, ) -> Self
Sourcepub fn is_infinite(self) -> Self
pub fn is_infinite(self) -> Self
Get mask of infinite values if dtype is Float.
Sourcepub fn is_not_nan(self) -> Self
pub fn is_not_nan(self) -> Self
Get inverse mask of NaN values if dtype is Float.
Sourcepub fn shift(self, n: Expr) -> Self
pub fn shift(self, n: Expr) -> Self
Shift the values in the array by some period. See the eager implementation.
Sourcepub fn shift_and_fill<E: Into<Expr>, IE: Into<Expr>>(
self,
n: E,
fill_value: IE,
) -> Self
pub fn shift_and_fill<E: Into<Expr>, IE: Into<Expr>>( self, n: E, fill_value: IE, ) -> Self
Shift the values in the array by some period and fill the resulting empty values.
Sourcepub fn cum_count(self, reverse: bool) -> Self
Available on crate feature cum_agg
only.
pub fn cum_count(self, reverse: bool) -> Self
cum_agg
only.Cumulatively count values from 0 to len.
Sourcepub fn cum_sum(self, reverse: bool) -> Self
Available on crate feature cum_agg
only.
pub fn cum_sum(self, reverse: bool) -> Self
cum_agg
only.Get an array with the cumulative sum computed at every element.
Sourcepub fn cum_prod(self, reverse: bool) -> Self
Available on crate feature cum_agg
only.
pub fn cum_prod(self, reverse: bool) -> Self
cum_agg
only.Get an array with the cumulative product computed at every element.
Sourcepub fn cum_min(self, reverse: bool) -> Self
Available on crate feature cum_agg
only.
pub fn cum_min(self, reverse: bool) -> Self
cum_agg
only.Get an array with the cumulative min computed at every element.
Sourcepub fn cum_max(self, reverse: bool) -> Self
Available on crate feature cum_agg
only.
pub fn cum_max(self, reverse: bool) -> Self
cum_agg
only.Get an array with the cumulative max computed at every element.
Sourcepub fn backward_fill(self, limit: FillNullLimit) -> Self
pub fn backward_fill(self, limit: FillNullLimit) -> Self
Fill missing value with next non-null.
Sourcepub fn forward_fill(self, limit: FillNullLimit) -> Self
pub fn forward_fill(self, limit: FillNullLimit) -> Self
Fill missing value with previous non-null.
Sourcepub fn round(self, decimals: u32) -> Self
Available on crate feature round_series
only.
pub fn round(self, decimals: u32) -> Self
round_series
only.Round underlying floating point array to given decimal numbers.
Sourcepub fn round_sig_figs(self, digits: i32) -> Self
Available on crate feature round_series
only.
pub fn round_sig_figs(self, digits: i32) -> Self
round_series
only.Round to a number of significant figures.
Sourcepub fn floor(self) -> Self
Available on crate feature round_series
only.
pub fn floor(self) -> Self
round_series
only.Floor underlying floating point array to the lowest integers smaller or equal to the float value.
Sourcepub fn ceil(self) -> Self
Available on crate feature round_series
only.
pub fn ceil(self) -> Self
round_series
only.Ceil underlying floating point array to the highest integers smaller or equal to the float value.
Sourcepub fn clip(self, min: Expr, max: Expr) -> Self
Available on crate feature round_series
only.
pub fn clip(self, min: Expr, max: Expr) -> Self
round_series
only.Clip underlying values to a set boundary.
Sourcepub fn clip_max(self, max: Expr) -> Self
Available on crate feature round_series
only.
pub fn clip_max(self, max: Expr) -> Self
round_series
only.Clip underlying values to a set boundary.
Sourcepub fn clip_min(self, min: Expr) -> Self
Available on crate feature round_series
only.
pub fn clip_min(self, min: Expr) -> Self
round_series
only.Clip underlying values to a set boundary.
Sourcepub fn abs(self) -> Self
Available on crate feature abs
only.
pub fn abs(self) -> Self
abs
only.Convert all values to their absolute/positive value.
Sourcepub fn over<E: AsRef<[IE]>, IE: Into<Expr> + Clone>(
self,
partition_by: E,
) -> Self
pub fn over<E: AsRef<[IE]>, IE: Into<Expr> + Clone>( self, partition_by: E, ) -> Self
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 │
╰────────┴────────╯
pub fn over_with_options<E: AsRef<[IE]>, IE: Into<Expr> + Clone>( self, partition_by: E, order_by: Option<(E, SortOptions)>, options: WindowMapping, ) -> Self
Sourcepub fn fill_null<E: Into<Expr>>(self, fill_value: E) -> Self
pub fn fill_null<E: Into<Expr>>(self, fill_value: E) -> Self
Replace the null values by a value.
pub fn fill_null_with_strategy(self, strategy: FillNullStrategy) -> Self
Sourcepub fn fill_nan<E: Into<Expr>>(self, fill_value: E) -> Self
pub fn fill_nan<E: Into<Expr>>(self, fill_value: E) -> Self
Replace the floating point NaN
values by a value.
Sourcepub fn count(self) -> Self
pub fn count(self) -> Self
Count the values of the Series or Get counts of the group by operation.
pub fn len(self) -> Self
Sourcepub fn is_duplicated(self) -> Self
Available on crate feature is_unique
only.
pub fn is_duplicated(self) -> Self
is_unique
only.Get a mask of duplicated values.
Sourcepub fn is_unique(self) -> Self
Available on crate feature is_unique
only.
pub fn is_unique(self) -> Self
is_unique
only.Get a mask of unique values.
Sourcepub fn approx_n_unique(self) -> Self
Available on crate feature approx_unique
only.
pub fn approx_n_unique(self) -> Self
approx_unique
only.Get the approximate count of unique values.
Sourcepub fn logical_or<E: Into<Expr>>(self, expr: E) -> Self
pub fn logical_or<E: Into<Expr>>(self, expr: E) -> Self
Logical “or” operation.
Sourcepub fn logical_and<E: Into<Expr>>(self, expr: E) -> Self
pub fn logical_and<E: Into<Expr>>(self, expr: E) -> Self
Logical “and” operation.
Sourcepub fn filter<E: Into<Expr>>(self, predicate: E) -> Self
pub fn filter<E: Into<Expr>>(self, predicate: E) -> Self
Filter a single column.
Should be used in aggregation context. If you want to filter on a
DataFrame level, use LazyFrame::filter
.
Sourcepub fn is_in<E: Into<Expr>>(self, other: E) -> Self
Available on crate feature is_in
only.
pub fn is_in<E: Into<Expr>>(self, other: E) -> Self
is_in
only.Check if the values of the left expression are in the lists of the right expr.
Sourcepub fn sort_by<E: AsRef<[IE]>, IE: Into<Expr> + Clone>(
self,
by: E,
sort_options: SortMultipleOptions,
) -> Expr
pub fn sort_by<E: AsRef<[IE]>, IE: Into<Expr> + Clone>( self, by: E, sort_options: SortMultipleOptions, ) -> Expr
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] }?
);
Sourcepub fn repeat_by<E: Into<Expr>>(self, by: E) -> Expr
Available on crate feature repeat_by
only.
pub fn repeat_by<E: Into<Expr>>(self, by: E) -> Expr
repeat_by
only.Repeat the column n
times, where n
is determined by the values in by
.
This yields an Expr
of dtype List
.
Sourcepub fn is_first_distinct(self) -> Expr
Available on crate feature is_first_distinct
only.
pub fn is_first_distinct(self) -> Expr
is_first_distinct
only.Get a mask of the first unique value.
Sourcepub fn is_last_distinct(self) -> Expr
Available on crate feature is_last_distinct
only.
pub fn is_last_distinct(self) -> Expr
is_last_distinct
only.Get a mask of the last unique value.
Sourcepub fn dot<E: Into<Expr>>(self, other: E) -> Expr
pub fn dot<E: Into<Expr>>(self, other: E) -> Expr
Compute the dot/inner product between two expressions.
Sourcepub fn mode(self) -> Expr
Available on crate feature mode
only.
pub fn mode(self) -> Expr
mode
only.Compute the mode(s) of this column. This is the most occurring value.
Sourcepub fn exclude(self, columns: impl IntoVec<PlSmallStr>) -> Expr
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 $
.
pub fn exclude_dtype<D: AsRef<[DataType]>>(self, dtypes: D) -> Expr
Sourcepub fn interpolate(self, method: InterpolationMethod) -> Expr
Available on crate feature interpolate
only.
pub fn interpolate(self, method: InterpolationMethod) -> Expr
interpolate
only.Fill null values using interpolation.
Sourcepub fn interpolate_by(self, by: Expr) -> Expr
Available on crate feature interpolate_by
only.
pub fn interpolate_by(self, by: Expr) -> Expr
interpolate_by
only.Fill null values using interpolation.
Sourcepub fn rolling_min_by(
self,
by: Expr,
options: RollingOptionsDynamicWindow,
) -> Expr
Available on crate feature rolling_window_by
only.
pub fn rolling_min_by( self, by: Expr, options: RollingOptionsDynamicWindow, ) -> Expr
rolling_window_by
only.Apply a rolling minimum based on another column.
Sourcepub fn rolling_max_by(
self,
by: Expr,
options: RollingOptionsDynamicWindow,
) -> Expr
Available on crate feature rolling_window_by
only.
pub fn rolling_max_by( self, by: Expr, options: RollingOptionsDynamicWindow, ) -> Expr
rolling_window_by
only.Apply a rolling maximum based on another column.
Sourcepub fn rolling_mean_by(
self,
by: Expr,
options: RollingOptionsDynamicWindow,
) -> Expr
Available on crate feature rolling_window_by
only.
pub fn rolling_mean_by( self, by: Expr, options: RollingOptionsDynamicWindow, ) -> Expr
rolling_window_by
only.Apply a rolling mean based on another column.
Sourcepub fn rolling_sum_by(
self,
by: Expr,
options: RollingOptionsDynamicWindow,
) -> Expr
Available on crate feature rolling_window_by
only.
pub fn rolling_sum_by( self, by: Expr, options: RollingOptionsDynamicWindow, ) -> Expr
rolling_window_by
only.Apply a rolling sum based on another column.
Sourcepub fn rolling_quantile_by(
self,
by: Expr,
method: QuantileMethod,
quantile: f64,
options: RollingOptionsDynamicWindow,
) -> Expr
Available on crate feature rolling_window_by
only.
pub fn rolling_quantile_by( self, by: Expr, method: QuantileMethod, quantile: f64, options: RollingOptionsDynamicWindow, ) -> Expr
rolling_window_by
only.Apply a rolling quantile based on another column.
Sourcepub fn rolling_var_by(
self,
by: Expr,
options: RollingOptionsDynamicWindow,
) -> Expr
Available on crate feature rolling_window_by
only.
pub fn rolling_var_by( self, by: Expr, options: RollingOptionsDynamicWindow, ) -> Expr
rolling_window_by
only.Apply a rolling variance based on another column.
Sourcepub fn rolling_std_by(
self,
by: Expr,
options: RollingOptionsDynamicWindow,
) -> Expr
Available on crate feature rolling_window_by
only.
pub fn rolling_std_by( self, by: Expr, options: RollingOptionsDynamicWindow, ) -> Expr
rolling_window_by
only.Apply a rolling std-dev based on another column.
Sourcepub fn rolling_median_by(
self,
by: Expr,
options: RollingOptionsDynamicWindow,
) -> Expr
Available on crate feature rolling_window_by
only.
pub fn rolling_median_by( self, by: Expr, options: RollingOptionsDynamicWindow, ) -> Expr
rolling_window_by
only.Apply a rolling median based on another column.
Sourcepub fn rolling_min(self, options: RollingOptionsFixedWindow) -> Expr
Available on crate feature rolling_window
only.
pub fn rolling_min(self, options: RollingOptionsFixedWindow) -> Expr
rolling_window
only.Apply a rolling minimum.
See: [RollingAgg::rolling_min
]
Sourcepub fn rolling_max(self, options: RollingOptionsFixedWindow) -> Expr
Available on crate feature rolling_window
only.
pub fn rolling_max(self, options: RollingOptionsFixedWindow) -> Expr
rolling_window
only.Apply a rolling maximum.
See: [RollingAgg::rolling_max
]
Sourcepub fn rolling_mean(self, options: RollingOptionsFixedWindow) -> Expr
Available on crate feature rolling_window
only.
pub fn rolling_mean(self, options: RollingOptionsFixedWindow) -> Expr
rolling_window
only.Apply a rolling mean.
See: [RollingAgg::rolling_mean
]
Sourcepub fn rolling_sum(self, options: RollingOptionsFixedWindow) -> Expr
Available on crate feature rolling_window
only.
pub fn rolling_sum(self, options: RollingOptionsFixedWindow) -> Expr
rolling_window
only.Apply a rolling sum.
See: [RollingAgg::rolling_sum
]
Sourcepub fn rolling_median(self, options: RollingOptionsFixedWindow) -> Expr
Available on crate feature rolling_window
only.
pub fn rolling_median(self, options: RollingOptionsFixedWindow) -> Expr
rolling_window
only.Apply a rolling median.
See: [RollingAgg::rolling_median
]
Sourcepub fn rolling_quantile(
self,
method: QuantileMethod,
quantile: f64,
options: RollingOptionsFixedWindow,
) -> Expr
Available on crate feature rolling_window
only.
pub fn rolling_quantile( self, method: QuantileMethod, quantile: f64, options: RollingOptionsFixedWindow, ) -> Expr
rolling_window
only.Apply a rolling quantile.
See: [RollingAgg::rolling_quantile
]
Sourcepub fn rolling_var(self, options: RollingOptionsFixedWindow) -> Expr
Available on crate feature rolling_window
only.
pub fn rolling_var(self, options: RollingOptionsFixedWindow) -> Expr
rolling_window
only.Apply a rolling variance.
Sourcepub fn rolling_std(self, options: RollingOptionsFixedWindow) -> Expr
Available on crate feature rolling_window
only.
pub fn rolling_std(self, options: RollingOptionsFixedWindow) -> Expr
rolling_window
only.Apply a rolling std-dev.
Sourcepub fn rolling_skew(self, window_size: usize, bias: bool) -> Expr
Available on crate features rolling_window
and moment
only.
pub fn rolling_skew(self, window_size: usize, bias: bool) -> Expr
rolling_window
and moment
only.Apply a rolling skew.
Sourcepub fn rolling_map(
self,
f: Arc<dyn Fn(&Series) -> Series + Send + Sync>,
output_type: GetOutput,
options: RollingOptionsFixedWindow,
) -> Expr
Available on crate feature rolling_window
only.
pub fn rolling_map( self, f: Arc<dyn Fn(&Series) -> Series + Send + Sync>, output_type: GetOutput, options: RollingOptionsFixedWindow, ) -> 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.
Sourcepub fn rolling_map_float<F>(self, window_size: usize, f: F) -> Expr
Available on crate feature rolling_window
only.
pub fn rolling_map_float<F>(self, window_size: usize, f: F) -> Expr
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.
pub fn peak_min(self) -> Expr
peaks
only.pub fn peak_max(self) -> Expr
peaks
only.Sourcepub fn rank(self, options: RankOptions, seed: Option<u64>) -> Expr
Available on crate feature rank
only.
pub fn rank(self, options: RankOptions, seed: Option<u64>) -> Expr
rank
only.Assign ranks to data, dealing with ties appropriately.
Sourcepub fn replace<E: Into<Expr>>(self, old: E, new: E) -> Expr
Available on crate feature replace
only.
pub fn replace<E: Into<Expr>>(self, old: E, new: E) -> Expr
replace
only.Replace the given values with other values.
Sourcepub fn replace_strict<E: Into<Expr>>(
self,
old: E,
new: E,
default: Option<E>,
return_dtype: Option<DataType>,
) -> Expr
Available on crate feature replace
only.
pub fn replace_strict<E: Into<Expr>>( self, old: E, new: E, default: Option<E>, return_dtype: Option<DataType>, ) -> Expr
replace
only.Replace the given values with other values.
Sourcepub fn cut(
self,
breaks: Vec<f64>,
labels: Option<impl IntoVec<PlSmallStr>>,
left_closed: bool,
include_breaks: bool,
) -> Expr
Available on crate feature cutqcut
only.
pub fn cut( self, breaks: Vec<f64>, labels: Option<impl IntoVec<PlSmallStr>>, left_closed: bool, include_breaks: bool, ) -> Expr
cutqcut
only.Bin continuous values into discrete categories.
Sourcepub 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.
pub fn qcut( self, probs: Vec<f64>, labels: Option<impl IntoVec<PlSmallStr>>, left_closed: bool, allow_duplicates: bool, include_breaks: bool, ) -> Expr
cutqcut
only.Bin continuous values into discrete categories based on their quantiles.
Sourcepub 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.
pub fn qcut_uniform( self, n_bins: usize, labels: Option<impl IntoVec<PlSmallStr>>, left_closed: bool, allow_duplicates: bool, include_breaks: bool, ) -> Expr
cutqcut
only.Bin continuous values into discrete categories using uniform quantile probabilities.
Sourcepub fn rle(self) -> Expr
Available on crate feature rle
only.
pub fn rle(self) -> Expr
rle
only.Get the lengths of runs of identical values.
Sourcepub fn rle_id(self) -> Expr
Available on crate feature rle
only.
pub fn rle_id(self) -> Expr
rle
only.Similar to rle
, but maps values to run IDs.
Sourcepub fn diff(self, n: i64, null_behavior: NullBehavior) -> Expr
Available on crate feature diff
only.
pub fn diff(self, n: i64, null_behavior: NullBehavior) -> Expr
diff
only.Calculate the n-th discrete difference between values.
Sourcepub fn pct_change(self, n: Expr) -> Expr
Available on crate feature pct_change
only.
pub fn pct_change(self, n: Expr) -> Expr
pct_change
only.Computes percentage change between values.
Sourcepub fn skew(self, bias: bool) -> Expr
Available on crate feature moment
only.
pub fn skew(self, bias: bool) -> Expr
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
Sourcepub fn kurtosis(self, fisher: bool, bias: bool) -> Expr
Available on crate feature moment
only.
pub fn kurtosis(self, fisher: bool, bias: bool) -> Expr
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.
Sourcepub fn upper_bound(self) -> Expr
pub fn upper_bound(self) -> Expr
Get maximal value that could be hold by this dtype.
Sourcepub fn lower_bound(self) -> Expr
pub fn lower_bound(self) -> Expr
Get minimal value that could be hold by this dtype.
pub fn reshape(self, dimensions: &[i64]) -> Self
dtype-array
only.Sourcepub fn ewm_mean(self, options: EWMOptions) -> Self
Available on crate feature ewma
only.
pub fn ewm_mean(self, options: EWMOptions) -> Self
ewma
only.Calculate the exponentially-weighted moving average.
Sourcepub fn ewm_mean_by(self, times: Expr, half_life: Duration) -> Self
Available on crate feature ewma_by
only.
pub fn ewm_mean_by(self, times: Expr, half_life: Duration) -> Self
ewma_by
only.Calculate the exponentially-weighted moving average by a time column.
Sourcepub fn ewm_std(self, options: EWMOptions) -> Self
Available on crate feature ewma
only.
pub fn ewm_std(self, options: EWMOptions) -> Self
ewma
only.Calculate the exponentially-weighted moving standard deviation.
Sourcepub fn ewm_var(self, options: EWMOptions) -> Self
Available on crate feature ewma
only.
pub fn ewm_var(self, options: EWMOptions) -> Self
ewma
only.Calculate the exponentially-weighted moving variance.
Sourcepub fn any(self, ignore_nulls: bool) -> Self
pub fn any(self, ignore_nulls: bool) -> Self
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.
Sourcepub fn all(self, ignore_nulls: bool) -> Self
pub fn all(self, ignore_nulls: bool) -> Self
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.
Sourcepub fn shrink_dtype(self) -> Self
pub fn shrink_dtype(self) -> Self
Shrink numeric columns to the minimal required datatype
needed to fit the extrema of this Series
.
This can be used to reduce memory pressure.
Sourcepub fn value_counts(
self,
sort: bool,
parallel: bool,
name: &str,
normalize: bool,
) -> Self
Available on crate feature dtype-struct
only.
pub fn value_counts( self, sort: bool, parallel: bool, name: &str, normalize: bool, ) -> Self
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
.
Sourcepub fn unique_counts(self) -> Self
Available on crate feature unique_counts
only.
pub fn unique_counts(self) -> Self
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.
Sourcepub fn log(self, base: f64) -> Self
Available on crate feature log
only.
pub fn log(self, base: f64) -> Self
log
only.Compute the logarithm to a given base.
Sourcepub fn log1p(self) -> Self
Available on crate feature log
only.
pub fn log1p(self) -> Self
log
only.Compute the natural logarithm of all elements plus one in the input array.
Sourcepub fn exp(self) -> Self
Available on crate feature log
only.
pub fn exp(self) -> Self
log
only.Calculate the exponential of all elements in the input array.
Sourcepub fn entropy(self, base: f64, normalize: bool) -> Self
Available on crate feature log
only.
pub fn entropy(self, base: f64, normalize: bool) -> Self
log
only.Compute the entropy as -sum(pk * log(pk)
.
where pk
are discrete probabilities.
Sourcepub fn null_count(self) -> Expr
pub fn null_count(self) -> Expr
Get the null count of the column/group.
Sourcepub fn set_sorted_flag(self, sorted: IsSorted) -> Expr
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!
Sourcepub fn hash(self, k0: u64, k1: u64, k2: u64, k3: u64) -> Expr
Available on crate feature row_hash
only.
pub fn hash(self, k0: u64, k1: u64, k2: u64, k3: u64) -> Expr
row_hash
only.Compute the hash of every element.
pub fn to_physical(self) -> Expr
pub fn gather_every(self, n: usize, offset: usize) -> Expr
pub fn extend_constant(self, value: Expr, n: Expr) -> Expr
Sourcepub fn str(self) -> StringNameSpace
Available on crate feature strings
only.
pub fn str(self) -> StringNameSpace
strings
only.Get the string::StringNameSpace
Sourcepub fn binary(self) -> BinaryNameSpace
pub fn binary(self) -> BinaryNameSpace
Get the binary::BinaryNameSpace
Sourcepub fn dt(self) -> DateLikeNameSpace
Available on crate feature temporal
only.
pub fn dt(self) -> DateLikeNameSpace
temporal
only.Get the dt::DateLikeNameSpace
Sourcepub fn list(self) -> ListNameSpace
pub fn list(self) -> ListNameSpace
Get the list::ListNameSpace
Sourcepub fn name(self) -> ExprNameNameSpace
pub fn name(self) -> ExprNameNameSpace
Get the name::ExprNameNameSpace
Sourcepub fn arr(self) -> ArrayNameSpace
Available on crate feature dtype-array
only.
pub fn arr(self) -> ArrayNameSpace
dtype-array
only.Get the array::ArrayNameSpace
.
Sourcepub fn cat(self) -> CategoricalNameSpace
Available on crate feature dtype-categorical
only.
pub fn cat(self) -> CategoricalNameSpace
dtype-categorical
only.Get the CategoricalNameSpace
.
Sourcepub fn struct_(self) -> StructNameSpace
Available on crate feature dtype-struct
only.
pub fn struct_(self) -> StructNameSpace
dtype-struct
only.Get the struct_::StructNameSpace
.
Sourcepub fn meta(self) -> MetaNameSpace
Available on crate feature meta
only.
pub fn meta(self) -> MetaNameSpace
meta
only.Get the meta::MetaNameSpace
Source§impl Expr
impl Expr
pub fn nodes<'a>(&'a self, container: &mut UnitVec<&'a Expr>)
pub fn nodes_owned(self, container: &mut UnitVec<Expr>)
pub fn map_expr<F: FnMut(Self) -> Self>(self, f: F) -> Self
pub fn try_map_expr<F: FnMut(Self) -> PolarsResult<Self>>( self, f: F, ) -> PolarsResult<Self>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Expr
impl<'de> Deserialize<'de> for Expr
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<'a> IntoIterator for &'a Expr
impl<'a> IntoIterator for &'a Expr
Source§impl TreeWalker for Expr
impl TreeWalker for Expr
type Arena = ()
fn apply_children<F: FnMut(&Self, &Self::Arena) -> PolarsResult<VisitRecursion>>( &self, op: &mut F, arena: &Self::Arena, ) -> PolarsResult<VisitRecursion>
fn map_children<F: FnMut(Self, &mut Self::Arena) -> PolarsResult<Self>>( self, f: &mut F, _arena: &mut Self::Arena, ) -> PolarsResult<Self>
Source§fn visit<V: Visitor<Node = Self, Arena = Self::Arena>>(
&self,
visitor: &mut V,
arena: &Self::Arena,
) -> PolarsResult<VisitRecursion>
fn visit<V: Visitor<Node = Self, Arena = Self::Arena>>( &self, visitor: &mut V, arena: &Self::Arena, ) -> PolarsResult<VisitRecursion>
fn rewrite<R: RewritingVisitor<Node = Self, Arena = Self::Arena>>( self, rewriter: &mut R, arena: &mut Self::Arena, ) -> PolarsResult<Self>
impl Eq for Expr
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string()
Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString
. Read more