Skip to content

Commit

Permalink
fix groups update to match exploded offsets (#3010)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Mar 30, 2022
1 parent 7adf768 commit 874913d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion polars/polars-lazy/src/physical_plan/expressions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ impl<'a> AggregationContext<'a> {
.iter()
.map(|&o| {
let len = (o - previous) as IdxSize;
let new_offset = offset + len;
// explode will fill empty rows with null, so we must increment the group
// offset accordingly
let new_offset = offset + len + (len == 0) as IdxSize;

previous = o;
let out = [offset, len];
offset = new_offset;
Expand Down
4 changes: 2 additions & 2 deletions polars/tests/it/lazy/groupby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ fn test_filter_sort_diff_2984() -> Result<()> {
.groupby([col("group")])
.agg([col("id")
.filter(col("id").lt(lit(3)))
.sort(true)
.sort(false)
.diff(1, Default::default())
.sum()])
.sort("group", Default::default())
.collect()?;

assert_eq!(Vec::from(out.column("id")?.i32()?), &[Some(-1), None]);
assert_eq!(Vec::from(out.column("id")?.i32()?), &[Some(1), None]);
Ok(())
}

0 comments on commit 874913d

Please sign in to comment.