polars icon indicating copy to clipboard operation
polars copied to clipboard

Don't panic for "failed to determine supertype of cat and bool"

Open jshinonome opened this issue 10 months ago • 2 comments

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

jshinonome avatar Apr 23 '24 12:04 jshinonome

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"))

daviskirk avatar Apr 24 '24 14:04 daviskirk

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"))

jshinonome avatar Apr 28 '24 09:04 jshinonome

I added a check which requires the type to be string / enum or categorical otherwise the comparison will return a ComputeError

c-peters avatar Apr 29 '24 09:04 c-peters

Thank you so much!!

jshinonome avatar Apr 29 '24 09:04 jshinonome