Skip to content

Commit

Permalink
refactor: remove default auto-explode for map_many_private (pola-rs#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
reswqa authored Sep 25, 2023
1 parent 27c18f7 commit 95f3d44
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 21 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,
)
}
}
6 changes: 5 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 @@ -258,6 +259,7 @@ impl DateLikeNameSpace {
FunctionExpr::TemporalExpr(TemporalFunction::Round(every, offset)),
&[ambiguous],
false,
false,
)
}

Expand All @@ -266,7 +268,7 @@ 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], false, false)
}

#[cfg(feature = "timezones")]
Expand All @@ -275,6 +277,7 @@ impl DateLikeNameSpace {
FunctionExpr::TemporalExpr(TemporalFunction::ReplaceTimeZone(time_zone)),
&[ambiguous],
false,
false,
)
}

Expand All @@ -283,6 +286,7 @@ impl DateLikeNameSpace {
FunctionExpr::TemporalExpr(TemporalFunction::Combine(tu)),
&[time],
false,
false,
)
}
}
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 @@ -90,8 +90,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 @@ -104,6 +108,7 @@ impl ListNameSpace {
self.0.map_many_private(
FunctionExpr::ListExpr(ListFunction::Take(null_on_oob)),
&[index],
true,
false,
)
}
Expand All @@ -126,6 +131,7 @@ impl ListNameSpace {
FunctionExpr::ListExpr(ListFunction::Join),
&[separator],
false,
false,
)
}

Expand Down Expand Up @@ -175,6 +181,7 @@ impl ListNameSpace {
self.0.map_many_private(
FunctionExpr::ListExpr(ListFunction::Slice),
&[offset, length],
true,
false,
)
}
Expand Down Expand Up @@ -254,6 +261,7 @@ impl ListNameSpace {
.map_many_private(
FunctionExpr::ListExpr(ListFunction::Contains),
&[other],
true,
false,
)
.with_function_options(|mut options| {
Expand All @@ -270,6 +278,7 @@ impl ListNameSpace {
.map_many_private(
FunctionExpr::ListExpr(ListFunction::CountMatches),
&[other],
true,
false,
)
.with_function_options(|mut options| {
Expand All @@ -284,11 +293,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 @@ -1065,7 +1066,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
28 changes: 22 additions & 6 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], false, 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], false, 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], false, false)
}

#[cfg(feature = "dtype-struct")]
Expand All @@ -225,6 +234,7 @@ impl StringNameSpace {
.into(),
&[by],
false,
false,
)
}

Expand All @@ -236,6 +246,7 @@ impl StringNameSpace {
StringFunction::SplitExact { n, inclusive: true }.into(),
&[by],
false,
false,
)
}

Expand All @@ -244,7 +255,7 @@ impl StringNameSpace {
/// keeps the remainder of the string intact. The resulting dtype is [`DataType::Struct`].
pub fn splitn(self, by: Expr, n: usize) -> Expr {
self.0
.map_many_private(StringFunction::SplitN(n).into(), &[by], false)
.map_many_private(StringFunction::SplitN(n).into(), &[by], false, false)
}

#[cfg(feature = "regex")]
Expand All @@ -253,6 +264,7 @@ impl StringNameSpace {
self.0.map_many_private(
FunctionExpr::StringExpr(StringFunction::Replace { n: 1, literal }),
&[pat, value],
false,
true,
)
}
Expand All @@ -263,6 +275,7 @@ impl StringNameSpace {
self.0.map_many_private(
FunctionExpr::StringExpr(StringFunction::Replace { n, literal }),
&[pat, value],
false,
true,
)
}
Expand All @@ -273,6 +286,7 @@ impl StringNameSpace {
self.0.map_many_private(
FunctionExpr::StringExpr(StringFunction::Replace { n: -1, literal }),
&[pat, value],
false,
true,
)
}
Expand Down Expand Up @@ -307,6 +321,7 @@ impl StringNameSpace {
FunctionExpr::StringExpr(StringFunction::StripPrefix),
&[prefix],
false,
false,
)
}

Expand All @@ -316,6 +331,7 @@ impl StringNameSpace {
FunctionExpr::StringExpr(StringFunction::StripSuffix),
&[suffix],
false,
false,
)
}

Expand Down

0 comments on commit 95f3d44

Please sign in to comment.