Skip to content

Commit

Permalink
remove special aggregate implementation for binary expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Mar 23, 2022
1 parent ad6d121 commit e7095a2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
1 change: 1 addition & 0 deletions polars/polars-lazy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ test = [
"abs",
"parquet",
"ipc",
"dtype-date",
]

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions polars/polars-lazy/src/dsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,12 +639,12 @@ impl Expr {

/// Drop null values
pub fn drop_nulls(self) -> Self {
self.map(|s| Ok(s.drop_nulls()), GetOutput::same_type())
self.apply(|s| Ok(s.drop_nulls()), GetOutput::same_type())
}

/// Drop NaN values
pub fn drop_nans(self) -> Self {
self.map(
self.apply(
|s| match s.dtype() {
DataType::Float32 => {
let ca = s.f32()?;
Expand Down
26 changes: 3 additions & 23 deletions polars/polars-lazy/src/physical_plan/expressions/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,29 +288,9 @@ impl PhysicalAggregation for BinaryExpr {
groups: &GroupsProxy,
state: &ExecutionState,
) -> Result<Option<Series>> {
match (self.left.as_agg_expr(), self.right.as_agg_expr()) {
(Ok(left), Ok(right)) => {
let (left_agg, right_agg) = POOL.install(|| {
rayon::join(
|| left.aggregate(df, groups, state),
|| right.aggregate(df, groups, state),
)
});
let right_agg = right_agg?;
left_agg?
.and_then(|left| right_agg.map(|right| apply_operator(&left, &right, self.op)))
.transpose()
}
(_, _) => Err(PolarsError::ComputeError(
format!(
"this binary expression is not an aggregation: {:?}
pherhaps you should add an aggregation like, '.sum()', '.min()', '.mean()', etc.
if you really want to collect this binary expression, use `.list()`",
self.expr
)
.into(),
)),
}
let mut ac = self.evaluate_on_groups(df, groups, state)?;
let s = ac.aggregated();
Ok(Some(s))
}
}

Expand Down
17 changes: 17 additions & 0 deletions polars/tests/it/lazy/expressions/arity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use super::*;

#[test]
#[cfg(feature = "unique_counts")]
fn test_list_broadcast() {
// simply test if this runs
df![
"g" => [1, 1, 1],
"a" => [1, 2, 3],
]
.unwrap()
.lazy()
.groupby([col("g")])
.agg([col("a").unique_counts() * count()])
.collect()
.unwrap();
}
1 change: 1 addition & 0 deletions polars/tests/it/lazy/expressions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod arity;
mod is_in;
mod slice;
mod window;
Expand Down

0 comments on commit e7095a2

Please sign in to comment.