Skip to content

Commit

Permalink
fix: Fix segfault of is_in (pola-rs#13814)
Browse files Browse the repository at this point in the history
  • Loading branch information
reswqa authored and r-brink committed Jan 24, 2024
1 parent efdc4b1 commit ad75f91
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
13 changes: 11 additions & 2 deletions crates/polars-plan/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
}
}

Expand Down
6 changes: 6 additions & 0 deletions py-polars/tests/unit/operations/test_is_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit ad75f91

Please sign in to comment.