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