Path: blob/main/crates/polars-plan/src/plans/aexpr/function_expr/business.rs
7889 views
use std::fmt::{Display, Formatter};12use polars_core::prelude::*;3use polars_ops::prelude::Roll;45use super::FunctionOptions;6use crate::plans::aexpr::function_expr::FieldsMapper;7use crate::prelude::FunctionFlags;89#[cfg_attr(feature = "ir_serde", derive(serde::Serialize, serde::Deserialize))]10#[derive(Clone, PartialEq, Debug, Eq, Hash)]11pub enum IRBusinessFunction {12BusinessDayCount {13week_mask: [bool; 7],14holidays: Vec<i32>,15},16AddBusinessDay {17week_mask: [bool; 7],18holidays: Vec<i32>,19roll: Roll,20},21IsBusinessDay {22week_mask: [bool; 7],23holidays: Vec<i32>,24},25}2627impl IRBusinessFunction {28pub fn get_field(&self, mapper: FieldsMapper) -> PolarsResult<Field> {29match self {30Self::BusinessDayCount { .. } => mapper.with_dtype(DataType::Int32),31Self::AddBusinessDay { .. } => mapper.with_same_dtype(),32Self::IsBusinessDay { .. } => mapper.with_dtype(DataType::Boolean),33}34}35pub fn function_options(&self) -> FunctionOptions {36use IRBusinessFunction as B;37match self {38B::BusinessDayCount { .. } => {39FunctionOptions::elementwise().with_flags(|f| f | FunctionFlags::ALLOW_RENAME)40},41B::AddBusinessDay { .. } | B::IsBusinessDay { .. } => FunctionOptions::elementwise(),42}43}44}4546impl Display for IRBusinessFunction {47fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {48use IRBusinessFunction::*;49let s = match self {50BusinessDayCount { .. } => "business_day_count",51AddBusinessDay { .. } => "add_business_days",52IsBusinessDay { .. } => "is_business_day",53};54write!(f, "{s}")55}56}575859