diff --git a/crates/polars-ops/src/series/ops/is_in.rs b/crates/polars-ops/src/series/ops/is_in.rs index cd773926fbdb..153eabc1a0c1 100644 --- a/crates/polars-ops/src/series/ops/is_in.rs +++ b/crates/polars-ops/src/series/ops/is_in.rs @@ -506,6 +506,8 @@ fn is_in_struct(ca_in: &StructChunked, other: &Series) -> PolarsResult is_in_struct_array(ca_in, other), _ => { + let ca_in = ca_in.cast(&ca_in.dtype().to_physical()).unwrap(); + let ca_in = ca_in.struct_()?; let other = other.cast(&other.dtype().to_physical()).unwrap(); let other = other.struct_()?; diff --git a/py-polars/tests/unit/operations/test_is_in.py b/py-polars/tests/unit/operations/test_is_in.py index 546a58d3b6fb..5e497c439823 100644 --- a/py-polars/tests/unit/operations/test_is_in.py +++ b/py-polars/tests/unit/operations/test_is_in.py @@ -390,3 +390,17 @@ def test_cat_list_is_in_from_single_str(val: str | None, expected: list[bool]) - res = df.select(pl.col("li").list.contains(pl.lit(val, dtype=pl.String))) expected_df = pl.DataFrame({"li": expected}) assert_frame_equal(res, expected_df) + + +def is_in_struct_enum_17618() -> None: + df = pl.DataFrame() + dtype = pl.Enum(categories=["HBS"]) + df = df.insert_column(0, pl.Series("category", [], dtype=dtype)) + assert df.filter( + pl.struct("category").is_in( + pl.Series( + [{"category": "HBS"}], + dtype=pl.Struct({"category": df["category"].dtype}), + ) + ) + ).shape == (0, 1)