Path: blob/main/crates/polars-plan/src/plans/aexpr/function_expr/cat.rs
7889 views
use super::*;12#[cfg_attr(feature = "ir_serde", derive(serde::Serialize, serde::Deserialize))]3#[derive(Clone, PartialEq, Debug, Eq, Hash)]4pub enum IRCategoricalFunction {5GetCategories,6#[cfg(feature = "strings")]7LenBytes,8#[cfg(feature = "strings")]9LenChars,10#[cfg(feature = "strings")]11StartsWith(String),12#[cfg(feature = "strings")]13EndsWith(String),14#[cfg(feature = "strings")]15Slice(i64, Option<usize>),16}1718impl IRCategoricalFunction {19pub(super) fn get_field(&self, mapper: FieldsMapper) -> PolarsResult<Field> {20use IRCategoricalFunction::*;21match self {22GetCategories => mapper.with_dtype(DataType::String),23#[cfg(feature = "strings")]24LenBytes => mapper.with_dtype(DataType::UInt32),25#[cfg(feature = "strings")]26LenChars => mapper.with_dtype(DataType::UInt32),27#[cfg(feature = "strings")]28StartsWith(_) => mapper.with_dtype(DataType::Boolean),29#[cfg(feature = "strings")]30EndsWith(_) => mapper.with_dtype(DataType::Boolean),31#[cfg(feature = "strings")]32Slice(_, _) => mapper.with_dtype(DataType::String),33}34}3536pub fn function_options(&self) -> FunctionOptions {37use IRCategoricalFunction as C;38match self {39C::GetCategories => FunctionOptions::groupwise(),40#[cfg(feature = "strings")]41C::LenBytes | C::LenChars | C::StartsWith(_) | C::EndsWith(_) | C::Slice(_, _) => {42FunctionOptions::elementwise()43},44}45}46}4748impl Display for IRCategoricalFunction {49fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {50use IRCategoricalFunction::*;51let s = match self {52GetCategories => "get_categories",53#[cfg(feature = "strings")]54LenBytes => "len_bytes",55#[cfg(feature = "strings")]56LenChars => "len_chars",57#[cfg(feature = "strings")]58StartsWith(_) => "starts_with",59#[cfg(feature = "strings")]60EndsWith(_) => "ends_with",61#[cfg(feature = "strings")]62Slice(_, _) => "slice",63};64write!(f, "cat.{s}")65}66}6768impl From<IRCategoricalFunction> for IRFunctionExpr {69fn from(func: IRCategoricalFunction) -> Self {70IRFunctionExpr::Categorical(func)71}72}737475