Skip to content

Commit

Permalink
fix(python, rust): Initialize validity for GroupsProxy::Slice windo…
Browse files Browse the repository at this point in the history
…ws (pola-rs#15509)

Co-authored-by: Ritchie Vink <[email protected]>
  • Loading branch information
rob-sil and ritchie46 authored Apr 6, 2024
1 parent ac1b088 commit 71adbfd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 1 addition & 2 deletions crates/polars-lazy/src/physical_plan/expressions/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ where
} else {
// We don't use a mutable bitmap as bits will have have race conditions!
// A single byte might alias if we write from single threads.
let mut validity: Vec<bool> = Vec::with_capacity(len);
let mut validity: Vec<bool> = vec![false; len];
let validity_ptr = validity.as_mut_ptr();
let sync_ptr_validity = unsafe { SyncPtr::new(validity_ptr) };

Expand Down Expand Up @@ -793,7 +793,6 @@ where
}
// SAFETY: we have written all slots
unsafe { values.set_len(len) }
unsafe { validity.set_len(len) }
let validity = Bitmap::from(validity);
let arr = PrimitiveArray::new(
T::get_dtype().to_physical().to_arrow(true),
Expand Down
20 changes: 20 additions & 0 deletions py-polars/tests/unit/operations/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,26 @@ def test_window_filtered_aggregation() -> None:
assert_frame_equal(out, expected)


def test_window_filtered_false_15483() -> None:
df = pl.DataFrame(
{
"group": ["A", "A"],
"value": [1, 2],
}
)
out = df.with_columns(
pl.col("value").filter(pl.col("group") != "A").arg_max().over("group")
)
expected = pl.DataFrame(
{
"group": ["A", "A"],
"value": [None, None],
},
schema_overrides={"value": pl.UInt32},
)
assert_frame_equal(out, expected)


def test_window_and_cse_10152() -> None:
q = pl.LazyFrame(
{
Expand Down

0 comments on commit 71adbfd

Please sign in to comment.