Skip to content

Commit

Permalink
fix window function braodcasting
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 10, 2024
1 parent 96c8816 commit e1735d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/polars-expr/src/expressions/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,10 @@ impl PhysicalExpr for WindowExpr {
match self.determine_map_strategy(ac.agg_state(), sorted_keys, &gb)? {
Nothing => {
let mut out = ac.flat_naive().into_owned();

if ac.is_literal() {
out = out.new_from_index(0, df.height())
}
cache_gb(gb, state, &cache_key);
if let Some(name) = &self.out_name {
out.rename(name.clone());
Expand Down
7 changes: 7 additions & 0 deletions py-polars/tests/unit/operations/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,10 @@ def test_window_17308() -> None:
assert df.select(pl.col("A").sum(), pl.col("B").sum().over("grp")).to_dict(
as_series=False
) == {"A": [3, 3], "B": [3, 4]}


def test_lit_window_broadcast() -> None:
# the broadcast should happen in the window function
assert pl.DataFrame({"a": [1, 1, 2]}).select(pl.lit(0).over("a").alias("a"))[
"a"
].to_list() == [0, 0, 0]

0 comments on commit e1735d9

Please sign in to comment.