Path: blob/main/crates/polars-plan/src/plans/aexpr/function_expr/mod.rs
7889 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},184Product,185#[cfg(feature = "rank")]186Rank {187options: RankOptions,188seed: Option<u64>,189},190Repeat,191#[cfg(feature = "round_series")]192Clip {193has_min: bool,194has_max: bool,195},196#[cfg(feature = "dtype-struct")]197AsStruct,198#[cfg(feature = "top_k")]199TopK {200descending: bool,201},202#[cfg(feature = "top_k")]203TopKBy {204descending: Vec<bool>,205},206#[cfg(feature = "cum_agg")]207CumCount {208reverse: bool,209},210#[cfg(feature = "cum_agg")]211CumSum {212reverse: bool,213},214#[cfg(feature = "cum_agg")]215CumProd {216reverse: bool,217},218#[cfg(feature = "cum_agg")]219CumMin {220reverse: bool,221},222#[cfg(feature = "cum_agg")]223CumMax {224reverse: bool,225},226Reverse,227#[cfg(feature = "dtype-struct")]228ValueCounts {229sort: bool,230parallel: bool,231name: PlSmallStr,232normalize: bool,233},234#[cfg(feature = "unique_counts")]235UniqueCounts,236#[cfg(feature = "approx_unique")]237ApproxNUnique,238Coalesce,239#[cfg(feature = "diff")]240Diff(NullBehavior),241#[cfg(feature = "pct_change")]242PctChange,243#[cfg(feature = "interpolate")]244Interpolate(InterpolationMethod),245#[cfg(feature = "interpolate_by")]246InterpolateBy,247#[cfg(feature = "log")]248Entropy {249base: f64,250normalize: bool,251},252#[cfg(feature = "log")]253Log,254#[cfg(feature = "log")]255Log1p,256#[cfg(feature = "log")]257Exp,258Unique(bool),259#[cfg(feature = "round_series")]260Round {261decimals: u32,262mode: RoundMode,263},264#[cfg(feature = "round_series")]265RoundSF {266digits: i32,267},268#[cfg(feature = "round_series")]269Floor,270#[cfg(feature = "round_series")]271Ceil,272#[cfg(feature = "fused")]273Fused(fused::FusedOperator),274ConcatExpr(bool),275#[cfg(feature = "cov")]276Correlation {277method: correlation::IRCorrelationMethod,278},279#[cfg(feature = "peaks")]280PeakMin,281#[cfg(feature = "peaks")]282PeakMax,283#[cfg(feature = "cutqcut")]284Cut {285breaks: Vec<f64>,286labels: Option<Vec<PlSmallStr>>,287left_closed: bool,288include_breaks: bool,289},290#[cfg(feature = "cutqcut")]291QCut {292probs: Vec<f64>,293labels: Option<Vec<PlSmallStr>>,294left_closed: bool,295allow_duplicates: bool,296include_breaks: bool,297},298#[cfg(feature = "rle")]299RLE,300#[cfg(feature = "rle")]301RLEID,302ToPhysical,303#[cfg(feature = "random")]304Random {305method: IRRandomMethod,306seed: Option<u64>,307},308SetSortedFlag(IsSorted),309#[cfg(feature = "ffi_plugin")]310/// Creating this node is unsafe311/// This will lead to calls over FFI.312FfiPlugin {313flags: FunctionOptions,314/// Shared library.315lib: PlSmallStr,316/// Identifier in the shared lib.317symbol: PlSmallStr,318/// Pickle serialized keyword arguments.319kwargs: Arc<[u8]>,320},321322FoldHorizontal {323callback: PlanCallback<(Series, Series), Series>,324returns_scalar: bool,325return_dtype: Option<DataType>,326},327ReduceHorizontal {328callback: PlanCallback<(Series, Series), Series>,329returns_scalar: bool,330return_dtype: Option<DataType>,331},332#[cfg(feature = "dtype-struct")]333CumReduceHorizontal {334callback: PlanCallback<(Series, Series), Series>,335returns_scalar: bool,336return_dtype: Option<DataType>,337},338#[cfg(feature = "dtype-struct")]339CumFoldHorizontal {340callback: PlanCallback<(Series, Series), Series>,341returns_scalar: bool,342return_dtype: Option<DataType>,343include_init: bool,344},345346MaxHorizontal,347MinHorizontal,348SumHorizontal {349ignore_nulls: bool,350},351MeanHorizontal {352ignore_nulls: bool,353},354#[cfg(feature = "ewma")]355EwmMean {356options: EWMOptions,357},358#[cfg(feature = "ewma_by")]359EwmMeanBy {360half_life: Duration,361},362#[cfg(feature = "ewma")]363EwmStd {364options: EWMOptions,365},366#[cfg(feature = "ewma")]367EwmVar {368options: EWMOptions,369},370#[cfg(feature = "replace")]371Replace,372#[cfg(feature = "replace")]373ReplaceStrict {374return_dtype: Option<DataType>,375},376GatherEvery {377n: usize,378offset: usize,379},380#[cfg(feature = "reinterpret")]381Reinterpret(bool),382ExtendConstant,383384RowEncode(Vec<DataType>, RowEncodingVariant),385#[cfg(feature = "dtype-struct")]386RowDecode(Vec<Field>, RowEncodingVariant),387}388389impl Hash for IRFunctionExpr {390fn hash<H: Hasher>(&self, state: &mut H) {391std::mem::discriminant(self).hash(state);392use IRFunctionExpr::*;393match self {394// Namespaces395#[cfg(feature = "dtype-array")]396ArrayExpr(f) => f.hash(state),397BinaryExpr(f) => f.hash(state),398#[cfg(feature = "dtype-categorical")]399Categorical(f) => f.hash(state),400#[cfg(feature = "dtype-extension")]401Extension(f) => f.hash(state),402ListExpr(f) => f.hash(state),403#[cfg(feature = "strings")]404StringExpr(f) => f.hash(state),405#[cfg(feature = "dtype-struct")]406StructExpr(f) => f.hash(state),407#[cfg(feature = "temporal")]408TemporalExpr(f) => f.hash(state),409#[cfg(feature = "bitwise")]410Bitwise(f) => f.hash(state),411412// Other expressions413Boolean(f) => f.hash(state),414#[cfg(feature = "business")]415Business(f) => f.hash(state),416Pow(f) => f.hash(state),417#[cfg(feature = "index_of")]418IndexOf => {},419#[cfg(feature = "search_sorted")]420SearchSorted { side, descending } => {421side.hash(state);422descending.hash(state);423},424#[cfg(feature = "random")]425Random { method, .. } => method.hash(state),426#[cfg(feature = "cov")]427Correlation { method, .. } => method.hash(state),428#[cfg(feature = "range")]429Range(f) => f.hash(state),430#[cfg(feature = "trigonometry")]431Trigonometry(f) => f.hash(state),432#[cfg(feature = "fused")]433Fused(f) => f.hash(state),434#[cfg(feature = "diff")]435Diff(null_behavior) => null_behavior.hash(state),436#[cfg(feature = "interpolate")]437Interpolate(f) => f.hash(state),438#[cfg(feature = "interpolate_by")]439InterpolateBy => {},440#[cfg(feature = "ffi_plugin")]441FfiPlugin {442flags: _,443lib,444symbol,445kwargs,446} => {447kwargs.hash(state);448lib.hash(state);449symbol.hash(state);450},451452FoldHorizontal {453callback,454returns_scalar,455return_dtype,456}457| ReduceHorizontal {458callback,459returns_scalar,460return_dtype,461} => {462callback.hash(state);463returns_scalar.hash(state);464return_dtype.hash(state);465},466#[cfg(feature = "dtype-struct")]467CumReduceHorizontal {468callback,469returns_scalar,470return_dtype,471} => {472callback.hash(state);473returns_scalar.hash(state);474return_dtype.hash(state);475},476#[cfg(feature = "dtype-struct")]477CumFoldHorizontal {478callback,479returns_scalar,480return_dtype,481include_init,482} => {483callback.hash(state);484returns_scalar.hash(state);485return_dtype.hash(state);486include_init.hash(state);487},488489SumHorizontal { ignore_nulls } | MeanHorizontal { ignore_nulls } => {490ignore_nulls.hash(state)491},492MaxHorizontal | MinHorizontal | DropNans | DropNulls | Reverse | ArgUnique | ArgMin493| ArgMax | Product | Shift | ShiftAndFill | Rechunk => {},494Append { upcast } => {495upcast.hash(state);496},497ArgSort {498descending,499nulls_last,500} => {501descending.hash(state);502nulls_last.hash(state);503},504#[cfg(feature = "mode")]505Mode { maintain_order } => {506maintain_order.hash(state);507},508#[cfg(feature = "abs")]509Abs => {},510Negate => {},511NullCount => {},512#[cfg(feature = "arg_where")]513ArgWhere => {},514#[cfg(feature = "trigonometry")]515Atan2 => {},516#[cfg(feature = "dtype-struct")]517AsStruct => {},518#[cfg(feature = "sign")]519Sign => {},520#[cfg(feature = "row_hash")]521Hash(a, b, c, d) => (a, b, c, d).hash(state),522FillNull => {},523#[cfg(feature = "rolling_window")]524RollingExpr { function, options } => {525function.hash(state);526options.hash(state);527},528#[cfg(feature = "rolling_window_by")]529RollingExprBy {530function_by,531options,532} => {533function_by.hash(state);534options.hash(state);535},536#[cfg(feature = "moment")]537Skew(a) => a.hash(state),538#[cfg(feature = "moment")]539Kurtosis(a, b) => {540a.hash(state);541b.hash(state);542},543Repeat => {},544#[cfg(feature = "rank")]545Rank { options, seed } => {546options.hash(state);547seed.hash(state);548},549#[cfg(feature = "round_series")]550Clip { has_min, has_max } => {551has_min.hash(state);552has_max.hash(state);553},554#[cfg(feature = "top_k")]555TopK { descending } => descending.hash(state),556#[cfg(feature = "cum_agg")]557CumCount { reverse } => reverse.hash(state),558#[cfg(feature = "cum_agg")]559CumSum { reverse } => reverse.hash(state),560#[cfg(feature = "cum_agg")]561CumProd { reverse } => reverse.hash(state),562#[cfg(feature = "cum_agg")]563CumMin { reverse } => reverse.hash(state),564#[cfg(feature = "cum_agg")]565CumMax { reverse } => reverse.hash(state),566#[cfg(feature = "dtype-struct")]567ValueCounts {568sort,569parallel,570name,571normalize,572} => {573sort.hash(state);574parallel.hash(state);575name.hash(state);576normalize.hash(state);577},578#[cfg(feature = "unique_counts")]579UniqueCounts => {},580#[cfg(feature = "approx_unique")]581ApproxNUnique => {},582Coalesce => {},583#[cfg(feature = "pct_change")]584PctChange => {},585#[cfg(feature = "log")]586Entropy { base, normalize } => {587base.to_bits().hash(state);588normalize.hash(state);589},590#[cfg(feature = "log")]591Log => {},592#[cfg(feature = "log")]593Log1p => {},594#[cfg(feature = "log")]595Exp => {},596Unique(a) => a.hash(state),597#[cfg(feature = "round_series")]598Round { decimals, mode } => {599decimals.hash(state);600mode.hash(state);601},602#[cfg(feature = "round_series")]603IRFunctionExpr::RoundSF { digits } => digits.hash(state),604#[cfg(feature = "round_series")]605IRFunctionExpr::Floor => {},606#[cfg(feature = "round_series")]607Ceil => {},608ConcatExpr(a) => a.hash(state),609#[cfg(feature = "peaks")]610PeakMin => {},611#[cfg(feature = "peaks")]612PeakMax => {},613#[cfg(feature = "cutqcut")]614Cut {615breaks,616labels,617left_closed,618include_breaks,619} => {620let slice = bytemuck::cast_slice::<_, u64>(breaks);621slice.hash(state);622labels.hash(state);623left_closed.hash(state);624include_breaks.hash(state);625},626#[cfg(feature = "dtype-array")]627Reshape(dims) => dims.hash(state),628#[cfg(feature = "repeat_by")]629RepeatBy => {},630#[cfg(feature = "cutqcut")]631QCut {632probs,633labels,634left_closed,635allow_duplicates,636include_breaks,637} => {638let slice = bytemuck::cast_slice::<_, u64>(probs);639slice.hash(state);640labels.hash(state);641left_closed.hash(state);642allow_duplicates.hash(state);643include_breaks.hash(state);644},645#[cfg(feature = "rle")]646RLE => {},647#[cfg(feature = "rle")]648RLEID => {},649ToPhysical => {},650SetSortedFlag(is_sorted) => is_sorted.hash(state),651#[cfg(feature = "ewma")]652EwmMean { options } => options.hash(state),653#[cfg(feature = "ewma_by")]654EwmMeanBy { half_life } => (half_life).hash(state),655#[cfg(feature = "ewma")]656EwmStd { options } => options.hash(state),657#[cfg(feature = "ewma")]658EwmVar { options } => options.hash(state),659#[cfg(feature = "hist")]660Hist {661bin_count,662include_category,663include_breakpoint,664} => {665bin_count.hash(state);666include_category.hash(state);667include_breakpoint.hash(state);668},669#[cfg(feature = "replace")]670Replace => {},671#[cfg(feature = "replace")]672ReplaceStrict { return_dtype } => return_dtype.hash(state),673FillNullWithStrategy(strategy) => strategy.hash(state),674GatherEvery { n, offset } => (n, offset).hash(state),675#[cfg(feature = "reinterpret")]676Reinterpret(signed) => signed.hash(state),677ExtendConstant => {},678#[cfg(feature = "top_k")]679TopKBy { descending } => descending.hash(state),680681RowEncode(dts, variants) => {682dts.hash(state);683variants.hash(state);684},685#[cfg(feature = "dtype-struct")]686RowDecode(fs, variants) => {687fs.hash(state);688variants.hash(state);689},690}691}692}693694impl Display for IRFunctionExpr {695fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {696use IRFunctionExpr::*;697let s = match self {698// Namespaces699#[cfg(feature = "dtype-array")]700ArrayExpr(func) => return write!(f, "{func}"),701BinaryExpr(func) => return write!(f, "{func}"),702#[cfg(feature = "dtype-categorical")]703Categorical(func) => return write!(f, "{func}"),704#[cfg(feature = "dtype-extension")]705Extension(func) => return write!(f, "{func}"),706ListExpr(func) => return write!(f, "{func}"),707#[cfg(feature = "strings")]708StringExpr(func) => return write!(f, "{func}"),709#[cfg(feature = "dtype-struct")]710StructExpr(func) => return write!(f, "{func}"),711#[cfg(feature = "temporal")]712TemporalExpr(func) => return write!(f, "{func}"),713#[cfg(feature = "bitwise")]714Bitwise(func) => return write!(f, "bitwise_{func}"),715716// Other expressions717Boolean(func) => return write!(f, "{func}"),718#[cfg(feature = "business")]719Business(func) => return write!(f, "{func}"),720#[cfg(feature = "abs")]721Abs => "abs",722Negate => "negate",723NullCount => "null_count",724Pow(func) => return write!(f, "{func}"),725#[cfg(feature = "row_hash")]726Hash(_, _, _, _) => "hash",727#[cfg(feature = "arg_where")]728ArgWhere => "arg_where",729#[cfg(feature = "index_of")]730IndexOf => "index_of",731#[cfg(feature = "search_sorted")]732SearchSorted { .. } => "search_sorted",733#[cfg(feature = "range")]734Range(func) => return write!(f, "{func}"),735#[cfg(feature = "trigonometry")]736Trigonometry(func) => return write!(f, "{func}"),737#[cfg(feature = "trigonometry")]738Atan2 => return write!(f, "arctan2"),739#[cfg(feature = "sign")]740Sign => "sign",741FillNull => "fill_null",742#[cfg(feature = "rolling_window")]743RollingExpr { function, .. } => return write!(f, "{function}"),744#[cfg(feature = "rolling_window_by")]745RollingExprBy { function_by, .. } => return write!(f, "{function_by}"),746Rechunk => "rechunk",747Append { .. } => "append",748ShiftAndFill => "shift_and_fill",749DropNans => "drop_nans",750DropNulls => "drop_nulls",751#[cfg(feature = "mode")]752Mode { maintain_order } => {753if *maintain_order {754"mode_stable"755} else {756"mode"757}758},759#[cfg(feature = "moment")]760Skew(_) => "skew",761#[cfg(feature = "moment")]762Kurtosis(..) => "kurtosis",763ArgUnique => "arg_unique",764ArgMin => "arg_min",765ArgMax => "arg_max",766ArgSort { .. } => "arg_sort",767Product => "product",768Repeat => "repeat",769#[cfg(feature = "rank")]770Rank { .. } => "rank",771#[cfg(feature = "round_series")]772Clip { has_min, has_max } => match (has_min, has_max) {773(true, true) => "clip",774(false, true) => "clip_max",775(true, false) => "clip_min",776_ => unreachable!(),777},778#[cfg(feature = "dtype-struct")]779AsStruct => "as_struct",780#[cfg(feature = "top_k")]781TopK { descending } => {782if *descending {783"bottom_k"784} else {785"top_k"786}787},788#[cfg(feature = "top_k")]789TopKBy { .. } => "top_k_by",790Shift => "shift",791#[cfg(feature = "cum_agg")]792CumCount { .. } => "cum_count",793#[cfg(feature = "cum_agg")]794CumSum { .. } => "cum_sum",795#[cfg(feature = "cum_agg")]796CumProd { .. } => "cum_prod",797#[cfg(feature = "cum_agg")]798CumMin { .. } => "cum_min",799#[cfg(feature = "cum_agg")]800CumMax { .. } => "cum_max",801#[cfg(feature = "dtype-struct")]802ValueCounts { .. } => "value_counts",803#[cfg(feature = "unique_counts")]804UniqueCounts => "unique_counts",805Reverse => "reverse",806#[cfg(feature = "approx_unique")]807ApproxNUnique => "approx_n_unique",808Coalesce => "coalesce",809#[cfg(feature = "diff")]810Diff(_) => "diff",811#[cfg(feature = "pct_change")]812PctChange => "pct_change",813#[cfg(feature = "interpolate")]814Interpolate(_) => "interpolate",815#[cfg(feature = "interpolate_by")]816InterpolateBy => "interpolate_by",817#[cfg(feature = "log")]818Entropy { .. } => "entropy",819#[cfg(feature = "log")]820Log => "log",821#[cfg(feature = "log")]822Log1p => "log1p",823#[cfg(feature = "log")]824Exp => "exp",825Unique(stable) => {826if *stable {827"unique_stable"828} else {829"unique"830}831},832#[cfg(feature = "round_series")]833Round { .. } => "round",834#[cfg(feature = "round_series")]835RoundSF { .. } => "round_sig_figs",836#[cfg(feature = "round_series")]837Floor => "floor",838#[cfg(feature = "round_series")]839Ceil => "ceil",840#[cfg(feature = "fused")]841Fused(fused) => return Display::fmt(fused, f),842ConcatExpr(_) => "concat_expr",843#[cfg(feature = "cov")]844Correlation { method, .. } => return Display::fmt(method, f),845#[cfg(feature = "peaks")]846PeakMin => "peak_min",847#[cfg(feature = "peaks")]848PeakMax => "peak_max",849#[cfg(feature = "cutqcut")]850Cut { .. } => "cut",851#[cfg(feature = "cutqcut")]852QCut { .. } => "qcut",853#[cfg(feature = "dtype-array")]854Reshape(_) => "reshape",855#[cfg(feature = "repeat_by")]856RepeatBy => "repeat_by",857#[cfg(feature = "rle")]858RLE => "rle",859#[cfg(feature = "rle")]860RLEID => "rle_id",861ToPhysical => "to_physical",862#[cfg(feature = "random")]863Random { method, .. } => method.into(),864SetSortedFlag(_) => "set_sorted",865#[cfg(feature = "ffi_plugin")]866FfiPlugin { lib, symbol, .. } => return write!(f, "{lib}:{symbol}"),867868FoldHorizontal { .. } => "fold",869ReduceHorizontal { .. } => "reduce",870#[cfg(feature = "dtype-struct")]871CumReduceHorizontal { .. } => "cum_reduce",872#[cfg(feature = "dtype-struct")]873CumFoldHorizontal { .. } => "cum_fold",874875MaxHorizontal => "max_horizontal",876MinHorizontal => "min_horizontal",877SumHorizontal { .. } => "sum_horizontal",878MeanHorizontal { .. } => "mean_horizontal",879#[cfg(feature = "ewma")]880EwmMean { .. } => "ewm_mean",881#[cfg(feature = "ewma_by")]882EwmMeanBy { .. } => "ewm_mean_by",883#[cfg(feature = "ewma")]884EwmStd { .. } => "ewm_std",885#[cfg(feature = "ewma")]886EwmVar { .. } => "ewm_var",887#[cfg(feature = "hist")]888Hist { .. } => "hist",889#[cfg(feature = "replace")]890Replace => "replace",891#[cfg(feature = "replace")]892ReplaceStrict { .. } => "replace_strict",893FillNullWithStrategy(_) => "fill_null_with_strategy",894GatherEvery { .. } => "gather_every",895#[cfg(feature = "reinterpret")]896Reinterpret(_) => "reinterpret",897ExtendConstant => "extend_constant",898899RowEncode(..) => "row_encode",900#[cfg(feature = "dtype-struct")]901RowDecode(..) => "row_decode",902};903write!(f, "{s}")904}905}906907#[macro_export]908macro_rules! wrap {909($e:expr) => {910SpecialEq::new(Arc::new($e))911};912913($e:expr, $($args:expr),*) => {{914let f = move |s: &mut [Column]| {915$e(s, $($args),*)916};917918SpecialEq::new(Arc::new(f))919}};920}921922/// `Fn(&[Column], args)`923/// * all expression arguments are in the slice.924/// * the first element is the root expression.925#[macro_export]926macro_rules! map_as_slice {927($func:path) => {{928let f = move |s: &mut [Column]| {929$func(s)930};931932SpecialEq::new(Arc::new(f))933}};934935($func:path, $($args:expr),*) => {{936let f = move |s: &mut [Column]| {937$func(s, $($args),*)938};939940SpecialEq::new(Arc::new(f))941}};942}943944/// * `FnOnce(Series)`945/// * `FnOnce(Series, args)`946#[macro_export]947macro_rules! map_owned {948($func:path) => {{949let f = move |c: &mut [Column]| {950let c = std::mem::take(&mut c[0]);951$func(c)952};953954SpecialEq::new(Arc::new(f))955}};956957($func:path, $($args:expr),*) => {{958let f = move |c: &mut [Column]| {959let c = std::mem::take(&mut c[0]);960$func(c, $($args),*)961};962963SpecialEq::new(Arc::new(f))964}};965}966967/// `Fn(&Series, args)`968#[macro_export]969macro_rules! map {970($func:path) => {{971let f = move |c: &mut [Column]| {972let c = &c[0];973$func(c)974};975976SpecialEq::new(Arc::new(f))977}};978979($func:path, $($args:expr),*) => {{980let f = move |c: &mut [Column]| {981let c = &c[0];982$func(c, $($args),*)983};984985SpecialEq::new(Arc::new(f))986}};987}988989impl IRFunctionExpr {990pub fn function_options(&self) -> FunctionOptions {991use IRFunctionExpr as F;992match self {993#[cfg(feature = "dtype-array")]994F::ArrayExpr(e) => e.function_options(),995F::BinaryExpr(e) => e.function_options(),996#[cfg(feature = "dtype-categorical")]997F::Categorical(e) => e.function_options(),998#[cfg(feature = "dtype-extension")]999F::Extension(e) => e.function_options(),1000F::ListExpr(e) => e.function_options(),1001#[cfg(feature = "strings")]1002F::StringExpr(e) => e.function_options(),1003#[cfg(feature = "dtype-struct")]1004F::StructExpr(e) => e.function_options(),1005#[cfg(feature = "temporal")]1006F::TemporalExpr(e) => e.function_options(),1007#[cfg(feature = "bitwise")]1008F::Bitwise(e) => e.function_options(),1009F::Boolean(e) => e.function_options(),1010#[cfg(feature = "business")]1011F::Business(e) => e.function_options(),1012F::Pow(e) => e.function_options(),1013#[cfg(feature = "range")]1014F::Range(e) => e.function_options(),1015#[cfg(feature = "abs")]1016F::Abs => FunctionOptions::elementwise(),1017F::Negate => FunctionOptions::elementwise(),1018#[cfg(feature = "hist")]1019F::Hist { .. } => FunctionOptions::groupwise(),1020F::NullCount => FunctionOptions::aggregation().flag(FunctionFlags::NON_ORDER_OBSERVING),1021#[cfg(feature = "row_hash")]1022F::Hash(_, _, _, _) => FunctionOptions::elementwise(),1023#[cfg(feature = "arg_where")]1024F::ArgWhere => FunctionOptions::groupwise(),1025#[cfg(feature = "index_of")]1026F::IndexOf => {1027FunctionOptions::aggregation().with_casting_rules(CastingRules::FirstArgLossless)1028},1029#[cfg(feature = "search_sorted")]1030F::SearchSorted { .. } => FunctionOptions::groupwise().with_supertyping(1031(SuperTypeFlags::default() & !SuperTypeFlags::ALLOW_PRIMITIVE_TO_STRING).into(),1032),1033#[cfg(feature = "trigonometry")]1034F::Trigonometry(_) => FunctionOptions::elementwise(),1035#[cfg(feature = "trigonometry")]1036F::Atan2 => FunctionOptions::elementwise(),1037#[cfg(feature = "sign")]1038F::Sign => FunctionOptions::elementwise(),1039F::FillNull => FunctionOptions::elementwise().with_supertyping(Default::default()),1040F::FillNullWithStrategy(strategy) if strategy.is_elementwise() => {1041FunctionOptions::elementwise()1042},1043F::FillNullWithStrategy(_) => FunctionOptions::length_preserving(),1044#[cfg(feature = "rolling_window")]1045F::RollingExpr { .. } => FunctionOptions::length_preserving(),1046#[cfg(feature = "rolling_window_by")]1047F::RollingExprBy { .. } => FunctionOptions::length_preserving(),1048F::Rechunk => FunctionOptions::length_preserving(),1049F::Append { .. } => FunctionOptions::groupwise(),1050F::ShiftAndFill => FunctionOptions::length_preserving(),1051F::Shift => FunctionOptions::length_preserving(),1052F::DropNans => {1053FunctionOptions::row_separable().flag(FunctionFlags::NON_ORDER_PRODUCING)1054},1055F::DropNulls => FunctionOptions::row_separable()1056.flag(FunctionFlags::ALLOW_EMPTY_INPUTS | FunctionFlags::NON_ORDER_PRODUCING),1057#[cfg(feature = "mode")]1058F::Mode { maintain_order } => FunctionOptions::groupwise().with_flags(|f| {1059let f = f | FunctionFlags::NON_ORDER_PRODUCING;10601061if !*maintain_order {1062f | FunctionFlags::NON_ORDER_OBSERVING | FunctionFlags::TERMINATES_INPUT_ORDER1063} else {1064f1065}1066}),1067#[cfg(feature = "moment")]1068F::Skew(_) => FunctionOptions::aggregation().flag(FunctionFlags::NON_ORDER_OBSERVING),1069#[cfg(feature = "moment")]1070F::Kurtosis(_, _) => {1071FunctionOptions::aggregation().flag(FunctionFlags::NON_ORDER_OBSERVING)1072},1073#[cfg(feature = "dtype-array")]1074F::Reshape(dims) => {1075if dims.len() == 1 && dims[0] == ReshapeDimension::Infer {1076FunctionOptions::row_separable()1077} else {1078FunctionOptions::groupwise()1079}1080},1081#[cfg(feature = "repeat_by")]1082F::RepeatBy => FunctionOptions::elementwise(),1083F::ArgUnique => FunctionOptions::groupwise(),1084F::ArgMin | F::ArgMax => FunctionOptions::aggregation(),1085F::ArgSort { .. } => FunctionOptions::length_preserving(),1086F::Product => FunctionOptions::aggregation().flag(FunctionFlags::NON_ORDER_OBSERVING),1087#[cfg(feature = "rank")]1088F::Rank { .. } => FunctionOptions::length_preserving(),1089F::Repeat => {1090FunctionOptions::groupwise().with_flags(|f| f | FunctionFlags::ALLOW_RENAME)1091},1092#[cfg(feature = "round_series")]1093F::Clip { .. } => FunctionOptions::elementwise(),1094#[cfg(feature = "dtype-struct")]1095F::AsStruct => FunctionOptions::elementwise().with_flags(|f| {1096f | FunctionFlags::PASS_NAME_TO_APPLY | FunctionFlags::INPUT_WILDCARD_EXPANSION1097}),1098#[cfg(feature = "top_k")]1099F::TopK { .. } => FunctionOptions::groupwise(),1100#[cfg(feature = "top_k")]1101F::TopKBy { .. } => FunctionOptions::groupwise(),1102#[cfg(feature = "cum_agg")]1103F::CumCount { .. }1104| F::CumSum { .. }1105| F::CumProd { .. }1106| F::CumMin { .. }1107| F::CumMax { .. } => FunctionOptions::length_preserving(),1108F::Reverse => FunctionOptions::length_preserving()1109.with_flags(|f| f | FunctionFlags::NON_ORDER_OBSERVING),1110#[cfg(feature = "dtype-struct")]1111F::ValueCounts { sort, .. } => FunctionOptions::groupwise().with_flags(|mut f| {1112if !sort {1113f |= FunctionFlags::TERMINATES_INPUT_ORDER | FunctionFlags::NON_ORDER_PRODUCING1114}1115f | FunctionFlags::PASS_NAME_TO_APPLY | FunctionFlags::NON_ORDER_OBSERVING1116}),1117#[cfg(feature = "unique_counts")]1118F::UniqueCounts => FunctionOptions::groupwise(),1119#[cfg(feature = "approx_unique")]1120F::ApproxNUnique => {1121FunctionOptions::aggregation().flag(FunctionFlags::NON_ORDER_OBSERVING)1122},1123F::Coalesce => FunctionOptions::elementwise()1124.with_flags(|f| f | FunctionFlags::INPUT_WILDCARD_EXPANSION)1125.with_supertyping(Default::default()),1126#[cfg(feature = "diff")]1127F::Diff(NullBehavior::Drop) => FunctionOptions::groupwise(),1128#[cfg(feature = "diff")]1129F::Diff(NullBehavior::Ignore) => FunctionOptions::length_preserving(),1130#[cfg(feature = "pct_change")]1131F::PctChange => FunctionOptions::length_preserving(),1132#[cfg(feature = "interpolate")]1133F::Interpolate(_) => FunctionOptions::length_preserving(),1134#[cfg(feature = "interpolate_by")]1135F::InterpolateBy => FunctionOptions::length_preserving(),1136#[cfg(feature = "log")]1137F::Log | F::Log1p | F::Exp => FunctionOptions::elementwise(),1138#[cfg(feature = "log")]1139F::Entropy { .. } => {1140FunctionOptions::aggregation().flag(FunctionFlags::NON_ORDER_OBSERVING)1141},1142F::Unique(maintain_order) => FunctionOptions::groupwise().with_flags(|f| {1143let f = f | FunctionFlags::NON_ORDER_PRODUCING;11441145if !*maintain_order {1146f | FunctionFlags::NON_ORDER_OBSERVING | FunctionFlags::TERMINATES_INPUT_ORDER1147} else {1148f1149}1150}),1151#[cfg(feature = "round_series")]1152F::Round { .. } | F::RoundSF { .. } | F::Floor | F::Ceil => {1153FunctionOptions::elementwise()1154},1155#[cfg(feature = "fused")]1156F::Fused(_) => FunctionOptions::elementwise(),1157F::ConcatExpr(_) => FunctionOptions::groupwise()1158.with_flags(|f| f | FunctionFlags::INPUT_WILDCARD_EXPANSION)1159.with_supertyping(Default::default()),1160#[cfg(feature = "cov")]1161F::Correlation { .. } => {1162FunctionOptions::aggregation().with_supertyping(Default::default())1163},1164#[cfg(feature = "peaks")]1165F::PeakMin | F::PeakMax => FunctionOptions::length_preserving(),1166#[cfg(feature = "cutqcut")]1167F::Cut { .. } | F::QCut { .. } => FunctionOptions::length_preserving()1168.with_flags(|f| f | FunctionFlags::PASS_NAME_TO_APPLY),1169#[cfg(feature = "rle")]1170F::RLE => FunctionOptions::groupwise(),1171#[cfg(feature = "rle")]1172F::RLEID => FunctionOptions::length_preserving(),1173F::ToPhysical => FunctionOptions::elementwise(),1174#[cfg(feature = "random")]1175F::Random {1176method: IRRandomMethod::Sample { .. },1177..1178} => FunctionOptions::groupwise(),1179#[cfg(feature = "random")]1180F::Random {1181method: IRRandomMethod::Shuffle,1182..1183} => FunctionOptions::length_preserving(),1184F::SetSortedFlag(_) => FunctionOptions::elementwise(),1185#[cfg(feature = "ffi_plugin")]1186F::FfiPlugin { flags, .. } => *flags,1187F::MaxHorizontal | F::MinHorizontal => FunctionOptions::elementwise().with_flags(|f| {1188f | FunctionFlags::INPUT_WILDCARD_EXPANSION | FunctionFlags::ALLOW_RENAME1189}),1190F::MeanHorizontal { .. } | F::SumHorizontal { .. } => FunctionOptions::elementwise()1191.with_flags(|f| f | FunctionFlags::INPUT_WILDCARD_EXPANSION),11921193F::FoldHorizontal { returns_scalar, .. }1194| F::ReduceHorizontal { returns_scalar, .. } => FunctionOptions::groupwise()1195.with_flags(|mut f| {1196f |= FunctionFlags::INPUT_WILDCARD_EXPANSION;1197if *returns_scalar {1198f |= FunctionFlags::RETURNS_SCALAR;1199}1200f1201}),1202#[cfg(feature = "dtype-struct")]1203F::CumFoldHorizontal { returns_scalar, .. }1204| F::CumReduceHorizontal { returns_scalar, .. } => FunctionOptions::groupwise()1205.with_flags(|mut f| {1206f |= FunctionFlags::INPUT_WILDCARD_EXPANSION;1207if *returns_scalar {1208f |= FunctionFlags::RETURNS_SCALAR;1209}1210f1211}),1212#[cfg(feature = "ewma")]1213F::EwmMean { .. } | F::EwmStd { .. } | F::EwmVar { .. } => {1214FunctionOptions::length_preserving()1215},1216#[cfg(feature = "ewma_by")]1217F::EwmMeanBy { .. } => FunctionOptions::length_preserving(),1218#[cfg(feature = "replace")]1219F::Replace => FunctionOptions::elementwise(),1220#[cfg(feature = "replace")]1221F::ReplaceStrict { .. } => FunctionOptions::elementwise(),1222F::GatherEvery { .. } => FunctionOptions::groupwise(),1223#[cfg(feature = "reinterpret")]1224F::Reinterpret(_) => FunctionOptions::elementwise(),1225F::ExtendConstant => FunctionOptions::groupwise(),12261227F::RowEncode(..) => FunctionOptions::elementwise(),1228#[cfg(feature = "dtype-struct")]1229F::RowDecode(..) => FunctionOptions::elementwise(),1230}1231}1232}123312341235