Skip to content

Commit

Permalink
fix: Fix gather len in group-by state (#19586)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Nov 1, 2024
1 parent d2a0441 commit 5053252
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/polars-expr/src/expressions/gather.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl PhysicalExpr for GatherExpr {
};

ac.with_series(taken.into_series(), true, Some(&self.expr))?;
ac.with_update_groups(UpdateGroups::WithGroupsLen);
ac.with_update_groups(UpdateGroups::WithSeriesLen);
Ok(ac)
}

Expand Down
12 changes: 12 additions & 0 deletions py-polars/tests/unit/operations/test_gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,15 @@ def test_gather_array_outer_validity_19482() -> None:
expect = pl.Series([[1], None], dtype=pl.Array(pl.Int64, 1))
assert_series_equal(s, expect)
assert_series_equal(s.gather([0, 1]), expect)


def test_gather_len_19561() -> None:
N = 4
df = pl.DataFrame({"foo": ["baz"] * N, "bar": range(N)})
idxs = pl.int_range(1, N).repeat_by(pl.int_range(1, N)).flatten()
gather = pl.col.bar.gather(idxs).alias("gather")

assert df.group_by("foo").agg(gather.len()).to_dict(as_series=False) == {
"foo": ["baz"],
"gather": [6],
}

0 comments on commit 5053252

Please sign in to comment.