Skip to content

Commit 763e083

Browse files
committed
feat: enhance ensure_expr_list to treat string-like objects as atomic
1 parent c446690 commit 763e083

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

python/datafusion/expr.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,10 @@ def ensure_expr_list(
261261

262262
def _iter(items: Iterable[Expr | Iterable[Expr]]) -> Iterable[expr_internal.Expr]:
263263
for expr in items:
264-
if isinstance(expr, Iterable) and not isinstance(expr, Expr):
264+
if isinstance(expr, Iterable) and not isinstance(
265+
expr, (Expr, str, bytes, bytearray)
266+
):
267+
# Treat string-like objects as atomic to surface standard errors
265268
yield from _iter(expr)
266269
else:
267270
yield ensure_expr(expr)

python/tests/test_expr.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
TransactionStart,
5151
Values,
5252
ensure_expr,
53+
ensure_expr_list,
5354
)
5455

5556

@@ -890,3 +891,18 @@ def test_ensure_expr():
890891
assert ensure_expr(e) is e.expr
891892
with pytest.raises(TypeError, match=re.escape(EXPR_TYPE_ERROR)):
892893
ensure_expr("a")
894+
895+
896+
def test_ensure_expr_list_string():
897+
with pytest.raises(TypeError, match=re.escape(EXPR_TYPE_ERROR)):
898+
ensure_expr_list("a")
899+
900+
901+
def test_ensure_expr_list_bytes():
902+
with pytest.raises(TypeError, match=re.escape(EXPR_TYPE_ERROR)):
903+
ensure_expr_list(b"a")
904+
905+
906+
def test_ensure_expr_list_bytearray():
907+
with pytest.raises(TypeError, match=re.escape(EXPR_TYPE_ERROR)):
908+
ensure_expr_list(bytearray(b"a"))

0 commit comments

Comments
 (0)