Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-plan/src/dsl/function_expr/array.rs
6940 views
1
use std::fmt;
2
3
use polars_core::prelude::SortOptions;
4
5
use super::FunctionExpr;
6
7
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
8
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9
#[cfg_attr(feature = "dsl-schema", derive(schemars::JsonSchema))]
10
pub enum ArrayFunction {
11
Length,
12
Slice(i64, i64),
13
Min,
14
Max,
15
Sum,
16
ToList,
17
Unique(bool),
18
NUnique,
19
Std(u8),
20
Var(u8),
21
Mean,
22
Median,
23
#[cfg(feature = "array_any_all")]
24
Any,
25
#[cfg(feature = "array_any_all")]
26
All,
27
Sort(SortOptions),
28
Reverse,
29
ArgMin,
30
ArgMax,
31
Get(bool),
32
Join(bool),
33
#[cfg(feature = "is_in")]
34
Contains {
35
nulls_equal: bool,
36
},
37
#[cfg(feature = "array_count")]
38
CountMatches,
39
Shift,
40
Explode {
41
skip_empty: bool,
42
},
43
Concat,
44
#[cfg(feature = "array_to_struct")]
45
ToStruct(Option<super::DslNameGenerator>),
46
}
47
48
impl fmt::Display for ArrayFunction {
49
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
50
use ArrayFunction::*;
51
let name = match self {
52
Concat => "concat",
53
Length => "length",
54
Slice(_, _) => "slice",
55
Min => "min",
56
Max => "max",
57
Sum => "sum",
58
ToList => "to_list",
59
Unique(_) => "unique",
60
NUnique => "n_unique",
61
Std(_) => "std",
62
Var(_) => "var",
63
Mean => "mean",
64
Median => "median",
65
#[cfg(feature = "array_any_all")]
66
Any => "any",
67
#[cfg(feature = "array_any_all")]
68
All => "all",
69
Sort(_) => "sort",
70
Reverse => "reverse",
71
ArgMin => "arg_min",
72
ArgMax => "arg_max",
73
Get(_) => "get",
74
Join(_) => "join",
75
#[cfg(feature = "is_in")]
76
Contains { nulls_equal: _ } => "contains",
77
#[cfg(feature = "array_count")]
78
CountMatches => "count_matches",
79
Shift => "shift",
80
Explode { .. } => "explode",
81
#[cfg(feature = "array_to_struct")]
82
ToStruct(_) => "to_struct",
83
};
84
write!(f, "arr.{name}")
85
}
86
}
87
88
impl From<ArrayFunction> for FunctionExpr {
89
fn from(value: ArrayFunction) -> Self {
90
Self::ArrayExpr(value)
91
}
92
}
93
94