Skip to content

Commit 0daf438

Browse files
committed
Add type check for filter predicates in DataFrame.filter method
1 parent 27bd8f7 commit 0daf438

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

python/datafusion/dataframe.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,12 @@ def filter(self, *predicates: Expr) -> DataFrame:
426426
"""
427427
df = self.df
428428
for p in predicates:
429+
if not isinstance(p, Expr):
430+
msg = (
431+
f"Expected Expr, got {type(p).__name__}. "
432+
"Use col() or lit() to construct expressions."
433+
)
434+
raise TypeError(msg)
429435
df = df.filter(p.expr)
430436
return DataFrame(df)
431437

python/tests/test_dataframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def test_sort_string_and_expression_equivalent(df):
277277

278278

279279
def test_filter_string_unsupported(df):
280-
with pytest.raises(AttributeError):
280+
with pytest.raises(TypeError, match=r"col\(\) or lit\(\)"):
281281
df.filter("a > 1")
282282

283283

0 commit comments

Comments
 (0)