diff --git a/py-polars/polars/_utils/parse_expr_input.py b/py-polars/polars/_utils/parse_expr_input.py index a9ee8c80c794..a56a4c178385 100644 --- a/py-polars/polars/_utils/parse_expr_input.py +++ b/py-polars/polars/_utils/parse_expr_input.py @@ -71,7 +71,7 @@ def _parse_inputs_as_iterable( def _is_iterable(input: Any | Iterable[Any]) -> bool: return isinstance(input, Iterable) and not isinstance( - input, (str, bytes, pl.Series) + input, (str, bytes, pl.Series, pl.DataFrame, pl.LazyFrame) ) diff --git a/py-polars/tests/unit/utils/test_parse_expr_input.py b/py-polars/tests/unit/utils/test_parse_expr_input.py index a17debfc94cb..2f9dd008d966 100644 --- a/py-polars/tests/unit/utils/test_parse_expr_input.py +++ b/py-polars/tests/unit/utils/test_parse_expr_input.py @@ -9,6 +9,7 @@ from polars._utils.parse_expr_input import parse_as_expression from polars._utils.wrap import wrap_expr from polars.testing import assert_frame_equal +from polars.exceptions import InvalidOperationError def assert_expr_equal(result: pl.Expr, expected: pl.Expr) -> None: @@ -78,3 +79,13 @@ def test_parse_as_expression_structify_multiple_outputs() -> None: result = wrap_expr(parse_as_expression(pl.col("*"), structify=True)) expected = pl.struct("a", "b") assert_expr_equal(result, expected) + + +def test_raise_with_df_in_context() -> None: + df = pl.DataFrame({"a": [1, 2, 3]}) + df2 = pl.DataFrame({"b": [2, 3, 4]}) + with pytest.raises(InvalidOperationError): + df.with_columns(df2) + + with pytest.raises(InvalidOperationError): + df.select([df2])