Path: blob/main/crates/polars-plan/src/dsl/functions/syntactic_sugar.rs
6940 views
use polars_core::chunked_array::cast::CastOptions;12use super::*;34/// Sum all the values in the column named `name`. Shorthand for `col(name).sum()`.5pub fn sum(name: &str) -> Expr {6col(name).sum()7}89/// Find the minimum of all the values in the column named `name`. Shorthand for `col(name).min()`.10pub fn min(name: &str) -> Expr {11col(name).min()12}1314/// Find the maximum of all the values in the column named `name`. Shorthand for `col(name).max()`.15pub fn max(name: &str) -> Expr {16col(name).max()17}1819/// Find the mean of all the values in the column named `name`. Shorthand for `col(name).mean()`.20pub fn mean(name: &str) -> Expr {21col(name).mean()22}2324/// Find the mean of all the values in the column named `name`. Alias for [`mean`].25pub fn avg(name: &str) -> Expr {26col(name).mean()27}2829/// Find the median of all the values in the column named `name`. Shorthand for `col(name).median()`.30pub fn median(name: &str) -> Expr {31col(name).median()32}3334/// Find a specific quantile of all the values in the column named `name`.35pub fn quantile(name: &str, quantile: Expr, method: QuantileMethod) -> Expr {36col(name).quantile(quantile, method)37}3839/// Negates a boolean column.40pub fn not(expr: Expr) -> Expr {41expr.not()42}4344/// A column which is `true` wherever `expr` is null, `false` elsewhere.45pub fn is_null(expr: Expr) -> Expr {46expr.is_null()47}4849/// A column which is `false` wherever `expr` is null, `true` elsewhere.50pub fn is_not_null(expr: Expr) -> Expr {51expr.is_not_null()52}5354/// Casts the column given by `Expr` to a different type.55///56/// Follows the rules of Rust casting, with the exception that integers and floats can be cast to `DataType::Date` and57/// `DataType::DateTime(_, _)`. A column consisting entirely of `Null` can be cast to any type, regardless of the58/// nominal type of the column.59pub fn cast(expr: Expr, dtype: impl Into<DataTypeExpr>) -> Expr {60Expr::Cast {61expr: Arc::new(expr),62dtype: dtype.into(),63options: CastOptions::NonStrict,64}65}666768