Skip to content

Commit

Permalink
fix: Fix filter scalar nulls (#19786)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Nov 15, 2024
1 parent 0e7f07e commit 9df0b79
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/polars-core/src/series/implementations/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ impl SeriesTrait for NullChunked {
// We still allow a length of `1` because it could be `lit(true)`.
polars_ensure!(filter.len() <= 1, ShapeMismatch: "filter's length: {} differs from that of the series: 0", filter.len());
0
} else if filter.len() == 1 {
return match filter.get(0) {
Some(true) => Ok(self.clone().into_series()),
None | Some(false) => Ok(NullChunked::new(self.name.clone(), 0).into_series()),
};
} else {
polars_ensure!(filter.len() == self.len(), ShapeMismatch: "filter's length: {} differs from that of the series: {}", filter.len(), self.len());
filter.sum().unwrap_or(0) as usize
Expand Down
5 changes: 5 additions & 0 deletions py-polars/tests/unit/operations/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,8 @@ def test_invalid_filter_18295() -> None:
.tail(3)
.filter(pl.col("value") > 0),
).sort("code")


def test_filter_19771() -> None:
q = pl.LazyFrame({"a": [None, None]})
assert q.filter(pl.lit(True)).collect()["a"].to_list() == [None, None]

0 comments on commit 9df0b79

Please sign in to comment.