polars
polars copied to clipboard
Don't panic for "failed to determine supertype of cat and bool"
Checks
- [X] I have checked that this issue has not already been reported.
- [X] I have confirmed this bug exists on the latest version of Polars.
Reproducible example
Fast to reproduce using python
import polars as pl
data = pl.DataFrame(
[
pl.Series("date", ["2000-01-02", "2000-01-02"]).cast(pl.Date),
pl.Series("col1", ["a", "b"], dtype=pl.Categorical),
]
)
# panic
data.filter(pl.col("col1")==True)
# not panic
data.filter(pl.col("col1")==1)
Log output
thread '<unnamed>' panicked at crates/polars-core/src/series/comparison.rs:109:9:
cannot coerce datatypes: ComputeError(ErrString("failed to determine supertype of cat and bool"))
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Issue description
Thought this issue mentioned the same error message, but I just would like polars to throw errors instead of panic. https://github.com/pola-rs/polars/issues/12231#issue-1976908515
Expected behavior
ComputeError: cannot compare string with bool data
Installed versions
rust: 0.39.2 python: polars 0.20.22
The same goes for datetimes:
df = pl.DataFrame({"a": pl.Series([1, 2], dtype=pl.Datetime), "b": pl.Series(["a", "b"], dtype=pl.Categorical)})
df.select(pl.col("a") == pl.col("b"))
PanicException: cannot coerce datatypes: ComputeError(ErrString("failed to determine supertype of datetime[μs] and cat"))
It would be great to throw an error for all "failed to determine supertype of {} and {}", not panic. Hit the following panic today,
ComputeError(ErrString("failed to determine supertype of i64 and cat"))
I added a check which requires the type to be string / enum or categorical otherwise the comparison will return a ComputeError
Thank you so much!!