Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions duckdb/polars_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ def _pl_tree_to_sql(tree: _ExpressionTree) -> str:
"Float64",
"Boolean",
):
if value[dtype] is None:
# JSON has no inf/nan, polars serializes them as null
msg = f"Non-finite {dtype} literals cannot be pushed down"
raise NotImplementedError(msg)
return str(value[dtype])

# Time type
Expand Down
17 changes: 17 additions & 0 deletions tests/fast/arrow/test_polars.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,23 @@ def test_polars_lazy_pushdown_numeric(self, data_type, duckdb_cursor):
valid_filter((pl.col("a") == 100) & (pl.col("b") == 10) & (pl.col("c") == 100))
valid_filter((pl.col("a") == 100) | (pl.col("b") == 1))

@pytest.mark.parametrize("data_type", ["FLOAT", "DOUBLE"])
def test_polars_lazy_pushdown_non_finite_float(self, data_type, duckdb_cursor):
duckdb_cursor.execute(f"CREATE TABLE test_non_finite (a {data_type})")
duckdb_cursor.execute("INSERT INTO test_non_finite VALUES (1), ('inf'), ('-inf'), ('nan'), (NULL)")
lazy_df = duckdb_cursor.table("test_non_finite").pl(lazy=True)
eager_df = lazy_df.collect()

# polars serializes inf/nan literals as JSON null, so they cannot be pushed down
for predicate in (
pl.col("a") < float("inf"),
pl.col("a") > float("-inf"),
pl.col("a") == float("inf"),
pl.col("a") >= float("nan"),
):
invalid_filter(predicate)
pl_testing.assert_frame_equal(lazy_df.filter(predicate).collect(), eager_df.filter(predicate))

def test_polars_lazy_pushdown_bool(self, duckdb_cursor):
duckdb_cursor.execute(
"""
Expand Down