Skip to content

Commit

Permalink
refactor: remove default auto-explode for man_many_private
Browse files Browse the repository at this point in the history
  • Loading branch information
reswqa committed Sep 23, 2023
1 parent 48d7b26 commit 96cdc1c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 20 deletions.
11 changes: 2 additions & 9 deletions crates/polars-plan/src/dsl/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ impl Expr {
FunctionExpr::Pow(PowFunction::Generic),
&[exponent.into()],
false,
false,
)
.with_function_options(|mut options| {
options.auto_explode = false;
options
})
}

/// Compute the square root of the given expression
Expand Down Expand Up @@ -117,11 +114,7 @@ impl Expr {
/// Compute the inverse tangent of the given expression, with the angle expressed as the argument of a complex number
#[cfg(feature = "trigonometry")]
pub fn arctan2(self, x: Self) -> Self {
self.map_many_private(FunctionExpr::Atan2, &[x], false)
.with_function_options(|mut options| {
options.auto_explode = false;
options
})
self.map_many_private(FunctionExpr::Atan2, &[x], false, false)
}

/// Compute the hyperbolic cosine of the given expression
Expand Down
3 changes: 3 additions & 0 deletions crates/polars-plan/src/dsl/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ impl BinaryNameSpace {
FunctionExpr::BinaryExpr(BinaryFunction::Contains),
&[pat],
true,
true,
)
}

Expand All @@ -19,6 +20,7 @@ impl BinaryNameSpace {
FunctionExpr::BinaryExpr(BinaryFunction::EndsWith),
&[sub],
true,
true,
)
}

Expand All @@ -28,6 +30,7 @@ impl BinaryNameSpace {
FunctionExpr::BinaryExpr(BinaryFunction::StartsWith),
&[sub],
true,
true,
)
}
}
5 changes: 4 additions & 1 deletion crates/polars-plan/src/dsl/dt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ impl DateLikeNameSpace {
self.0.map_many_private(
FunctionExpr::TemporalExpr(TemporalFunction::Truncate(offset)),
&[every, ambiguous],
true,
false,
)
}
Expand Down Expand Up @@ -265,14 +266,15 @@ impl DateLikeNameSpace {
#[cfg(feature = "date_offset")]
pub fn offset_by(self, by: Expr) -> Expr {
self.0
.map_many_private(FunctionExpr::DateOffset, &[by], false)
.map_many_private(FunctionExpr::DateOffset, &[by], true, false)
}

#[cfg(feature = "timezones")]
pub fn replace_time_zone(self, time_zone: Option<TimeZone>, ambiguous: Expr) -> Expr {
self.0.map_many_private(
FunctionExpr::TemporalExpr(TemporalFunction::ReplaceTimeZone(time_zone)),
&[ambiguous],
true,
false,
)
}
Expand All @@ -281,6 +283,7 @@ impl DateLikeNameSpace {
self.0.map_many_private(
FunctionExpr::TemporalExpr(TemporalFunction::Combine(tu)),
&[time],
true,
false,
)
}
Expand Down
15 changes: 12 additions & 3 deletions crates/polars-plan/src/dsl/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ impl ListNameSpace {

/// Get items in every sublist by index.
pub fn get(self, index: Expr) -> Expr {
self.0
.map_many_private(FunctionExpr::ListExpr(ListFunction::Get), &[index], false)
self.0.map_many_private(
FunctionExpr::ListExpr(ListFunction::Get),
&[index],
true,
false,
)
}

/// Get items in every sublist by multiple indexes.
Expand All @@ -98,6 +102,7 @@ impl ListNameSpace {
self.0.map_many_private(
FunctionExpr::ListExpr(ListFunction::Take(null_on_oob)),
&[index],
true,
false,
)
}
Expand All @@ -119,6 +124,7 @@ impl ListNameSpace {
self.0.map_many_private(
FunctionExpr::ListExpr(ListFunction::Join),
&[separator],
true,
false,
)
}
Expand Down Expand Up @@ -169,6 +175,7 @@ impl ListNameSpace {
self.0.map_many_private(
FunctionExpr::ListExpr(ListFunction::Slice),
&[offset, length],
true,
false,
)
}
Expand Down Expand Up @@ -248,6 +255,7 @@ impl ListNameSpace {
.map_many_private(
FunctionExpr::ListExpr(ListFunction::Contains),
&[other],
true,
false,
)
.with_function_options(|mut options| {
Expand All @@ -264,6 +272,7 @@ impl ListNameSpace {
.map_many_private(
FunctionExpr::ListExpr(ListFunction::CountMatches),
&[other],
true,
false,
)
.with_function_options(|mut options| {
Expand All @@ -278,11 +287,11 @@ impl ListNameSpace {
.map_many_private(
FunctionExpr::ListExpr(ListFunction::SetOperation(set_operation)),
&[other],
false,
true,
)
.with_function_options(|mut options| {
options.input_wildcard_expansion = true;
options.auto_explode = false;
options
})
}
Expand Down
5 changes: 3 additions & 2 deletions crates/polars-plan/src/dsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ impl Expr {
self,
function_expr: FunctionExpr,
arguments: &[Expr],
auto_explode: bool,
cast_to_supertypes: bool,
) -> Self {
let mut input = Vec::with_capacity(arguments.len() + 1);
Expand All @@ -701,7 +702,7 @@ impl Expr {
function: function_expr,
options: FunctionOptions {
collect_groups: ApplyOptions::ApplyFlat,
auto_explode: true,
auto_explode,
cast_to_supertypes,
..Default::default()
},
Expand Down Expand Up @@ -1053,7 +1054,7 @@ impl Expr {
let arguments = &[other];
// we don't have to apply on groups, so this is faster
if has_literal {
self.map_many_private(BooleanFunction::IsIn.into(), arguments, true)
self.map_many_private(BooleanFunction::IsIn.into(), arguments, true, true)
} else {
self.apply_many_private(BooleanFunction::IsIn.into(), arguments, true, true)
}
Expand Down
24 changes: 19 additions & 5 deletions crates/polars-plan/src/dsl/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ impl StringNameSpace {
}),
&[pat],
true,
true,
)
}

Expand All @@ -28,6 +29,7 @@ impl StringNameSpace {
}),
&[pat],
true,
true,
)
}

Expand All @@ -37,6 +39,7 @@ impl StringNameSpace {
FunctionExpr::StringExpr(StringFunction::EndsWith),
&[sub],
true,
true,
)
}

Expand All @@ -46,6 +49,7 @@ impl StringNameSpace {
FunctionExpr::StringExpr(StringFunction::StartsWith),
&[sub],
true,
true,
)
}

Expand Down Expand Up @@ -119,13 +123,17 @@ impl StringNameSpace {
/// Extract each successive non-overlapping match in an individual string as an array
pub fn extract_all(self, pat: Expr) -> Expr {
self.0
.map_many_private(StringFunction::ExtractAll.into(), &[pat], false)
.map_many_private(StringFunction::ExtractAll.into(), &[pat], true, false)
}

/// Count all successive non-overlapping regex matches.
pub fn count_matches(self, pat: Expr, literal: bool) -> Expr {
self.0
.map_many_private(StringFunction::CountMatches(literal).into(), &[pat], false)
self.0.map_many_private(
StringFunction::CountMatches(literal).into(),
&[pat],
true,
false,
)
}

/// Convert a Utf8 column into a Date/Datetime/Time column.
Expand All @@ -134,6 +142,7 @@ impl StringNameSpace {
self.0.map_many_private(
StringFunction::Strptime(dtype, options).into(),
&[ambiguous],
true,
false,
)
}
Expand Down Expand Up @@ -205,13 +214,13 @@ impl StringNameSpace {
/// Split the string by a substring. The resulting dtype is `List<Utf8>`.
pub fn split(self, by: Expr) -> Expr {
self.0
.map_many_private(StringFunction::Split(false).into(), &[by], false)
.map_many_private(StringFunction::Split(false).into(), &[by], true, false)
}

/// Split the string by a substring and keep the substring. The resulting dtype is `List<Utf8>`.
pub fn split_inclusive(self, by: Expr) -> Expr {
self.0
.map_many_private(StringFunction::Split(true).into(), &[by], false)
.map_many_private(StringFunction::Split(true).into(), &[by], true, false)
}

#[cfg(feature = "dtype-struct")]
Expand Down Expand Up @@ -261,6 +270,7 @@ impl StringNameSpace {
FunctionExpr::StringExpr(StringFunction::Replace { n: 1, literal }),
&[pat, value],
true,
true,
)
}

Expand All @@ -271,6 +281,7 @@ impl StringNameSpace {
FunctionExpr::StringExpr(StringFunction::Replace { n, literal }),
&[pat, value],
true,
true,
)
}

Expand All @@ -281,6 +292,7 @@ impl StringNameSpace {
FunctionExpr::StringExpr(StringFunction::Replace { n: -1, literal }),
&[pat, value],
true,
true,
)
}

Expand Down Expand Up @@ -313,6 +325,7 @@ impl StringNameSpace {
self.0.map_many_private(
FunctionExpr::StringExpr(StringFunction::StripPrefix),
&[prefix],
true,
false,
)
}
Expand All @@ -322,6 +335,7 @@ impl StringNameSpace {
self.0.map_many_private(
FunctionExpr::StringExpr(StringFunction::StripSuffix),
&[suffix],
true,
false,
)
}
Expand Down

0 comments on commit 96cdc1c

Please sign in to comment.