Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't partition group-by with non-scalar literals in agg #20704

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/polars-plan/src/plans/aexpr/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ pub fn can_pre_agg(agg: Node, expr_arena: &Arena<AExpr>, _input_schema: &Schema)
&& !has_aggregation(*falsy)
&& !has_aggregation(*predicate)
},
Column(_) | Len | Literal(_) | Cast { .. } => true,
Literal(lv) => lv.is_scalar(),
Column(_) | Len | Cast { .. } => true,
_ => false,
}
});
Expand Down
12 changes: 12 additions & 0 deletions py-polars/tests/unit/operations/test_group_by.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import typing
from collections import OrderedDict
from datetime import date, datetime, timedelta
from typing import TYPE_CHECKING, Any
Expand Down Expand Up @@ -1182,3 +1183,14 @@ def test_group_by_map_groups_slice_pushdown_20002() -> None:
}
),
)


@typing.no_type_check
def test_group_by_lit_series(capfd: Any, monkeypatch: Any) -> None:
monkeypatch.setenv("POLARS_VERBOSE", "1")
n = 10
df = pl.DataFrame({"x": np.ones(2 * n), "y": n * list(range(2))})
a = np.ones(n, dtype=float)
df.lazy().group_by("y").agg(pl.col("x").dot(a)).collect()
captured = capfd.readouterr().err
assert "are not partitionable" in captured
Loading