Skip to content

Commit

Permalink
Some refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
reswqa committed Apr 12, 2024
1 parent d59c930 commit 8a71cbb
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions crates/polars-lazy/src/physical_plan/expressions/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ impl ApplyExpr {
ca: ListChunked,
) -> PolarsResult<AggregationContext<'a>> {
let all_unit_len = all_unit_length(&ca);
if all_unit_len
&& (self.returns_scalar || matches!(ac.state, AggState::AggregatedScalar(_)))
{
if all_unit_len && self.returns_scalar {
ac.with_agg_state(AggState::AggregatedScalar(
ca.explode().unwrap().into_series(),
));
Expand Down Expand Up @@ -356,12 +354,20 @@ impl PhysicalExpr for ApplyExpr {
},
ApplyOptions::GroupWise => self.apply_multiple_group_aware(acs, df),
ApplyOptions::ElementWise => {
if acs.iter().any(|ac| {
matches!(
ac.agg_state(),
AggState::AggregatedList(_) | AggState::AggregatedScalar(_)
)
}) {
let mut has_agg_list = false;
let mut has_agg_scalar = false;
let mut has_not_agg = false;
for ac in &acs {
match ac.state {
AggState::AggregatedList(_) => has_agg_list = true,
AggState::AggregatedScalar(_) => has_agg_scalar = true,
AggState::NotAggregated(_) => has_not_agg = true,
_ => {},
}
}
if has_agg_list {
return self.apply_multiple_group_aware(acs, df);
} else if has_agg_scalar && has_not_agg {
self.apply_multiple_group_aware(acs, df)
} else {
apply_multiple_elementwise(
Expand Down

0 comments on commit 8a71cbb

Please sign in to comment.