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
8353 views
1
use std::fmt;
2
3
use polars_core::prelude::{ExplodeOptions, 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(ExplodeOptions),
41
Concat,
42
#[cfg(feature = "array_to_struct")]
43
ToStruct(Option<super::DslNameGenerator>),
44
}
45
46
impl fmt::Display for ArrayFunction {
47
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
48
use ArrayFunction::*;
49
let name = match self {
50
Concat => "concat",
51
Length => "length",
52
Slice(_, _) => "slice",
53
Min => "min",
54
Max => "max",
55
Sum => "sum",
56
ToList => "to_list",
57
Unique(_) => "unique",
58
NUnique => "n_unique",
59
Std(_) => "std",
60
Var(_) => "var",
61
Mean => "mean",
62
Median => "median",
63
#[cfg(feature = "array_any_all")]
64
Any => "any",
65
#[cfg(feature = "array_any_all")]
66
All => "all",
67
Sort(_) => "sort",
68
Reverse => "reverse",
69
ArgMin => "arg_min",
70
ArgMax => "arg_max",
71
Get(_) => "get",
72
Join(_) => "join",
73
#[cfg(feature = "is_in")]
74
Contains { nulls_equal: _ } => "contains",
75
#[cfg(feature = "array_count")]
76
CountMatches => "count_matches",
77
Shift => "shift",
78
Explode { .. } => "explode",
79
#[cfg(feature = "array_to_struct")]
80
ToStruct(_) => "to_struct",
81
};
82
write!(f, "arr.{name}")
83
}
84
}
85
86
impl From<ArrayFunction> for FunctionExpr {
87
fn from(value: ArrayFunction) -> Self {
88
Self::ArrayExpr(value)
89
}
90
}
91
92