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