From ad75f9171e4978461147602cfd22858b22db8a13 Mon Sep 17 00:00:00 2001 From: Weijie Guo Date: Fri, 19 Jan 2024 16:06:35 +0800 Subject: [PATCH] fix: Fix segfault of `is_in` (#13814) --- crates/polars-plan/src/utils.rs | 13 +++++++++++-- py-polars/tests/unit/operations/test_is_in.py | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/polars-plan/src/utils.rs b/crates/polars-plan/src/utils.rs index 523f3340d2ea..69787ff15467 100644 --- a/crates/polars-plan/src/utils.rs +++ b/crates/polars-plan/src/utils.rs @@ -151,8 +151,17 @@ pub(crate) fn all_return_scalar(e: &Expr) -> bool { Expr::Literal(lv) => lv.projects_as_scalar(), Expr::Function { options: opt, .. } => opt.returns_scalar, Expr::Agg(_) => true, - Expr::Column(_) => false, - _ => expr_to_leaf_column_exprs_iter(e).all(all_return_scalar), + Expr::Column(_) | Expr::Wildcard => false, + _ => { + let mut empty = true; + for leaf in expr_to_leaf_column_exprs_iter(e) { + if !all_return_scalar(leaf) { + return false; + } + empty = false; + } + !empty + }, } } diff --git a/py-polars/tests/unit/operations/test_is_in.py b/py-polars/tests/unit/operations/test_is_in.py index 7e597e95161f..8805e47f7104 100644 --- a/py-polars/tests/unit/operations/test_is_in.py +++ b/py-polars/tests/unit/operations/test_is_in.py @@ -306,3 +306,9 @@ def test_cat_is_in_with_lit_str_cache_setup(dtype: pl.DataType) -> None: assert_series_equal(pl.Series(["a"], dtype=dtype).is_in(["a"]), pl.Series([True])) assert_series_equal(pl.Series(["b"], dtype=dtype).is_in(["b"]), pl.Series([True])) assert_series_equal(pl.Series(["c"], dtype=dtype).is_in(["c"]), pl.Series([True])) + + +def test_is_in_with_wildcard_13809() -> None: + out = pl.DataFrame({"A": ["B"]}).select(pl.all().is_in(["C"])) + expected = pl.DataFrame({"A": [False]}) + assert_frame_equal(out, expected)