Skip to content

Commit

Permalink
fix: Fix struct -> enum is_in (#17622)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jul 14, 2024
1 parent d43df08 commit aa682db
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crates/polars-ops/src/series/ops/is_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ fn is_in_struct(ca_in: &StructChunked, other: &Series) -> PolarsResult<BooleanCh
#[cfg(feature = "dtype-array")]
DataType::Array(_, _) => 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_()?;

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

0 comments on commit aa682db

Please sign in to comment.