Path: blob/main/crates/polars-plan/src/plans/aexpr/function_expr/mod.rs
8383 views
#[cfg(feature = "dtype-array")]1mod array;2mod binary;3#[cfg(feature = "bitwise")]4mod bitwise;5mod boolean;6#[cfg(feature = "business")]7mod business;8#[cfg(feature = "dtype-categorical")]9mod cat;10#[cfg(feature = "cov")]11mod correlation;12#[cfg(feature = "cum_agg")]13mod cum;14#[cfg(feature = "temporal")]15mod datetime;16#[cfg(feature = "dtype-extension")]17mod extension;18#[cfg(feature = "fused")]19mod fused;20mod list;21#[cfg(feature = "ffi_plugin")]22pub mod plugin;23mod pow;24#[cfg(feature = "random")]25mod random;26#[cfg(feature = "range")]27mod range;28#[cfg(feature = "rolling_window")]29mod rolling;30#[cfg(feature = "rolling_window_by")]31mod rolling_by;32mod row_encode;33pub(super) mod schema;34#[cfg(feature = "strings")]35mod strings;36#[cfg(feature = "dtype-struct")]37mod struct_;38#[cfg(feature = "trigonometry")]39mod trigonometry;4041use std::fmt::{Display, Formatter};42use std::hash::{Hash, Hasher};4344#[cfg(feature = "dtype-array")]45pub use array::IRArrayFunction;46#[cfg(feature = "cov")]47pub use correlation::IRCorrelationMethod;48#[cfg(feature = "fused")]49pub use fused::FusedOperator;50pub use list::IRListFunction;51pub use polars_core::datatypes::ReshapeDimension;52use polars_core::prelude::*;53use polars_core::series::IsSorted;54use polars_core::series::ops::NullBehavior;55use polars_core::utils::SuperTypeFlags;56#[cfg(feature = "random")]57pub use random::IRRandomMethod;58use schema::FieldsMapper;5960pub use self::binary::IRBinaryFunction;61#[cfg(feature = "bitwise")]62pub use self::bitwise::IRBitwiseFunction;63pub use self::boolean::IRBooleanFunction;64#[cfg(feature = "business")]65pub use self::business::IRBusinessFunction;66#[cfg(feature = "dtype-categorical")]67pub use self::cat::IRCategoricalFunction;68#[cfg(feature = "temporal")]69pub use self::datetime::IRTemporalFunction;70#[cfg(feature = "dtype-extension")]71pub use self::extension::IRExtensionFunction;72pub use self::pow::IRPowFunction;73#[cfg(feature = "range")]74pub use self::range::IRRangeFunction;75#[cfg(feature = "rolling_window")]76pub use self::rolling::IRRollingFunction;77#[cfg(feature = "rolling_window_by")]78pub use self::rolling_by::IRRollingFunctionBy;79pub use self::row_encode::RowEncodingVariant;80#[cfg(feature = "strings")]81pub use self::strings::IRStringFunction;82#[cfg(all(feature = "strings", feature = "regex", feature = "timezones"))]83pub use self::strings::TZ_AWARE_RE;84#[cfg(feature = "dtype-struct")]85pub use self::struct_::IRStructFunction;86#[cfg(feature = "trigonometry")]87pub use self::trigonometry::IRTrigonometricFunction;88use super::*;8990#[cfg_attr(feature = "ir_serde", derive(serde::Serialize, serde::Deserialize))]91#[derive(Clone, PartialEq, Debug)]92pub enum IRFunctionExpr {93// Namespaces94#[cfg(feature = "dtype-array")]95ArrayExpr(IRArrayFunction),96BinaryExpr(IRBinaryFunction),97#[cfg(feature = "dtype-categorical")]98Categorical(IRCategoricalFunction),99#[cfg(feature = "dtype-extension")]100Extension(IRExtensionFunction),101ListExpr(IRListFunction),102#[cfg(feature = "strings")]103StringExpr(IRStringFunction),104#[cfg(feature = "dtype-struct")]105StructExpr(IRStructFunction),106#[cfg(feature = "temporal")]107TemporalExpr(IRTemporalFunction),108#[cfg(feature = "bitwise")]109Bitwise(IRBitwiseFunction),110111// Other expressions112Boolean(IRBooleanFunction),113#[cfg(feature = "business")]114Business(IRBusinessFunction),115#[cfg(feature = "abs")]116Abs,117Negate,118#[cfg(feature = "hist")]119Hist {120bin_count: Option<usize>,121include_category: bool,122include_breakpoint: bool,123},124NullCount,125Pow(IRPowFunction),126#[cfg(feature = "row_hash")]127Hash(u64, u64, u64, u64),128#[cfg(feature = "arg_where")]129ArgWhere,130#[cfg(feature = "index_of")]131IndexOf,132#[cfg(feature = "search_sorted")]133SearchSorted {134side: SearchSortedSide,135descending: bool,136},137#[cfg(feature = "range")]138Range(IRRangeFunction),139#[cfg(feature = "trigonometry")]140Trigonometry(IRTrigonometricFunction),141#[cfg(feature = "trigonometry")]142Atan2,143#[cfg(feature = "sign")]144Sign,145FillNull,146FillNullWithStrategy(FillNullStrategy),147#[cfg(feature = "rolling_window")]148RollingExpr {149function: IRRollingFunction,150options: RollingOptionsFixedWindow,151},152#[cfg(feature = "rolling_window_by")]153RollingExprBy {154function_by: IRRollingFunctionBy,155options: RollingOptionsDynamicWindow,156},157Rechunk,158Append {159upcast: bool,160},161ShiftAndFill,162Shift,163DropNans,164DropNulls,165#[cfg(feature = "mode")]166Mode {167maintain_order: bool,168},169#[cfg(feature = "moment")]170Skew(bool),171#[cfg(feature = "moment")]172Kurtosis(bool, bool),173#[cfg(feature = "dtype-array")]174Reshape(Vec<ReshapeDimension>),175#[cfg(feature = "repeat_by")]176RepeatBy,177ArgUnique,178ArgMin,179ArgMax,180ArgSort {181descending: bool,182nulls_last: bool,183},184MinBy,185MaxBy,186Product,187#[cfg(feature = "rank")]188Rank {189options: RankOptions,190seed: Option<u64>,191},192Repeat,193#[cfg(feature = "round_series")]194Clip {195has_min: bool,196has_max: bool,197},198#[cfg(feature = "dtype-struct")]199AsStruct,200#[cfg(feature = "top_k")]201TopK {202descending: bool,203},204#[cfg(feature = "top_k")]205TopKBy {206descending: Vec<bool>,207},208#[cfg(feature = "cum_agg")]209CumCount {210reverse: bool,211},212#[cfg(feature = "cum_agg")]213CumSum {214reverse: bool,215},216#[cfg(feature = "cum_agg")]217CumProd {218reverse: bool,219},220#[cfg(feature = "cum_agg")]221CumMin {222reverse: bool,223},224#[cfg(feature = "cum_agg")]225CumMax {226reverse: bool,227},228Reverse,229#[cfg(feature = "dtype-struct")]230ValueCounts {231sort: bool,232parallel: bool,233name: PlSmallStr,234normalize: bool,235},236#[cfg(feature = "unique_counts")]237UniqueCounts,238#[cfg(feature = "approx_unique")]239ApproxNUnique,240Coalesce,241#[cfg(feature = "diff")]242Diff(NullBehavior),243#[cfg(feature = "pct_change")]244PctChange,245#[cfg(feature = "interpolate")]246Interpolate(InterpolationMethod),247#[cfg(feature = "interpolate_by")]248InterpolateBy,249#[cfg(feature = "log")]250Entropy {251base: f64,252normalize: bool,253},254#[cfg(feature = "log")]255Log,256#[cfg(feature = "log")]257Log1p,258#[cfg(feature = "log")]259Exp,260Unique(/* maintain_order */ bool),261#[cfg(feature = "round_series")]262Round {263decimals: u32,264mode: RoundMode,265},266#[cfg(feature = "round_series")]267RoundSF {268digits: i32,269},270#[cfg(feature = "round_series")]271Floor,272#[cfg(feature = "round_series")]273Ceil,274#[cfg(feature = "fused")]275Fused(fused::FusedOperator),276ConcatExpr(bool),277#[cfg(feature = "cov")]278Correlation {279method: correlation::IRCorrelationMethod,280},281#[cfg(feature = "peaks")]282PeakMin,283#[cfg(feature = "peaks")]284PeakMax,285#[cfg(feature = "cutqcut")]286Cut {287breaks: Vec<f64>,288labels: Option<Vec<PlSmallStr>>,289left_closed: bool,290include_breaks: bool,291},292#[cfg(feature = "cutqcut")]293QCut {294probs: Vec<f64>,295labels: Option<Vec<PlSmallStr>>,296left_closed: bool,297allow_duplicates: bool,298include_breaks: bool,299},300#[cfg(feature = "rle")]301RLE,302#[cfg(feature = "rle")]303RLEID,304ToPhysical,305#[cfg(feature = "random")]306Random {307method: IRRandomMethod,308seed: Option<u64>,309},310SetSortedFlag(IsSorted),311#[cfg(feature = "ffi_plugin")]312/// Creating this node is unsafe313/// This will lead to calls over FFI.314FfiPlugin {315flags: FunctionOptions,316/// Shared library.317lib: PlSmallStr,318/// Identifier in the shared lib.319symbol: PlSmallStr,320/// Pickle serialized keyword arguments.321kwargs: Arc<[u8]>,322},323324FoldHorizontal {325callback: PlanCallback<(Series, Series), Series>,326returns_scalar: bool,327return_dtype: Option<DataType>,328},329ReduceHorizontal {330callback: PlanCallback<(Series, Series), Series>,331returns_scalar: bool,332return_dtype: Option<DataType>,333},334#[cfg(feature = "dtype-struct")]335CumReduceHorizontal {336callback: PlanCallback<(Series, Series), Series>,337returns_scalar: bool,338return_dtype: Option<DataType>,339},340#[cfg(feature = "dtype-struct")]341CumFoldHorizontal {342callback: PlanCallback<(Series, Series), Series>,343returns_scalar: bool,344return_dtype: Option<DataType>,345include_init: bool,346},347348MaxHorizontal,349MinHorizontal,350SumHorizontal {351ignore_nulls: bool,352},353MeanHorizontal {354ignore_nulls: bool,355},356#[cfg(feature = "ewma")]357EwmMean {358options: EWMOptions,359},360#[cfg(feature = "ewma_by")]361EwmMeanBy {362half_life: Duration,363},364#[cfg(feature = "ewma")]365EwmStd {366options: EWMOptions,367},368#[cfg(feature = "ewma")]369EwmVar {370options: EWMOptions,371},372#[cfg(feature = "replace")]373Replace,374#[cfg(feature = "replace")]375ReplaceStrict {376return_dtype: Option<DataType>,377},378GatherEvery {379n: usize,380offset: usize,381},382#[cfg(feature = "reinterpret")]383Reinterpret(bool),384ExtendConstant,385386RowEncode(Vec<DataType>, RowEncodingVariant),387#[cfg(feature = "dtype-struct")]388RowDecode(Vec<Field>, RowEncodingVariant),389}390391impl Hash for IRFunctionExpr {392fn hash<H: Hasher>(&self, state: &mut H) {393std::mem::discriminant(self).hash(state);394use IRFunctionExpr::*;395match self {396// Namespaces397#[cfg(feature = "dtype-array")]398ArrayExpr(f) => f.hash(state),399BinaryExpr(f) => f.hash(state),400#[cfg(feature = "dtype-categorical")]401Categorical(f) => f.hash(state),402#[cfg(feature = "dtype-extension")]403Extension(f) => f.hash(state),404ListExpr(f) => f.hash(state),405#[cfg(feature = "strings")]406StringExpr(f) => f.hash(state),407#[cfg(feature = "dtype-struct")]408StructExpr(f) => f.hash(state),409#[cfg(feature = "temporal")]410TemporalExpr(f) => f.hash(state),411#[cfg(feature = "bitwise")]412Bitwise(f) => f.hash(state),413414// Other expressions415Boolean(f) => f.hash(state),416#[cfg(feature = "business")]417Business(f) => f.hash(state),418Pow(f) => f.hash(state),419#[cfg(feature = "index_of")]420IndexOf => {},421#[cfg(feature = "search_sorted")]422SearchSorted { side, descending } => {423side.hash(state);424descending.hash(state);425},426#[cfg(feature = "random")]427Random { method, .. } => method.hash(state),428#[cfg(feature = "cov")]429Correlation { method, .. } => method.hash(state),430#[cfg(feature = "range")]431Range(f) => f.hash(state),432#[cfg(feature = "trigonometry")]433Trigonometry(f) => f.hash(state),434#[cfg(feature = "fused")]435Fused(f) => f.hash(state),436#[cfg(feature = "diff")]437Diff(null_behavior) => null_behavior.hash(state),438#[cfg(feature = "interpolate")]439Interpolate(f) => f.hash(state),440#[cfg(feature = "interpolate_by")]441InterpolateBy => {},442#[cfg(feature = "ffi_plugin")]443FfiPlugin {444flags: _,445lib,446symbol,447kwargs,448} => {449kwargs.hash(state);450lib.hash(state);451symbol.hash(state);452},453454FoldHorizontal {455callback,456returns_scalar,457return_dtype,458}459| ReduceHorizontal {460callback,461returns_scalar,462return_dtype,463} => {464callback.hash(state);465returns_scalar.hash(state);466return_dtype.hash(state);467},468#[cfg(feature = "dtype-struct")]469CumReduceHorizontal {470callback,471returns_scalar,472return_dtype,473} => {474callback.hash(state);475returns_scalar.hash(state);476return_dtype.hash(state);477},478#[cfg(feature = "dtype-struct")]479CumFoldHorizontal {480callback,481returns_scalar,482return_dtype,483include_init,484} => {485callback.hash(state);486returns_scalar.hash(state);487return_dtype.hash(state);488include_init.hash(state);489},490491SumHorizontal { ignore_nulls } | MeanHorizontal { ignore_nulls } => {492ignore_nulls.hash(state)493},494MaxHorizontal | MinHorizontal | DropNans | DropNulls | Reverse | ArgUnique | ArgMin495| ArgMax | Product | Shift | ShiftAndFill | Rechunk | MinBy | MaxBy => {},496Append { upcast } => {497upcast.hash(state);498},499ArgSort {500descending,501nulls_last,502} => {503descending.hash(state);504nulls_last.hash(state);505},506#[cfg(feature = "mode")]507Mode { maintain_order } => {508maintain_order.hash(state);509},510#[cfg(feature = "abs")]511Abs => {},512Negate => {},513NullCount => {},514#[cfg(feature = "arg_where")]515ArgWhere => {},516#[cfg(feature = "trigonometry")]517Atan2 => {},518#[cfg(feature = "dtype-struct")]519AsStruct => {},520#[cfg(feature = "sign")]521Sign => {},522#[cfg(feature = "row_hash")]523Hash(a, b, c, d) => (a, b, c, d).hash(state),524FillNull => {},525#[cfg(feature = "rolling_window")]526RollingExpr { function, options } => {527function.hash(state);528options.hash(state);529},530#[cfg(feature = "rolling_window_by")]531RollingExprBy {532function_by,533options,534} => {535function_by.hash(state);536options.hash(state);537},538#[cfg(feature = "moment")]539Skew(a) => a.hash(state),540#[cfg(feature = "moment")]541Kurtosis(a, b) => {542a.hash(state);543b.hash(state);544},545Repeat => {},546#[cfg(feature = "rank")]547Rank { options, seed } => {548options.hash(state);549seed.hash(state);550},551#[cfg(feature = "round_series")]552Clip { has_min, has_max } => {553has_min.hash(state);554has_max.hash(state);555},556#[cfg(feature = "top_k")]557TopK { descending } => descending.hash(state),558#[cfg(feature = "cum_agg")]559CumCount { reverse } => reverse.hash(state),560#[cfg(feature = "cum_agg")]561CumSum { reverse } => reverse.hash(state),562#[cfg(feature = "cum_agg")]563CumProd { reverse } => reverse.hash(state),564#[cfg(feature = "cum_agg")]565CumMin { reverse } => reverse.hash(state),566#[cfg(feature = "cum_agg")]567CumMax { reverse } => reverse.hash(state),568#[cfg(feature = "dtype-struct")]569ValueCounts {570sort,571parallel,572name,573normalize,574} => {575sort.hash(state);576parallel.hash(state);577name.hash(state);578normalize.hash(state);579},580#[cfg(feature = "unique_counts")]581UniqueCounts => {},582#[cfg(feature = "approx_unique")]583ApproxNUnique => {},584Coalesce => {},585#[cfg(feature = "pct_change")]586PctChange => {},587#[cfg(feature = "log")]588Entropy { base, normalize } => {589base.to_bits().hash(state);590normalize.hash(state);591},592#[cfg(feature = "log")]593Log => {},594#[cfg(feature = "log")]595Log1p => {},596#[cfg(feature = "log")]597Exp => {},598Unique(a) => a.hash(state),599#[cfg(feature = "round_series")]600Round { decimals, mode } => {601decimals.hash(state);602mode.hash(state);603},604#[cfg(feature = "round_series")]605IRFunctionExpr::RoundSF { digits } => digits.hash(state),606#[cfg(feature = "round_series")]607IRFunctionExpr::Floor => {},608#[cfg(feature = "round_series")]609Ceil => {},610ConcatExpr(a) => a.hash(state),611#[cfg(feature = "peaks")]612PeakMin => {},613#[cfg(feature = "peaks")]614PeakMax => {},615#[cfg(feature = "cutqcut")]616Cut {617breaks,618labels,619left_closed,620include_breaks,621} => {622let slice = bytemuck::cast_slice::<_, u64>(breaks);623slice.hash(state);624labels.hash(state);625left_closed.hash(state);626include_breaks.hash(state);627},628#[cfg(feature = "dtype-array")]629Reshape(dims) => dims.hash(state),630#[cfg(feature = "repeat_by")]631RepeatBy => {},632#[cfg(feature = "cutqcut")]633QCut {634probs,635labels,636left_closed,637allow_duplicates,638include_breaks,639} => {640let slice = bytemuck::cast_slice::<_, u64>(probs);641slice.hash(state);642labels.hash(state);643left_closed.hash(state);644allow_duplicates.hash(state);645include_breaks.hash(state);646},647#[cfg(feature = "rle")]648RLE => {},649#[cfg(feature = "rle")]650RLEID => {},651ToPhysical => {},652SetSortedFlag(is_sorted) => is_sorted.hash(state),653#[cfg(feature = "ewma")]654EwmMean { options } => options.hash(state),655#[cfg(feature = "ewma_by")]656EwmMeanBy { half_life } => (half_life).hash(state),657#[cfg(feature = "ewma")]658EwmStd { options } => options.hash(state),659#[cfg(feature = "ewma")]660EwmVar { options } => options.hash(state),661#[cfg(feature = "hist")]662Hist {663bin_count,664include_category,665include_breakpoint,666} => {667bin_count.hash(state);668include_category.hash(state);669include_breakpoint.hash(state);670},671#[cfg(feature = "replace")]672Replace => {},673#[cfg(feature = "replace")]674ReplaceStrict { return_dtype } => return_dtype.hash(state),675FillNullWithStrategy(strategy) => strategy.hash(state),676GatherEvery { n, offset } => (n, offset).hash(state),677#[cfg(feature = "reinterpret")]678Reinterpret(signed) => signed.hash(state),679ExtendConstant => {},680#[cfg(feature = "top_k")]681TopKBy { descending } => descending.hash(state),682683RowEncode(dts, variants) => {684dts.hash(state);685variants.hash(state);686},687#[cfg(feature = "dtype-struct")]688RowDecode(fs, variants) => {689fs.hash(state);690variants.hash(state);691},692}693}694}695696impl Display for IRFunctionExpr {697fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {698use IRFunctionExpr::*;699let s = match self {700// Namespaces701#[cfg(feature = "dtype-array")]702ArrayExpr(func) => return write!(f, "{func}"),703BinaryExpr(func) => return write!(f, "{func}"),704#[cfg(feature = "dtype-categorical")]705Categorical(func) => return write!(f, "{func}"),706#[cfg(feature = "dtype-extension")]707Extension(func) => return write!(f, "{func}"),708ListExpr(func) => return write!(f, "{func}"),709#[cfg(feature = "strings")]710StringExpr(func) => return write!(f, "{func}"),711#[cfg(feature = "dtype-struct")]712StructExpr(func) => return write!(f, "{func}"),713#[cfg(feature = "temporal")]714TemporalExpr(func) => return write!(f, "{func}"),715#[cfg(feature = "bitwise")]716Bitwise(func) => return write!(f, "bitwise_{func}"),717718// Other expressions719Boolean(func) => return write!(f, "{func}"),720#[cfg(feature = "business")]721Business(func) => return write!(f, "{func}"),722#[cfg(feature = "abs")]723Abs => "abs",724Negate => "negate",725NullCount => "null_count",726Pow(func) => return write!(f, "{func}"),727#[cfg(feature = "row_hash")]728Hash(_, _, _, _) => "hash",729#[cfg(feature = "arg_where")]730ArgWhere => "arg_where",731#[cfg(feature = "index_of")]732IndexOf => "index_of",733#[cfg(feature = "search_sorted")]734SearchSorted { .. } => "search_sorted",735#[cfg(feature = "range")]736Range(func) => return write!(f, "{func}"),737#[cfg(feature = "trigonometry")]738Trigonometry(func) => return write!(f, "{func}"),739#[cfg(feature = "trigonometry")]740Atan2 => return write!(f, "arctan2"),741#[cfg(feature = "sign")]742Sign => "sign",743FillNull => "fill_null",744#[cfg(feature = "rolling_window")]745RollingExpr { function, .. } => return write!(f, "{function}"),746#[cfg(feature = "rolling_window_by")]747RollingExprBy { function_by, .. } => return write!(f, "{function_by}"),748Rechunk => "rechunk",749Append { .. } => "append",750ShiftAndFill => "shift_and_fill",751DropNans => "drop_nans",752DropNulls => "drop_nulls",753#[cfg(feature = "mode")]754Mode { maintain_order } => {755if *maintain_order {756"mode_stable"757} else {758"mode"759}760},761#[cfg(feature = "moment")]762Skew(_) => "skew",763#[cfg(feature = "moment")]764Kurtosis(..) => "kurtosis",765ArgUnique => "arg_unique",766ArgMin => "arg_min",767ArgMax => "arg_max",768ArgSort { .. } => "arg_sort",769MinBy => "min_by",770MaxBy => "max_by",771Product => "product",772Repeat => "repeat",773#[cfg(feature = "rank")]774Rank { .. } => "rank",775#[cfg(feature = "round_series")]776Clip { has_min, has_max } => match (has_min, has_max) {777(true, true) => "clip",778(false, true) => "clip_max",779(true, false) => "clip_min",780_ => unreachable!(),781},782#[cfg(feature = "dtype-struct")]783AsStruct => "as_struct",784#[cfg(feature = "top_k")]785TopK { descending } => {786if *descending {787"bottom_k"788} else {789"top_k"790}791},792#[cfg(feature = "top_k")]793TopKBy { .. } => "top_k_by",794Shift => "shift",795#[cfg(feature = "cum_agg")]796CumCount { .. } => "cum_count",797#[cfg(feature = "cum_agg")]798CumSum { .. } => "cum_sum",799#[cfg(feature = "cum_agg")]800CumProd { .. } => "cum_prod",801#[cfg(feature = "cum_agg")]802CumMin { .. } => "cum_min",803#[cfg(feature = "cum_agg")]804CumMax { .. } => "cum_max",805#[cfg(feature = "dtype-struct")]806ValueCounts { .. } => "value_counts",807#[cfg(feature = "unique_counts")]808UniqueCounts => "unique_counts",809Reverse => "reverse",810#[cfg(feature = "approx_unique")]811ApproxNUnique => "approx_n_unique",812Coalesce => "coalesce",813#[cfg(feature = "diff")]814Diff(_) => "diff",815#[cfg(feature = "pct_change")]816PctChange => "pct_change",817#[cfg(feature = "interpolate")]818Interpolate(_) => "interpolate",819#[cfg(feature = "interpolate_by")]820InterpolateBy => "interpolate_by",821#[cfg(feature = "log")]822Entropy { .. } => "entropy",823#[cfg(feature = "log")]824Log => "log",825#[cfg(feature = "log")]826Log1p => "log1p",827#[cfg(feature = "log")]828Exp => "exp",829Unique(stable) => {830if *stable {831"unique_stable"832} else {833"unique"834}835},836#[cfg(feature = "round_series")]837Round { .. } => "round",838#[cfg(feature = "round_series")]839RoundSF { .. } => "round_sig_figs",840#[cfg(feature = "round_series")]841Floor => "floor",842#[cfg(feature = "round_series")]843Ceil => "ceil",844#[cfg(feature = "fused")]845Fused(fused) => return Display::fmt(fused, f),846ConcatExpr(_) => "concat_expr",847#[cfg(feature = "cov")]848Correlation { method, .. } => return Display::fmt(method, f),849#[cfg(feature = "peaks")]850PeakMin => "peak_min",851#[cfg(feature = "peaks")]852PeakMax => "peak_max",853#[cfg(feature = "cutqcut")]854Cut { .. } => "cut",855#[cfg(feature = "cutqcut")]856QCut { .. } => "qcut",857#[cfg(feature = "dtype-array")]858Reshape(_) => "reshape",859#[cfg(feature = "repeat_by")]860RepeatBy => "repeat_by",861#[cfg(feature = "rle")]862RLE => "rle",863#[cfg(feature = "rle")]864RLEID => "rle_id",865ToPhysical => "to_physical",866#[cfg(feature = "random")]867Random { method, .. } => method.into(),868SetSortedFlag(_) => "set_sorted",869#[cfg(feature = "ffi_plugin")]870FfiPlugin { lib, symbol, .. } => return write!(f, "{lib}:{symbol}"),871872FoldHorizontal { .. } => "fold",873ReduceHorizontal { .. } => "reduce",874#[cfg(feature = "dtype-struct")]875CumReduceHorizontal { .. } => "cum_reduce",876#[cfg(feature = "dtype-struct")]877CumFoldHorizontal { .. } => "cum_fold",878879MaxHorizontal => "max_horizontal",880MinHorizontal => "min_horizontal",881SumHorizontal { .. } => "sum_horizontal",882MeanHorizontal { .. } => "mean_horizontal",883#[cfg(feature = "ewma")]884EwmMean { .. } => "ewm_mean",885#[cfg(feature = "ewma_by")]886EwmMeanBy { .. } => "ewm_mean_by",887#[cfg(feature = "ewma")]888EwmStd { .. } => "ewm_std",889#[cfg(feature = "ewma")]890EwmVar { .. } => "ewm_var",891#[cfg(feature = "hist")]892Hist { .. } => "hist",893#[cfg(feature = "replace")]894Replace => "replace",895#[cfg(feature = "replace")]896ReplaceStrict { .. } => "replace_strict",897FillNullWithStrategy(_) => "fill_null_with_strategy",898GatherEvery { .. } => "gather_every",899#[cfg(feature = "reinterpret")]900Reinterpret(_) => "reinterpret",901ExtendConstant => "extend_constant",902903RowEncode(..) => "row_encode",904#[cfg(feature = "dtype-struct")]905RowDecode(..) => "row_decode",906};907write!(f, "{s}")908}909}910911#[macro_export]912macro_rules! wrap {913($e:expr) => {914SpecialEq::new(Arc::new($e))915};916917($e:expr, $($args:expr),*) => {{918let f = move |s: &mut [Column]| {919$e(s, $($args),*)920};921922SpecialEq::new(Arc::new(f))923}};924}925926/// `Fn(&[Column], args)`927/// * all expression arguments are in the slice.928/// * the first element is the root expression.929#[macro_export]930macro_rules! map_as_slice {931($func:path) => {{932let f = move |s: &mut [Column]| {933$func(s)934};935936SpecialEq::new(Arc::new(f))937}};938939($func:path, $($args:expr),*) => {{940let f = move |s: &mut [Column]| {941$func(s, $($args),*)942};943944SpecialEq::new(Arc::new(f))945}};946}947948/// * `FnOnce(Series)`949/// * `FnOnce(Series, args)`950#[macro_export]951macro_rules! map_owned {952($func:path) => {{953let f = move |c: &mut [Column]| {954let c = std::mem::take(&mut c[0]);955$func(c)956};957958SpecialEq::new(Arc::new(f))959}};960961($func:path, $($args:expr),*) => {{962let f = move |c: &mut [Column]| {963let c = std::mem::take(&mut c[0]);964$func(c, $($args),*)965};966967SpecialEq::new(Arc::new(f))968}};969}970971/// `Fn(&Series, args)`972#[macro_export]973macro_rules! map {974($func:path) => {{975let f = move |c: &mut [Column]| {976let c = &c[0];977$func(c)978};979980SpecialEq::new(Arc::new(f))981}};982983($func:path, $($args:expr),*) => {{984let f = move |c: &mut [Column]| {985let c = &c[0];986$func(c, $($args),*)987};988989SpecialEq::new(Arc::new(f))990}};991}992993impl IRFunctionExpr {994pub fn function_options(&self) -> FunctionOptions {995use IRFunctionExpr as F;996match self {997#[cfg(feature = "dtype-array")]998F::ArrayExpr(e) => e.function_options(),999F::BinaryExpr(e) => e.function_options(),1000#[cfg(feature = "dtype-categorical")]1001F::Categorical(e) => e.function_options(),1002#[cfg(feature = "dtype-extension")]1003F::Extension(e) => e.function_options(),1004F::ListExpr(e) => e.function_options(),1005#[cfg(feature = "strings")]1006F::StringExpr(e) => e.function_options(),1007#[cfg(feature = "dtype-struct")]1008F::StructExpr(e) => e.function_options(),1009#[cfg(feature = "temporal")]1010F::TemporalExpr(e) => e.function_options(),1011#[cfg(feature = "bitwise")]1012F::Bitwise(e) => e.function_options(),1013F::Boolean(e) => e.function_options(),1014#[cfg(feature = "business")]1015F::Business(e) => e.function_options(),1016F::Pow(e) => e.function_options(),1017#[cfg(feature = "range")]1018F::Range(e) => e.function_options(),1019#[cfg(feature = "abs")]1020F::Abs => FunctionOptions::elementwise(),1021F::Negate => FunctionOptions::elementwise(),1022#[cfg(feature = "hist")]1023F::Hist { .. } => FunctionOptions::groupwise(),1024F::NullCount => FunctionOptions::aggregation().flag(FunctionFlags::NON_ORDER_OBSERVING),1025#[cfg(feature = "row_hash")]1026F::Hash(_, _, _, _) => FunctionOptions::elementwise(),1027#[cfg(feature = "arg_where")]1028F::ArgWhere => FunctionOptions::groupwise(),1029#[cfg(feature = "index_of")]1030F::IndexOf => {1031FunctionOptions::aggregation().with_casting_rules(CastingRules::FirstArgLossless)1032},1033#[cfg(feature = "search_sorted")]1034F::SearchSorted { .. } => FunctionOptions::groupwise().with_supertyping(1035(SuperTypeFlags::default() & !SuperTypeFlags::ALLOW_PRIMITIVE_TO_STRING).into(),1036),1037#[cfg(feature = "trigonometry")]1038F::Trigonometry(_) => FunctionOptions::elementwise(),1039#[cfg(feature = "trigonometry")]1040F::Atan2 => FunctionOptions::elementwise(),1041#[cfg(feature = "sign")]1042F::Sign => FunctionOptions::elementwise(),1043F::FillNull => FunctionOptions::elementwise().with_supertyping(Default::default()),1044F::FillNullWithStrategy(strategy) if strategy.is_elementwise() => {1045FunctionOptions::elementwise()1046},1047F::FillNullWithStrategy(_) => FunctionOptions::length_preserving(),1048#[cfg(feature = "rolling_window")]1049F::RollingExpr { .. } => FunctionOptions::length_preserving(),1050#[cfg(feature = "rolling_window_by")]1051F::RollingExprBy { .. } => FunctionOptions::length_preserving(),1052F::Rechunk => FunctionOptions::length_preserving(),1053F::Append { .. } => FunctionOptions::groupwise(),1054F::ShiftAndFill => FunctionOptions::length_preserving(),1055F::Shift => FunctionOptions::length_preserving(),1056F::DropNans => {1057FunctionOptions::row_separable().flag(FunctionFlags::NON_ORDER_PRODUCING)1058},1059F::DropNulls => FunctionOptions::row_separable()1060.flag(FunctionFlags::ALLOW_EMPTY_INPUTS | FunctionFlags::NON_ORDER_PRODUCING),1061#[cfg(feature = "mode")]1062F::Mode { maintain_order } => FunctionOptions::groupwise().with_flags(|f| {1063let f = f | FunctionFlags::NON_ORDER_PRODUCING;10641065if !*maintain_order {1066f | FunctionFlags::NON_ORDER_OBSERVING | FunctionFlags::TERMINATES_INPUT_ORDER1067} else {1068f1069}1070}),1071#[cfg(feature = "moment")]1072F::Skew(_) => FunctionOptions::aggregation().flag(FunctionFlags::NON_ORDER_OBSERVING),1073#[cfg(feature = "moment")]1074F::Kurtosis(_, _) => {1075FunctionOptions::aggregation().flag(FunctionFlags::NON_ORDER_OBSERVING)1076},1077#[cfg(feature = "dtype-array")]1078F::Reshape(dims) => {1079if dims.len() == 1 && dims[0] == ReshapeDimension::Infer {1080FunctionOptions::row_separable()1081} else {1082FunctionOptions::groupwise()1083}1084},1085#[cfg(feature = "repeat_by")]1086F::RepeatBy => FunctionOptions::elementwise(),1087F::ArgUnique => FunctionOptions::groupwise(),1088F::ArgMin | F::ArgMax => FunctionOptions::aggregation(),1089F::ArgSort { .. } => FunctionOptions::length_preserving(),1090F::MinBy | F::MaxBy => FunctionOptions::aggregation(),1091F::Product => FunctionOptions::aggregation().flag(FunctionFlags::NON_ORDER_OBSERVING),1092#[cfg(feature = "rank")]1093F::Rank { .. } => FunctionOptions::length_preserving(),1094F::Repeat => {1095FunctionOptions::groupwise().with_flags(|f| f | FunctionFlags::ALLOW_RENAME)1096},1097#[cfg(feature = "round_series")]1098F::Clip { .. } => FunctionOptions::elementwise(),1099#[cfg(feature = "dtype-struct")]1100F::AsStruct => FunctionOptions::elementwise().with_flags(|f| {1101f | FunctionFlags::PASS_NAME_TO_APPLY | FunctionFlags::INPUT_WILDCARD_EXPANSION1102}),1103#[cfg(feature = "top_k")]1104F::TopK { .. } => FunctionOptions::groupwise(),1105#[cfg(feature = "top_k")]1106F::TopKBy { .. } => FunctionOptions::groupwise(),1107#[cfg(feature = "cum_agg")]1108F::CumCount { .. }1109| F::CumSum { .. }1110| F::CumProd { .. }1111| F::CumMin { .. }1112| F::CumMax { .. } => FunctionOptions::length_preserving(),1113F::Reverse => FunctionOptions::length_preserving()1114.with_flags(|f| f | FunctionFlags::NON_ORDER_OBSERVING),1115#[cfg(feature = "dtype-struct")]1116F::ValueCounts { sort, .. } => FunctionOptions::groupwise().with_flags(|mut f| {1117if !sort {1118f |= FunctionFlags::TERMINATES_INPUT_ORDER | FunctionFlags::NON_ORDER_PRODUCING1119}1120f | FunctionFlags::PASS_NAME_TO_APPLY | FunctionFlags::NON_ORDER_OBSERVING1121}),1122#[cfg(feature = "unique_counts")]1123F::UniqueCounts => FunctionOptions::groupwise(),1124#[cfg(feature = "approx_unique")]1125F::ApproxNUnique => {1126FunctionOptions::aggregation().flag(FunctionFlags::NON_ORDER_OBSERVING)1127},1128F::Coalesce => FunctionOptions::elementwise()1129.with_flags(|f| f | FunctionFlags::INPUT_WILDCARD_EXPANSION)1130.with_supertyping(Default::default()),1131#[cfg(feature = "diff")]1132F::Diff(NullBehavior::Drop) => FunctionOptions::groupwise(),1133#[cfg(feature = "diff")]1134F::Diff(NullBehavior::Ignore) => FunctionOptions::length_preserving(),1135#[cfg(feature = "pct_change")]1136F::PctChange => FunctionOptions::length_preserving(),1137#[cfg(feature = "interpolate")]1138F::Interpolate(_) => FunctionOptions::length_preserving(),1139#[cfg(feature = "interpolate_by")]1140F::InterpolateBy => FunctionOptions::length_preserving(),1141#[cfg(feature = "log")]1142F::Log | F::Log1p | F::Exp => FunctionOptions::elementwise(),1143#[cfg(feature = "log")]1144F::Entropy { .. } => {1145FunctionOptions::aggregation().flag(FunctionFlags::NON_ORDER_OBSERVING)1146},1147F::Unique(maintain_order) => FunctionOptions::groupwise().with_flags(|f| {1148let f = f | FunctionFlags::NON_ORDER_PRODUCING;11491150if !*maintain_order {1151f | FunctionFlags::NON_ORDER_OBSERVING | FunctionFlags::TERMINATES_INPUT_ORDER1152} else {1153f1154}1155}),1156#[cfg(feature = "round_series")]1157F::Round { .. } | F::RoundSF { .. } | F::Floor | F::Ceil => {1158FunctionOptions::elementwise()1159},1160#[cfg(feature = "fused")]1161F::Fused(_) => FunctionOptions::elementwise(),1162F::ConcatExpr(_) => FunctionOptions::groupwise()1163.with_flags(|f| f | FunctionFlags::INPUT_WILDCARD_EXPANSION)1164.with_supertyping(Default::default()),1165#[cfg(feature = "cov")]1166F::Correlation { .. } => {1167FunctionOptions::aggregation().with_supertyping(Default::default())1168},1169#[cfg(feature = "peaks")]1170F::PeakMin | F::PeakMax => FunctionOptions::length_preserving(),1171#[cfg(feature = "cutqcut")]1172F::Cut { .. } | F::QCut { .. } => FunctionOptions::length_preserving()1173.with_flags(|f| f | FunctionFlags::PASS_NAME_TO_APPLY),1174#[cfg(feature = "rle")]1175F::RLE => FunctionOptions::groupwise(),1176#[cfg(feature = "rle")]1177F::RLEID => FunctionOptions::length_preserving(),1178F::ToPhysical => FunctionOptions::elementwise(),1179#[cfg(feature = "random")]1180F::Random {1181method: IRRandomMethod::Sample { .. },1182..1183} => FunctionOptions::groupwise(),1184#[cfg(feature = "random")]1185F::Random {1186method: IRRandomMethod::Shuffle,1187..1188} => FunctionOptions::length_preserving(),1189F::SetSortedFlag(_) => FunctionOptions::elementwise(),1190#[cfg(feature = "ffi_plugin")]1191F::FfiPlugin { flags, .. } => *flags,1192F::MaxHorizontal | F::MinHorizontal => FunctionOptions::elementwise().with_flags(|f| {1193f | FunctionFlags::INPUT_WILDCARD_EXPANSION | FunctionFlags::ALLOW_RENAME1194}),1195F::MeanHorizontal { .. } | F::SumHorizontal { .. } => FunctionOptions::elementwise()1196.with_flags(|f| f | FunctionFlags::INPUT_WILDCARD_EXPANSION),11971198F::FoldHorizontal { returns_scalar, .. }1199| F::ReduceHorizontal { returns_scalar, .. } => FunctionOptions::groupwise()1200.with_flags(|mut f| {1201f |= FunctionFlags::INPUT_WILDCARD_EXPANSION;1202if *returns_scalar {1203f |= FunctionFlags::RETURNS_SCALAR;1204}1205f1206}),1207#[cfg(feature = "dtype-struct")]1208F::CumFoldHorizontal { returns_scalar, .. }1209| F::CumReduceHorizontal { returns_scalar, .. } => FunctionOptions::groupwise()1210.with_flags(|mut f| {1211f |= FunctionFlags::INPUT_WILDCARD_EXPANSION;1212if *returns_scalar {1213f |= FunctionFlags::RETURNS_SCALAR;1214}1215f1216}),1217#[cfg(feature = "ewma")]1218F::EwmMean { .. } | F::EwmStd { .. } | F::EwmVar { .. } => {1219FunctionOptions::length_preserving()1220},1221#[cfg(feature = "ewma_by")]1222F::EwmMeanBy { .. } => FunctionOptions::length_preserving(),1223#[cfg(feature = "replace")]1224F::Replace => FunctionOptions::elementwise(),1225#[cfg(feature = "replace")]1226F::ReplaceStrict { .. } => FunctionOptions::elementwise(),1227F::GatherEvery { .. } => FunctionOptions::groupwise(),1228#[cfg(feature = "reinterpret")]1229F::Reinterpret(_) => FunctionOptions::elementwise(),1230F::ExtendConstant => FunctionOptions::groupwise(),12311232F::RowEncode(..) => FunctionOptions::elementwise(),1233#[cfg(feature = "dtype-struct")]1234F::RowDecode(..) => FunctionOptions::elementwise(),1235}1236}1237}123812391240