polars.Expr.is_in#

Expr.is_in(other: Expr | Collection[Any] | Series, *, nulls_equal: bool = False) → Expr[source]#

Check if elements of this expression are present in the other Series.

engine:In MemoryStreamingDistributed
Parameters:
other

Series or sequence of primitive type.

nulls_equalbool, default False

If True, treat null as a distinct value. Null values will not propagate. Note that Expr.list.contains() and Expr.arr.contains() default to True.

Returns:
Expr

Expression of data type Boolean.

Notes

For supported dtype pairs, lossy conversions do not create matches. Values that would overflow or require rounding match nothing. Cast explicitly to compare integers and floats.

Examples

>>> df = pl.DataFrame(
...     {"sets": [[1, 2, 3], [1, 2], [9, 10]], "optional_members": [1, 2, 3]}
... )
>>> df.with_columns(contains=pl.col("optional_members").is_in("sets"))
shape: (3, 3)
┌───────────┬──────────────────┬──────────┐
│ sets      ┆ optional_members ┆ contains │
│ ---       ┆ ---              ┆ ---      │
│ list[i64] ┆ i64              ┆ bool     │
╞═══════════╪══════════════════╪══════════╡
│ [1, 2, 3] ┆ 1                ┆ true     │
│ [1, 2]    ┆ 2                ┆ true     │
│ [9, 10]   ┆ 3                ┆ false    │
└───────────┴──────────────────┴──────────┘