Path: blob/main/crates/polars-plan/src/dsl/function_expr/list.rs
6940 views
use super::*;12#[derive(Clone, Eq, PartialEq, Hash, Debug)]3#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]4#[cfg_attr(feature = "dsl-schema", derive(schemars::JsonSchema))]5pub enum ListFunction {6Concat,7#[cfg(feature = "is_in")]8Contains {9nulls_equal: bool,10},11#[cfg(feature = "list_drop_nulls")]12DropNulls,13#[cfg(feature = "list_sample")]14Sample {15is_fraction: bool,16with_replacement: bool,17shuffle: bool,18seed: Option<u64>,19},20Slice,21Shift,22Get(bool),23#[cfg(feature = "list_gather")]24Gather(bool),25#[cfg(feature = "list_gather")]26GatherEvery,27#[cfg(feature = "list_count")]28CountMatches,29Sum,30Length,31Max,32Min,33Mean,34Median,35Std(u8),36Var(u8),37ArgMin,38ArgMax,39#[cfg(feature = "diff")]40Diff {41n: i64,42null_behavior: NullBehavior,43},44Sort(SortOptions),45Reverse,46Unique(bool),47NUnique,48#[cfg(feature = "list_sets")]49SetOperation(SetOperation),50#[cfg(feature = "list_any_all")]51Any,52#[cfg(feature = "list_any_all")]53All,54Join(bool),55#[cfg(feature = "dtype-array")]56ToArray(usize),57#[cfg(feature = "list_to_struct")]58ToStruct(Arc<[PlSmallStr]>),59}6061impl Display for ListFunction {62fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {63use ListFunction::*;6465let name = match self {66Concat => "concat",67#[cfg(feature = "is_in")]68Contains { nulls_equal: _ } => "contains",69#[cfg(feature = "list_drop_nulls")]70DropNulls => "drop_nulls",71#[cfg(feature = "list_sample")]72Sample { is_fraction, .. } => {73if *is_fraction {74"sample_fraction"75} else {76"sample_n"77}78},79Slice => "slice",80Shift => "shift",81Get(_) => "get",82#[cfg(feature = "list_gather")]83Gather(_) => "gather",84#[cfg(feature = "list_gather")]85GatherEvery => "gather_every",86#[cfg(feature = "list_count")]87CountMatches => "count_matches",88Sum => "sum",89Min => "min",90Max => "max",91Mean => "mean",92Median => "median",93Std(_) => "std",94Var(_) => "var",95ArgMin => "arg_min",96ArgMax => "arg_max",97#[cfg(feature = "diff")]98Diff { .. } => "diff",99Length => "length",100Sort(_) => "sort",101Reverse => "reverse",102Unique(is_stable) => {103if *is_stable {104"unique_stable"105} else {106"unique"107}108},109NUnique => "n_unique",110#[cfg(feature = "list_sets")]111SetOperation(s) => return write!(f, "list.{s}"),112#[cfg(feature = "list_any_all")]113Any => "any",114#[cfg(feature = "list_any_all")]115All => "all",116Join(_) => "join",117#[cfg(feature = "dtype-array")]118ToArray(_) => "to_array",119#[cfg(feature = "list_to_struct")]120ToStruct(_) => "to_struct",121};122write!(f, "list.{name}")123}124}125126impl From<ListFunction> for FunctionExpr {127fn from(value: ListFunction) -> Self {128Self::ListExpr(value)129}130}131132133