Path: blob/main/crates/polars-plan/src/plans/conversion/ir_to_dsl.rs
6940 views
use super::*;12/// converts a node from the AExpr arena to Expr3#[recursive]4pub fn node_to_expr(node: Node, expr_arena: &Arena<AExpr>) -> Expr {5let expr = expr_arena.get(node).clone();67match expr {8AExpr::Explode { expr, skip_empty } => Expr::Explode {9input: Arc::new(node_to_expr(expr, expr_arena)),10skip_empty,11},12AExpr::Column(a) => Expr::Column(a),13AExpr::Literal(s) => Expr::Literal(s),14AExpr::BinaryExpr { left, op, right } => {15let l = node_to_expr(left, expr_arena);16let r = node_to_expr(right, expr_arena);17Expr::BinaryExpr {18left: Arc::new(l),19op,20right: Arc::new(r),21}22},23AExpr::Cast {24expr,25dtype,26options: strict,27} => {28let exp = node_to_expr(expr, expr_arena);29Expr::Cast {30expr: Arc::new(exp),31dtype: dtype.into(),32options: strict,33}34},35AExpr::Sort { expr, options } => {36let exp = node_to_expr(expr, expr_arena);37Expr::Sort {38expr: Arc::new(exp),39options,40}41},42AExpr::Gather {43expr,44idx,45returns_scalar,46} => {47let expr = node_to_expr(expr, expr_arena);48let idx = node_to_expr(idx, expr_arena);49Expr::Gather {50expr: Arc::new(expr),51idx: Arc::new(idx),52returns_scalar,53}54},55AExpr::SortBy {56expr,57by,58sort_options,59} => {60let expr = node_to_expr(expr, expr_arena);61let by = by62.iter()63.map(|node| node_to_expr(*node, expr_arena))64.collect();65Expr::SortBy {66expr: Arc::new(expr),67by,68sort_options,69}70},71AExpr::Filter { input, by } => {72let input = node_to_expr(input, expr_arena);73let by = node_to_expr(by, expr_arena);74Expr::Filter {75input: Arc::new(input),76by: Arc::new(by),77}78},79AExpr::Agg(agg) => match agg {80IRAggExpr::Min {81input,82propagate_nans,83} => {84let exp = node_to_expr(input, expr_arena);85AggExpr::Min {86input: Arc::new(exp),87propagate_nans,88}89.into()90},91IRAggExpr::Max {92input,93propagate_nans,94} => {95let exp = node_to_expr(input, expr_arena);96AggExpr::Max {97input: Arc::new(exp),98propagate_nans,99}100.into()101},102103IRAggExpr::Mean(expr) => {104let exp = node_to_expr(expr, expr_arena);105AggExpr::Mean(Arc::new(exp)).into()106},107IRAggExpr::Median(expr) => {108let exp = node_to_expr(expr, expr_arena);109AggExpr::Median(Arc::new(exp)).into()110},111IRAggExpr::NUnique(expr) => {112let exp = node_to_expr(expr, expr_arena);113AggExpr::NUnique(Arc::new(exp)).into()114},115IRAggExpr::First(expr) => {116let exp = node_to_expr(expr, expr_arena);117AggExpr::First(Arc::new(exp)).into()118},119IRAggExpr::Last(expr) => {120let exp = node_to_expr(expr, expr_arena);121AggExpr::Last(Arc::new(exp)).into()122},123IRAggExpr::Implode(expr) => {124let exp = node_to_expr(expr, expr_arena);125AggExpr::Implode(Arc::new(exp)).into()126},127IRAggExpr::Quantile {128expr,129quantile,130method,131} => {132let expr = node_to_expr(expr, expr_arena);133let quantile = node_to_expr(quantile, expr_arena);134AggExpr::Quantile {135expr: Arc::new(expr),136quantile: Arc::new(quantile),137method,138}139.into()140},141IRAggExpr::Sum(expr) => {142let exp = node_to_expr(expr, expr_arena);143AggExpr::Sum(Arc::new(exp)).into()144},145IRAggExpr::Std(expr, ddof) => {146let exp = node_to_expr(expr, expr_arena);147AggExpr::Std(Arc::new(exp), ddof).into()148},149IRAggExpr::Var(expr, ddof) => {150let exp = node_to_expr(expr, expr_arena);151AggExpr::Var(Arc::new(exp), ddof).into()152},153IRAggExpr::AggGroups(expr) => {154let exp = node_to_expr(expr, expr_arena);155AggExpr::AggGroups(Arc::new(exp)).into()156},157IRAggExpr::Count {158input,159include_nulls,160} => {161let input = node_to_expr(input, expr_arena);162AggExpr::Count {163input: Arc::new(input),164include_nulls,165}166.into()167},168},169AExpr::Ternary {170predicate,171truthy,172falsy,173} => {174let p = node_to_expr(predicate, expr_arena);175let t = node_to_expr(truthy, expr_arena);176let f = node_to_expr(falsy, expr_arena);177178Expr::Ternary {179predicate: Arc::new(p),180truthy: Arc::new(t),181falsy: Arc::new(f),182}183},184AExpr::AnonymousFunction {185input,186function,187options,188fmt_str,189} => Expr::AnonymousFunction {190input: expr_irs_to_exprs(input, expr_arena),191function,192options,193fmt_str,194},195AExpr::Eval {196expr,197evaluation,198variant,199} => Expr::Eval {200expr: Arc::new(node_to_expr(expr, expr_arena)),201evaluation: Arc::new(node_to_expr(evaluation, expr_arena)),202variant,203},204AExpr::Function {205input,206function,207options: _,208} => {209let input = expr_irs_to_exprs(input, expr_arena);210ir_function_to_dsl(input, function)211},212AExpr::Window {213function,214partition_by,215order_by,216options,217} => {218let function = Arc::new(node_to_expr(function, expr_arena));219let partition_by = nodes_to_exprs(&partition_by, expr_arena);220let order_by =221order_by.map(|(n, options)| (Arc::new(node_to_expr(n, expr_arena)), options));222Expr::Window {223function,224partition_by,225order_by,226options,227}228},229AExpr::Slice {230input,231offset,232length,233} => Expr::Slice {234input: Arc::new(node_to_expr(input, expr_arena)),235offset: Arc::new(node_to_expr(offset, expr_arena)),236length: Arc::new(node_to_expr(length, expr_arena)),237},238AExpr::Len => Expr::Len,239}240}241242fn nodes_to_exprs(nodes: &[Node], expr_arena: &Arena<AExpr>) -> Vec<Expr> {243nodes.iter().map(|n| node_to_expr(*n, expr_arena)).collect()244}245246pub fn ir_function_to_dsl(input: Vec<Expr>, function: IRFunctionExpr) -> Expr {247use {FunctionExpr as F, IRFunctionExpr as IF};248249let function = match function {250#[cfg(feature = "dtype-array")]251IF::ArrayExpr(f) => {252use {ArrayFunction as A, IRArrayFunction as IA};253F::ArrayExpr(match f {254IA::Concat => A::Concat,255IA::Length => A::Length,256IA::Min => A::Min,257IA::Max => A::Max,258IA::Sum => A::Sum,259IA::ToList => A::ToList,260IA::Unique(v) => A::Unique(v),261IA::NUnique => A::NUnique,262IA::Std(v) => A::Std(v),263IA::Var(v) => A::Var(v),264IA::Mean => A::Mean,265IA::Median => A::Median,266#[cfg(feature = "array_any_all")]267IA::Any => A::Any,268#[cfg(feature = "array_any_all")]269IA::All => A::All,270IA::Sort(v) => A::Sort(v),271IA::Reverse => A::Reverse,272IA::ArgMin => A::ArgMin,273IA::ArgMax => A::ArgMax,274IA::Get(v) => A::Get(v),275IA::Join(v) => A::Join(v),276#[cfg(feature = "is_in")]277IA::Contains { nulls_equal } => A::Contains { nulls_equal },278#[cfg(feature = "array_count")]279IA::CountMatches => A::CountMatches,280IA::Shift => A::Shift,281IA::Slice(offset, length) => A::Slice(offset, length),282IA::Explode { skip_empty } => A::Explode { skip_empty },283#[cfg(feature = "array_to_struct")]284IA::ToStruct(ng) => A::ToStruct(ng),285})286},287IF::BinaryExpr(f) => {288use {BinaryFunction as B, IRBinaryFunction as IB};289F::BinaryExpr(match f {290IB::Contains => B::Contains,291IB::StartsWith => B::StartsWith,292IB::EndsWith => B::EndsWith,293#[cfg(feature = "binary_encoding")]294IB::HexDecode(v) => B::HexDecode(v),295#[cfg(feature = "binary_encoding")]296IB::HexEncode => B::HexEncode,297#[cfg(feature = "binary_encoding")]298IB::Base64Decode(v) => B::Base64Decode(v),299#[cfg(feature = "binary_encoding")]300IB::Base64Encode => B::Base64Encode,301IB::Size => B::Size,302#[cfg(feature = "binary_encoding")]303IB::Reinterpret(data_type, v) => B::Reinterpret(data_type.into(), v),304})305},306#[cfg(feature = "dtype-categorical")]307IF::Categorical(f) => {308use {CategoricalFunction as C, IRCategoricalFunction as IC};309F::Categorical(match f {310IC::GetCategories => C::GetCategories,311#[cfg(feature = "strings")]312IC::LenBytes => C::LenBytes,313#[cfg(feature = "strings")]314IC::LenChars => C::LenChars,315#[cfg(feature = "strings")]316IC::StartsWith(v) => C::StartsWith(v),317#[cfg(feature = "strings")]318IC::EndsWith(v) => C::EndsWith(v),319#[cfg(feature = "strings")]320IC::Slice(s, l) => C::Slice(s, l),321})322},323IF::ListExpr(f) => {324use {IRListFunction as IL, ListFunction as L};325F::ListExpr(match f {326IL::Concat => L::Concat,327#[cfg(feature = "is_in")]328IL::Contains { nulls_equal } => L::Contains { nulls_equal },329#[cfg(feature = "list_drop_nulls")]330IL::DropNulls => L::DropNulls,331#[cfg(feature = "list_sample")]332IL::Sample {333is_fraction,334with_replacement,335shuffle,336seed,337} => L::Sample {338is_fraction,339with_replacement,340shuffle,341seed,342},343IL::Slice => L::Slice,344IL::Shift => L::Shift,345IL::Get(v) => L::Get(v),346#[cfg(feature = "list_gather")]347IL::Gather(v) => L::Gather(v),348#[cfg(feature = "list_gather")]349IL::GatherEvery => L::GatherEvery,350#[cfg(feature = "list_count")]351IL::CountMatches => L::CountMatches,352IL::Sum => L::Sum,353IL::Length => L::Length,354IL::Max => L::Max,355IL::Min => L::Min,356IL::Mean => L::Mean,357IL::Median => L::Median,358IL::Std(v) => L::Std(v),359IL::Var(v) => L::Var(v),360IL::ArgMin => L::ArgMin,361IL::ArgMax => L::ArgMax,362#[cfg(feature = "diff")]363IL::Diff { n, null_behavior } => L::Diff { n, null_behavior },364IL::Sort(sort_options) => L::Sort(sort_options),365IL::Reverse => L::Reverse,366IL::Unique(v) => L::Unique(v),367IL::NUnique => L::NUnique,368#[cfg(feature = "list_sets")]369IL::SetOperation(set_operation) => L::SetOperation(set_operation),370#[cfg(feature = "list_any_all")]371IL::Any => L::Any,372#[cfg(feature = "list_any_all")]373IL::All => L::All,374IL::Join(v) => L::Join(v),375#[cfg(feature = "dtype-array")]376IL::ToArray(v) => L::ToArray(v),377#[cfg(feature = "list_to_struct")]378IL::ToStruct(list_to_struct_args) => L::ToStruct(list_to_struct_args),379})380},381#[cfg(feature = "strings")]382IF::StringExpr(f) => {383use {IRStringFunction as IB, StringFunction as B};384F::StringExpr(match f {385#[cfg(feature = "concat_str")]386IB::ConcatHorizontal {387delimiter,388ignore_nulls,389} => B::ConcatHorizontal {390delimiter,391ignore_nulls,392},393#[cfg(feature = "concat_str")]394IB::ConcatVertical {395delimiter,396ignore_nulls,397} => B::ConcatVertical {398delimiter,399ignore_nulls,400},401#[cfg(feature = "regex")]402IB::Contains { literal, strict } => B::Contains { literal, strict },403IB::CountMatches(v) => B::CountMatches(v),404IB::EndsWith => B::EndsWith,405IB::Extract(v) => B::Extract(v),406IB::ExtractAll => B::ExtractAll,407#[cfg(feature = "extract_groups")]408IB::ExtractGroups { dtype, pat } => B::ExtractGroups { dtype, pat },409#[cfg(feature = "regex")]410IB::Find { literal, strict } => B::Find { literal, strict },411#[cfg(feature = "string_to_integer")]412IB::ToInteger { dtype, strict } => B::ToInteger { dtype, strict },413IB::LenBytes => B::LenBytes,414IB::LenChars => B::LenChars,415IB::Lowercase => B::Lowercase,416#[cfg(feature = "extract_jsonpath")]417IB::JsonDecode(dtype) => B::JsonDecode(dtype.into()),418#[cfg(feature = "extract_jsonpath")]419IB::JsonPathMatch => B::JsonPathMatch,420#[cfg(feature = "regex")]421IB::Replace { n, literal } => B::Replace { n, literal },422#[cfg(feature = "string_normalize")]423IB::Normalize { form } => B::Normalize { form },424#[cfg(feature = "string_reverse")]425IB::Reverse => B::Reverse,426#[cfg(feature = "string_pad")]427IB::PadStart { fill_char } => B::PadStart { fill_char },428#[cfg(feature = "string_pad")]429IB::PadEnd { fill_char } => B::PadEnd { fill_char },430IB::Slice => B::Slice,431IB::Head => B::Head,432IB::Tail => B::Tail,433#[cfg(feature = "string_encoding")]434IB::HexEncode => B::HexEncode,435#[cfg(feature = "binary_encoding")]436IB::HexDecode(v) => B::HexDecode(v),437#[cfg(feature = "string_encoding")]438IB::Base64Encode => B::Base64Encode,439#[cfg(feature = "binary_encoding")]440IB::Base64Decode(v) => B::Base64Decode(v),441IB::StartsWith => B::StartsWith,442IB::StripChars => B::StripChars,443IB::StripCharsStart => B::StripCharsStart,444IB::StripCharsEnd => B::StripCharsEnd,445IB::StripPrefix => B::StripPrefix,446IB::StripSuffix => B::StripSuffix,447#[cfg(feature = "dtype-struct")]448IB::SplitExact { n, inclusive } => B::SplitExact { n, inclusive },449#[cfg(feature = "dtype-struct")]450IB::SplitN(n) => B::SplitN(n),451#[cfg(feature = "temporal")]452IB::Strptime(dtype, strptime_options) => {453B::Strptime(dtype.into(), strptime_options)454},455IB::Split(v) => B::Split(v),456#[cfg(feature = "dtype-decimal")]457IB::ToDecimal { scale } => B::ToDecimal { scale },458#[cfg(feature = "nightly")]459IB::Titlecase => B::Titlecase,460IB::Uppercase => B::Uppercase,461#[cfg(feature = "string_pad")]462IB::ZFill => B::ZFill,463#[cfg(feature = "find_many")]464IB::ContainsAny {465ascii_case_insensitive,466} => B::ContainsAny {467ascii_case_insensitive,468},469#[cfg(feature = "find_many")]470IB::ReplaceMany {471ascii_case_insensitive,472} => B::ReplaceMany {473ascii_case_insensitive,474},475#[cfg(feature = "find_many")]476IB::ExtractMany {477ascii_case_insensitive,478overlapping,479} => B::ExtractMany {480ascii_case_insensitive,481overlapping,482},483#[cfg(feature = "find_many")]484IB::FindMany {485ascii_case_insensitive,486overlapping,487} => B::FindMany {488ascii_case_insensitive,489overlapping,490},491#[cfg(feature = "regex")]492IB::EscapeRegex => B::EscapeRegex,493})494},495#[cfg(feature = "dtype-struct")]496IF::StructExpr(f) => {497use {IRStructFunction as IB, StructFunction as B};498F::StructExpr(match f {499IB::FieldByName(pl_small_str) => B::FieldByName(pl_small_str),500IB::RenameFields(pl_small_strs) => B::RenameFields(pl_small_strs),501IB::PrefixFields(pl_small_str) => B::PrefixFields(pl_small_str),502IB::SuffixFields(pl_small_str) => B::SuffixFields(pl_small_str),503#[cfg(feature = "json")]504IB::JsonEncode => B::JsonEncode,505IB::WithFields => B::WithFields,506#[cfg(feature = "python")]507IB::MapFieldNames(special_eq) => B::MapFieldNames(special_eq),508})509},510#[cfg(feature = "temporal")]511IF::TemporalExpr(f) => {512use {IRTemporalFunction as IB, TemporalFunction as B};513F::TemporalExpr(match f {514IB::Millennium => B::Millennium,515IB::Century => B::Century,516IB::Year => B::Year,517IB::IsLeapYear => B::IsLeapYear,518IB::IsoYear => B::IsoYear,519IB::Quarter => B::Quarter,520IB::Month => B::Month,521IB::DaysInMonth => B::DaysInMonth,522IB::Week => B::Week,523IB::WeekDay => B::WeekDay,524IB::Day => B::Day,525IB::OrdinalDay => B::OrdinalDay,526IB::Time => B::Time,527IB::Date => B::Date,528IB::Datetime => B::Datetime,529#[cfg(feature = "dtype-duration")]530IB::Duration(time_unit) => B::Duration(time_unit),531IB::Hour => B::Hour,532IB::Minute => B::Minute,533IB::Second => B::Second,534IB::Millisecond => B::Millisecond,535IB::Microsecond => B::Microsecond,536IB::Nanosecond => B::Nanosecond,537#[cfg(feature = "dtype-duration")]538IB::TotalDays => B::TotalDays,539#[cfg(feature = "dtype-duration")]540IB::TotalHours => B::TotalHours,541#[cfg(feature = "dtype-duration")]542IB::TotalMinutes => B::TotalMinutes,543#[cfg(feature = "dtype-duration")]544IB::TotalSeconds => B::TotalSeconds,545#[cfg(feature = "dtype-duration")]546IB::TotalMilliseconds => B::TotalMilliseconds,547#[cfg(feature = "dtype-duration")]548IB::TotalMicroseconds => B::TotalMicroseconds,549#[cfg(feature = "dtype-duration")]550IB::TotalNanoseconds => B::TotalNanoseconds,551IB::ToString(v) => B::ToString(v),552IB::CastTimeUnit(time_unit) => B::CastTimeUnit(time_unit),553IB::WithTimeUnit(time_unit) => B::WithTimeUnit(time_unit),554#[cfg(feature = "timezones")]555IB::ConvertTimeZone(time_zone) => B::ConvertTimeZone(time_zone),556IB::TimeStamp(time_unit) => B::TimeStamp(time_unit),557IB::Truncate => B::Truncate,558#[cfg(feature = "offset_by")]559IB::OffsetBy => B::OffsetBy,560#[cfg(feature = "month_start")]561IB::MonthStart => B::MonthStart,562#[cfg(feature = "month_end")]563IB::MonthEnd => B::MonthEnd,564#[cfg(feature = "timezones")]565IB::BaseUtcOffset => B::BaseUtcOffset,566#[cfg(feature = "timezones")]567IB::DSTOffset => B::DSTOffset,568IB::Round => B::Round,569IB::Replace => B::Replace,570#[cfg(feature = "timezones")]571IB::ReplaceTimeZone(time_zone, non_existent) => {572B::ReplaceTimeZone(time_zone, non_existent)573},574IB::Combine(time_unit) => B::Combine(time_unit),575IB::DatetimeFunction {576time_unit,577time_zone,578} => B::DatetimeFunction {579time_unit,580time_zone,581},582})583},584#[cfg(feature = "bitwise")]585IF::Bitwise(f) => {586use {BitwiseFunction as B, IRBitwiseFunction as IB};587F::Bitwise(match f {588IB::CountOnes => B::CountOnes,589IB::CountZeros => B::CountZeros,590IB::LeadingOnes => B::LeadingOnes,591IB::LeadingZeros => B::LeadingZeros,592IB::TrailingOnes => B::TrailingOnes,593IB::TrailingZeros => B::TrailingZeros,594IB::And => B::And,595IB::Or => B::Or,596IB::Xor => B::Xor,597})598},599IF::Boolean(f) => {600use {BooleanFunction as B, IRBooleanFunction as IB};601F::Boolean(match f {602IB::Any { ignore_nulls } => B::Any { ignore_nulls },603IB::All { ignore_nulls } => B::All { ignore_nulls },604IB::IsNull => B::IsNull,605IB::IsNotNull => B::IsNotNull,606IB::IsFinite => B::IsFinite,607IB::IsInfinite => B::IsInfinite,608IB::IsNan => B::IsNan,609IB::IsNotNan => B::IsNotNan,610#[cfg(feature = "is_first_distinct")]611IB::IsFirstDistinct => B::IsFirstDistinct,612#[cfg(feature = "is_last_distinct")]613IB::IsLastDistinct => B::IsLastDistinct,614#[cfg(feature = "is_unique")]615IB::IsUnique => B::IsUnique,616#[cfg(feature = "is_unique")]617IB::IsDuplicated => B::IsDuplicated,618#[cfg(feature = "is_between")]619IB::IsBetween { closed } => B::IsBetween { closed },620#[cfg(feature = "is_in")]621IB::IsIn { nulls_equal } => B::IsIn { nulls_equal },622#[cfg(feature = "is_close")]623IB::IsClose {624abs_tol,625rel_tol,626nans_equal,627} => B::IsClose {628abs_tol,629rel_tol,630nans_equal,631},632IB::AllHorizontal => B::AllHorizontal,633IB::AnyHorizontal => B::AnyHorizontal,634IB::Not => B::Not,635})636},637#[cfg(feature = "business")]638IF::Business(f) => {639use {BusinessFunction as B, IRBusinessFunction as IB};640F::Business(match f {641IB::BusinessDayCount {642week_mask,643holidays,644} => B::BusinessDayCount {645week_mask,646holidays,647},648IB::AddBusinessDay {649week_mask,650holidays,651roll,652} => B::AddBusinessDay {653week_mask,654holidays,655roll,656},657IB::IsBusinessDay {658week_mask,659holidays,660} => B::IsBusinessDay {661week_mask,662holidays,663},664})665},666#[cfg(feature = "abs")]667IF::Abs => F::Abs,668IF::Negate => F::Negate,669#[cfg(feature = "hist")]670IF::Hist {671bin_count,672include_category,673include_breakpoint,674} => F::Hist {675bin_count,676include_category,677include_breakpoint,678},679IF::NullCount => F::NullCount,680IF::Pow(f) => {681use {IRPowFunction as IP, PowFunction as P};682F::Pow(match f {683IP::Generic => P::Generic,684IP::Sqrt => P::Sqrt,685IP::Cbrt => P::Cbrt,686})687},688#[cfg(feature = "row_hash")]689IF::Hash(s0, s1, s2, s3) => F::Hash(s0, s1, s2, s3),690#[cfg(feature = "arg_where")]691IF::ArgWhere => F::ArgWhere,692#[cfg(feature = "index_of")]693IF::IndexOf => F::IndexOf,694#[cfg(feature = "search_sorted")]695IF::SearchSorted { side, descending } => F::SearchSorted { side, descending },696#[cfg(feature = "range")]697IF::Range(f) => {698use {IRRangeFunction as IR, RangeFunction as R};699F::Range(match f {700IR::IntRange { step, dtype } => R::IntRange {701step,702dtype: dtype.into(),703},704IR::IntRanges { dtype } => R::IntRanges {705dtype: dtype.into(),706},707IR::LinearSpace { closed } => R::LinearSpace { closed },708IR::LinearSpaces {709closed,710array_width,711} => R::LinearSpaces {712closed,713array_width,714},715#[cfg(feature = "dtype-date")]716IR::DateRange { interval, closed } => R::DateRange { interval, closed },717#[cfg(feature = "dtype-date")]718IR::DateRanges { interval, closed } => R::DateRanges { interval, closed },719#[cfg(feature = "dtype-datetime")]720IR::DatetimeRange {721interval,722closed,723time_unit,724time_zone,725} => R::DatetimeRange {726interval,727closed,728time_unit,729time_zone,730},731#[cfg(feature = "dtype-datetime")]732IR::DatetimeRanges {733interval,734closed,735time_unit,736time_zone,737} => R::DatetimeRanges {738interval,739closed,740time_unit,741time_zone,742},743#[cfg(feature = "dtype-time")]744IR::TimeRange { interval, closed } => R::TimeRange { interval, closed },745#[cfg(feature = "dtype-time")]746IR::TimeRanges { interval, closed } => R::TimeRanges { interval, closed },747})748},749#[cfg(feature = "trigonometry")]750IF::Trigonometry(f) => {751use {IRTrigonometricFunction as IT, TrigonometricFunction as T};752F::Trigonometry(match f {753IT::Cos => T::Cos,754IT::Cot => T::Cot,755IT::Sin => T::Sin,756IT::Tan => T::Tan,757IT::ArcCos => T::ArcCos,758IT::ArcSin => T::ArcSin,759IT::ArcTan => T::ArcTan,760IT::Cosh => T::Cosh,761IT::Sinh => T::Sinh,762IT::Tanh => T::Tanh,763IT::ArcCosh => T::ArcCosh,764IT::ArcSinh => T::ArcSinh,765IT::ArcTanh => T::ArcTanh,766IT::Degrees => T::Degrees,767IT::Radians => T::Radians,768})769},770#[cfg(feature = "trigonometry")]771IF::Atan2 => F::Atan2,772#[cfg(feature = "sign")]773IF::Sign => F::Sign,774IF::FillNull => F::FillNull,775IF::FillNullWithStrategy(strategy) => F::FillNullWithStrategy(strategy),776#[cfg(feature = "rolling_window")]777IF::RollingExpr { function, options } => {778use {IRRollingFunction as IR, RollingFunction as R};779FunctionExpr::RollingExpr {780function: match function {781IR::Min => R::Min,782IR::Max => R::Max,783IR::Mean => R::Mean,784IR::Sum => R::Sum,785IR::Quantile => R::Quantile,786IR::Var => R::Var,787IR::Std => R::Std,788#[cfg(feature = "moment")]789IR::Skew => R::Skew,790#[cfg(feature = "moment")]791IR::Kurtosis => R::Kurtosis,792#[cfg(feature = "cov")]793IR::CorrCov {794corr_cov_options,795is_corr,796} => R::CorrCov {797corr_cov_options,798is_corr,799},800IR::Map(f) => R::Map(f),801},802options,803}804},805#[cfg(feature = "rolling_window_by")]806IF::RollingExprBy {807function_by,808options,809} => {810use {IRRollingFunctionBy as IR, RollingFunctionBy as R};811FunctionExpr::RollingExprBy {812function_by: match function_by {813IR::MinBy => R::MinBy,814IR::MaxBy => R::MaxBy,815IR::MeanBy => R::MeanBy,816IR::SumBy => R::SumBy,817IR::QuantileBy => R::QuantileBy,818IR::VarBy => R::VarBy,819IR::StdBy => R::StdBy,820},821options,822}823},824IF::Rechunk => F::Rechunk,825IF::Append { upcast } => F::Append { upcast },826IF::ShiftAndFill => F::ShiftAndFill,827IF::Shift => F::Shift,828IF::DropNans => F::DropNans,829IF::DropNulls => F::DropNulls,830#[cfg(feature = "mode")]831IF::Mode => F::Mode,832#[cfg(feature = "moment")]833IF::Skew(v) => F::Skew(v),834#[cfg(feature = "moment")]835IF::Kurtosis(fisher, bias) => F::Kurtosis(fisher, bias),836#[cfg(feature = "dtype-array")]837IF::Reshape(dims) => F::Reshape(dims),838#[cfg(feature = "repeat_by")]839IF::RepeatBy => F::RepeatBy,840IF::ArgUnique => F::ArgUnique,841IF::ArgMin => F::ArgMin,842IF::ArgMax => F::ArgMax,843IF::ArgSort {844descending,845nulls_last,846} => F::ArgSort {847descending,848nulls_last,849},850IF::Product => F::Product,851#[cfg(feature = "rank")]852IF::Rank { options, seed } => F::Rank { options, seed },853IF::Repeat => F::Repeat,854#[cfg(feature = "round_series")]855IF::Clip { has_min, has_max } => F::Clip { has_min, has_max },856#[cfg(feature = "dtype-struct")]857IF::AsStruct => F::AsStruct,858#[cfg(feature = "top_k")]859IF::TopK { descending } => F::TopK { descending },860#[cfg(feature = "top_k")]861IF::TopKBy { descending } => F::TopKBy { descending },862#[cfg(feature = "cum_agg")]863IF::CumCount { reverse } => F::CumCount { reverse },864#[cfg(feature = "cum_agg")]865IF::CumSum { reverse } => F::CumSum { reverse },866#[cfg(feature = "cum_agg")]867IF::CumProd { reverse } => F::CumProd { reverse },868#[cfg(feature = "cum_agg")]869IF::CumMin { reverse } => F::CumMin { reverse },870#[cfg(feature = "cum_agg")]871IF::CumMax { reverse } => F::CumMax { reverse },872IF::Reverse => F::Reverse,873#[cfg(feature = "dtype-struct")]874IF::ValueCounts {875sort,876parallel,877name,878normalize,879} => F::ValueCounts {880sort,881parallel,882name,883normalize,884},885#[cfg(feature = "unique_counts")]886IF::UniqueCounts => F::UniqueCounts,887#[cfg(feature = "approx_unique")]888IF::ApproxNUnique => F::ApproxNUnique,889IF::Coalesce => F::Coalesce,890#[cfg(feature = "diff")]891IF::Diff(nb) => F::Diff(nb),892#[cfg(feature = "pct_change")]893IF::PctChange => F::PctChange,894#[cfg(feature = "interpolate")]895IF::Interpolate(m) => F::Interpolate(m),896#[cfg(feature = "interpolate_by")]897IF::InterpolateBy => F::InterpolateBy,898#[cfg(feature = "log")]899IF::Entropy { base, normalize } => F::Entropy { base, normalize },900#[cfg(feature = "log")]901IF::Log => F::Log,902#[cfg(feature = "log")]903IF::Log1p => F::Log1p,904#[cfg(feature = "log")]905IF::Exp => F::Exp,906IF::Unique(v) => F::Unique(v),907#[cfg(feature = "round_series")]908IF::Round { decimals, mode } => F::Round { decimals, mode },909#[cfg(feature = "round_series")]910IF::RoundSF { digits } => F::RoundSF { digits },911#[cfg(feature = "round_series")]912IF::Floor => F::Floor,913#[cfg(feature = "round_series")]914IF::Ceil => F::Ceil,915IF::UpperBound => F::UpperBound,916IF::LowerBound => F::LowerBound,917#[cfg(feature = "fused")]918IF::Fused(f) => {919assert_eq!(input.len(), 3);920let mut input = input.into_iter();921let fst = input.next().unwrap();922let snd = input.next().unwrap();923let trd = input.next().unwrap();924return match f {925FusedOperator::MultiplyAdd => (fst * snd) + trd,926FusedOperator::SubMultiply => fst - (snd * trd),927FusedOperator::MultiplySub => (fst * snd) - trd,928};929},930IF::ConcatExpr(v) => F::ConcatExpr(v),931#[cfg(feature = "cov")]932IF::Correlation { method } => {933use {CorrelationMethod as C, IRCorrelationMethod as IC};934F::Correlation {935method: match method {936IC::Pearson => C::Pearson,937#[cfg(all(feature = "rank", feature = "propagate_nans"))]938IC::SpearmanRank(v) => C::SpearmanRank(v),939IC::Covariance(v) => C::Covariance(v),940},941}942},943#[cfg(feature = "peaks")]944IF::PeakMin => F::PeakMin,945#[cfg(feature = "peaks")]946IF::PeakMax => F::PeakMax,947#[cfg(feature = "cutqcut")]948IF::Cut {949breaks,950labels,951left_closed,952include_breaks,953} => F::Cut {954breaks,955labels,956left_closed,957include_breaks,958},959#[cfg(feature = "cutqcut")]960IF::QCut {961probs,962labels,963left_closed,964allow_duplicates,965include_breaks,966} => F::QCut {967probs,968labels,969left_closed,970allow_duplicates,971include_breaks,972},973#[cfg(feature = "rle")]974IF::RLE => F::RLE,975#[cfg(feature = "rle")]976IF::RLEID => F::RLEID,977IF::ToPhysical => F::ToPhysical,978#[cfg(feature = "random")]979IF::Random { method, seed } => {980use {IRRandomMethod as IR, RandomMethod as R};981F::Random {982method: match method {983IR::Shuffle => R::Shuffle,984IR::Sample {985is_fraction,986with_replacement,987shuffle,988} => R::Sample {989is_fraction,990with_replacement,991shuffle,992},993},994seed,995}996},997IF::SetSortedFlag(s) => F::SetSortedFlag(s),998#[cfg(feature = "ffi_plugin")]999IF::FfiPlugin {1000flags,1001lib,1002symbol,1003kwargs,1004} => F::FfiPlugin {1005flags,1006lib,1007symbol,1008kwargs,1009},10101011IF::FoldHorizontal {1012callback,1013returns_scalar,1014return_dtype,1015} => F::FoldHorizontal {1016callback,1017returns_scalar,1018return_dtype: return_dtype.map(DataTypeExpr::Literal),1019},1020IF::ReduceHorizontal {1021callback,1022returns_scalar,1023return_dtype,1024} => F::ReduceHorizontal {1025callback,1026returns_scalar,1027return_dtype: return_dtype.map(DataTypeExpr::Literal),1028},1029#[cfg(feature = "dtype-struct")]1030IF::CumReduceHorizontal {1031callback,1032returns_scalar,1033return_dtype,1034} => F::CumReduceHorizontal {1035callback,1036returns_scalar,1037return_dtype: return_dtype.map(DataTypeExpr::Literal),1038},1039#[cfg(feature = "dtype-struct")]1040IF::CumFoldHorizontal {1041callback,1042returns_scalar,1043return_dtype,1044include_init,1045} => F::CumFoldHorizontal {1046callback,1047returns_scalar,1048return_dtype: return_dtype.map(DataTypeExpr::Literal),1049include_init,1050},10511052IF::MaxHorizontal => F::MaxHorizontal,1053IF::MinHorizontal => F::MinHorizontal,1054IF::SumHorizontal { ignore_nulls } => F::SumHorizontal { ignore_nulls },1055IF::MeanHorizontal { ignore_nulls } => F::MeanHorizontal { ignore_nulls },1056#[cfg(feature = "ewma")]1057IF::EwmMean { options } => F::EwmMean { options },1058#[cfg(feature = "ewma_by")]1059IF::EwmMeanBy { half_life } => F::EwmMeanBy { half_life },1060#[cfg(feature = "ewma")]1061IF::EwmStd { options } => F::EwmStd { options },1062#[cfg(feature = "ewma")]1063IF::EwmVar { options } => F::EwmVar { options },1064#[cfg(feature = "replace")]1065IF::Replace => F::Replace,1066#[cfg(feature = "replace")]1067IF::ReplaceStrict { return_dtype } => F::ReplaceStrict {1068return_dtype: return_dtype.map(Into::into),1069},1070IF::GatherEvery { n, offset } => F::GatherEvery { n, offset },1071#[cfg(feature = "reinterpret")]1072IF::Reinterpret(v) => F::Reinterpret(v),1073IF::ExtendConstant => F::ExtendConstant,10741075IF::RowEncode(_, v) => F::RowEncode(v),1076#[cfg(feature = "dtype-struct")]1077IF::RowDecode(fs, v) => F::RowDecode(1078fs.into_iter().map(|f| (f.name, f.dtype.into())).collect(),1079v,1080),1081};10821083Expr::Function { input, function }1084}108510861087