From 8552f60de7ece25195e7f12d501188482831cbfe Mon Sep 17 00:00:00 2001 From: Daniel Imfeld Date: Sat, 25 Jan 2025 02:49:04 -1000 Subject: [PATCH] fix(python): Handle boolean comparisons in Iceberg predicate pushdown (#18199) --- py-polars/polars/io/iceberg.py | 2 ++ py-polars/tests/unit/io/test_iceberg.py | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/py-polars/polars/io/iceberg.py b/py-polars/polars/io/iceberg.py index 5d47eb2f389e..e9fe55d18df8 100644 --- a/py-polars/polars/io/iceberg.py +++ b/py-polars/polars/io/iceberg.py @@ -263,6 +263,8 @@ def _(a: Call) -> Any: f = _convert_predicate(a.func) if f == "field": return args + elif f == "scalar": + return args[0] elif f in _temporal_conversions: # convert from polars-native i64 to ISO8601 string return _temporal_conversions[f](*args).isoformat() diff --git a/py-polars/tests/unit/io/test_iceberg.py b/py-polars/tests/unit/io/test_iceberg.py index 59ba92559459..2b15e5313b3f 100644 --- a/py-polars/tests/unit/io/test_iceberg.py +++ b/py-polars/tests/unit/io/test_iceberg.py @@ -176,3 +176,12 @@ def test_parse_lteq(self) -> None: expr = _to_ast("(pa.compute.field('ts') <= '2023-08-08')") assert _convert_predicate(expr) == LessThanOrEqual("ts", "2023-08-08") + + def test_compare_boolean(self) -> None: + from pyiceberg.expressions import EqualTo + + expr = _to_ast("(pa.compute.field('ts') == pa.compute.scalar(True))") + assert _convert_predicate(expr) == EqualTo("ts", True) + + expr = _to_ast("(pa.compute.field('ts') == pa.compute.scalar(False))") + assert _convert_predicate(expr) == EqualTo("ts", False)