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/cat.rs
6940 views
1
use super::*;
2
3
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4
#[cfg_attr(feature = "dsl-schema", derive(schemars::JsonSchema))]
5
#[derive(Clone, PartialEq, Debug, Eq, Hash)]
6
pub enum CategoricalFunction {
7
GetCategories,
8
#[cfg(feature = "strings")]
9
LenBytes,
10
#[cfg(feature = "strings")]
11
LenChars,
12
#[cfg(feature = "strings")]
13
StartsWith(String),
14
#[cfg(feature = "strings")]
15
EndsWith(String),
16
#[cfg(feature = "strings")]
17
Slice(i64, Option<usize>),
18
}
19
20
impl Display for CategoricalFunction {
21
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
22
use CategoricalFunction::*;
23
let s = match self {
24
GetCategories => "get_categories",
25
#[cfg(feature = "strings")]
26
LenBytes => "len_bytes",
27
#[cfg(feature = "strings")]
28
LenChars => "len_chars",
29
#[cfg(feature = "strings")]
30
StartsWith(_) => "starts_with",
31
#[cfg(feature = "strings")]
32
EndsWith(_) => "ends_with",
33
#[cfg(feature = "strings")]
34
Slice(_, _) => "slice",
35
};
36
write!(f, "cat.{s}")
37
}
38
}
39
40
impl From<CategoricalFunction> for FunctionExpr {
41
fn from(func: CategoricalFunction) -> Self {
42
FunctionExpr::Categorical(func)
43
}
44
}
45
46