Skip to content

Commit

Permalink
fix: fix nullable filter mask in group_by (#11207)
Browse files Browse the repository at this point in the history
  • Loading branch information
reswqa authored Sep 20, 2023
1 parent 4390604 commit 9ff5140
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/polars-lazy/src/physical_plan/expressions/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl PhysicalExpr for FilterExpr {
let predicate = predicate_s.bool()?;

// All values true - don't do anything.
if predicate.all() {
if let Some(true) = predicate.all_kleene() {
return Ok(ac_s);
}
// All values false - create empty groups.
Expand Down
16 changes: 16 additions & 0 deletions py-polars/tests/unit/operations/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ def test_melt_values_predicate_pushdown() -> None:
).to_dict(False) == {"id": [1], "variable": ["asset_key_1"], "value": ["123"]}


def test_group_by_filter_all_true() -> None:
df = pl.DataFrame(
{
"name": ["a", "a", "b", "b"],
"type": [None, 1, 1, None],
"order": [1, 2, 3, 4],
}
)
out = (
df.group_by("name")
.agg([pl.col("order").filter(pl.col("type") == 1).n_unique().alias("n_unique")])
.select("n_unique")
)
assert out.to_dict(False) == {"n_unique": [1, 1]}


def test_filter_is_in_4572() -> None:
df = pl.DataFrame({"id": [1, 2, 1, 2], "k": ["a"] * 2 + ["b"] * 2})
expected = (
Expand Down

0 comments on commit 9ff5140

Please sign in to comment.