Path: blob/main/crates/polars-plan/src/dsl/functions/mod.rs
8427 views
//! # Functions1//!2//! Functions on expressions that might be useful.3#[cfg(feature = "business")]4mod business;5#[cfg(feature = "dtype-struct")]6mod coerce;7mod concat;8#[cfg(feature = "cov")]9mod correlation;10pub(crate) mod horizontal;11#[cfg(any(feature = "range", feature = "arg_where"))]12mod index;13#[cfg(feature = "range")]14mod range;15mod repeat;16mod selectors;17mod syntactic_sugar;18#[cfg(feature = "temporal")]19mod temporal;2021pub use arity::*;22#[cfg(all(feature = "business", feature = "dtype-date"))]23pub use business::business_day_count;24#[cfg(feature = "dtype-struct")]25pub use coerce::*;26pub use concat::*;27#[cfg(feature = "cov")]28pub use correlation::*;29pub use horizontal::{30all_horizontal, any_horizontal, coalesce, fold_exprs, max_horizontal, mean_horizontal,31min_horizontal, reduce_exprs, sum_horizontal,32};33#[cfg(feature = "dtype-struct")]34pub use horizontal::{cum_fold_exprs, cum_reduce_exprs};35#[cfg(any(feature = "range", feature = "arg_where"))]36pub use index::*;37#[cfg(all(38feature = "range",39any(feature = "dtype-date", feature = "dtype-datetime")40))]41pub use range::date_range; // This shouldn't be necessary, but clippy complains about dead code42#[cfg(all(feature = "range", feature = "dtype-time"))]43pub use range::time_range; // This shouldn't be necessary, but clippy complains about dead code44#[cfg(feature = "range")]45pub use range::*;46pub use repeat::*;47pub use selectors::*;48pub use syntactic_sugar::*;49#[cfg(feature = "temporal")]50pub use temporal::*;5152#[cfg(feature = "arg_where")]53use crate::dsl::function_expr::FunctionExpr;54use crate::dsl::function_expr::ListFunction;55#[cfg(all(feature = "concat_str", feature = "strings"))]56use crate::dsl::function_expr::StringFunction;57use crate::dsl::*;5859/// Return the number of rows in the context.60pub fn len() -> Expr {61Expr::Len62}6364/// First column in a DataFrame.65pub fn first() -> Selector {66nth(0)67}6869/// Last column in a DataFrame.70pub fn last() -> Selector {71nth(-1)72}7374/// Nth column in a DataFrame.75pub fn nth(n: i64) -> Selector {76Selector::ByIndex {77indices: [n].into(),78strict: true,79}80}8182/// Create a Literal Expression from `L`. A literal expression behaves like a column that contains a single distinct83/// value.84///85/// The column is automatically of the "correct" length to make the operations work. Often this is determined by the86/// length of the `LazyFrame` it is being used with. For instance, `lazy_df.with_column(lit(5).alias("five"))` creates a87/// new column named "five" that is the length of the Dataframe (at the time `collect` is called), where every value in88/// the column is `5`.89pub fn lit<L: Literal>(t: L) -> Expr {90t.lit()91}929394