Skip to content

Commit

Permalink
fix: Skip Batches Expression for boolean literals (#21310)
Browse files Browse the repository at this point in the history
  • Loading branch information
coastalwhite authored Feb 18, 2025
1 parent eae47a4 commit a3072d2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
4 changes: 2 additions & 2 deletions crates/polars-plan/src/plans/aexpr/predicates/skip_batches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ fn aexpr_to_skip_batch_predicate_rec(
if let Some(Some(lv)) = constant_evaluate(e, expr_arena, schema, 0) {
if let Some(av) = lv.to_any_value() {
return match av {
AnyValue::Null => Some(lv!(bool: false)),
AnyValue::Boolean(b) => Some(lv!(bool: b)),
AnyValue::Null => Some(lv!(bool: true)),
AnyValue::Boolean(b) => Some(lv!(bool: !b)),
_ => None,
};
}
Expand Down
10 changes: 10 additions & 0 deletions py-polars/tests/unit/io/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2869,3 +2869,13 @@ def test_nested_string_slice_utf8_21202() -> None:
pl.scan_parquet(f).slice(1, 1).collect().to_series(),
s.slice(1, 1),
)


def test_filter_true_predicate_21204() -> None:
f = io.BytesIO()

df = pl.DataFrame({"a": [1]})
df.write_parquet(f)
f.seek(0)
lf = pl.scan_parquet(f).filter(pl.lit(True))
assert_frame_equal(lf.collect(), df)
27 changes: 26 additions & 1 deletion py-polars/tests/unit/io/test_skip_batch_predicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import polars as pl
from polars.meta import get_index_type
from polars.testing import assert_series_equal
from polars.testing import assert_frame_equal, assert_series_equal
from polars.testing.parametric.strategies import series

if TYPE_CHECKING:
Expand Down Expand Up @@ -55,6 +55,31 @@ def assert_skp_series(
raise


def test_true_false_predicate() -> None:
true_sbp = pl.lit(True)._skip_batch_predicate({})
false_sbp = pl.lit(False)._skip_batch_predicate({})
null_sbp = pl.lit(None)._skip_batch_predicate({})

df = pl.DataFrame({"len": [1]})

out = df.select(
true=true_sbp,
false=false_sbp,
null=null_sbp,
)

assert_frame_equal(
out,
pl.DataFrame(
{
"true": [False],
"false": [True],
"null": [True],
}
),
)


def test_equality() -> None:
assert_skp_series(
"a",
Expand Down

0 comments on commit a3072d2

Please sign in to comment.