Skip to content

Commit

Permalink
Remove mutual exclusivity from aggregate and returns_scalar
Browse files Browse the repository at this point in the history
  • Loading branch information
mcrumiller committed Feb 17, 2025
1 parent 5e51218 commit bf6dda3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
7 changes: 0 additions & 7 deletions crates/polars-expr/src/expressions/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ impl ApplyExpr {
output_field: Field,
returns_scalar: bool,
) -> Self {
#[cfg(debug_assertions)]
if matches!(options.collect_groups, ApplyOptions::ElementWise)
&& options.flags.contains(FunctionFlags::RETURNS_SCALAR)
{
panic!("expr {:?} is not implemented correctly. 'returns_scalar' and 'elementwise' are mutually exclusive", expr)
}

Self {
inputs,
function,
Expand Down
12 changes: 8 additions & 4 deletions crates/polars-plan/src/dsl/dt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,11 @@ impl DateLikeNameSpace {

/// Round the Datetime/Date range into buckets.
pub fn round(self, every: Expr) -> Expr {
let returns_scalar = all_return_scalar(&self.0);
self.0.map_many_private(
FunctionExpr::TemporalExpr(TemporalFunction::Round),
&[every],
false,
returns_scalar,
None,
)
}
Expand All @@ -254,10 +255,11 @@ impl DateLikeNameSpace {
/// This will take leap years/ months into account.
#[cfg(feature = "offset_by")]
pub fn offset_by(self, by: Expr) -> Expr {
let returns_scalar = all_return_scalar(&self.0);
self.0.map_many_private(
FunctionExpr::TemporalExpr(TemporalFunction::OffsetBy),
&[by],
false,
returns_scalar,
None,
)
}
Expand All @@ -269,20 +271,22 @@ impl DateLikeNameSpace {
ambiguous: Expr,
non_existent: NonExistent,
) -> Expr {
let returns_scalar = all_return_scalar(&self.0);
self.0.map_many_private(
FunctionExpr::TemporalExpr(TemporalFunction::ReplaceTimeZone(time_zone, non_existent)),
&[ambiguous],
false,
returns_scalar,
None,
)
}

/// Combine an existing Date/Datetime with a Time, creating a new Datetime value.
pub fn combine(self, time: Expr, tu: TimeUnit) -> Expr {
let returns_scalar = all_return_scalar(&self.0) && all_return_scalar(&time);
self.0.map_many_private(
FunctionExpr::TemporalExpr(TemporalFunction::Combine(tu)),
&[time],
false,
returns_scalar,
None,
)
}
Expand Down

0 comments on commit bf6dda3

Please sign in to comment.