Skip to content

Commit

Permalink
fix is_in for empty lists (#2679)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Feb 17, 2022
1 parent 83d5499 commit 4faa427
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions polars/polars-lazy/src/dsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,15 @@ impl Expr {
#[cfg_attr(docsrs, doc(cfg(feature = "is_in")))]
pub fn is_in(self, other: Expr) -> Self {
let has_literal = has_root_literal_expr(&other);
if has_literal {
if let Expr::Literal(LiteralValue::Series(s)) = &other {
// nothing is in an empty list return all False
if s.is_empty() {
return Expr::Literal(LiteralValue::Boolean(false));
}
}
}

let f = |s: &mut [Series]| {
let left = &s[0];
let other = &s[1];
Expand Down
6 changes: 6 additions & 0 deletions py-polars/tests/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -1892,3 +1892,9 @@ def test_categorical_outer_join() -> None:
expected = pl.DataFrame({"val1": [1], "key1": [42], "key2": ["bar"], "val2": [2]})

assert out.frame_equal(expected)


def test_empty_is_in() -> None:
assert pl.DataFrame({"foo": ["a", "b", "c", "d"]}).filter(
pl.col("foo").is_in([])
).shape == (0, 1)

0 comments on commit 4faa427

Please sign in to comment.