Open Wainberg opened 9 months ago
Yes, this should raise indeed.
Furthermore, why do we allow the casting from Categorical
to Boolean
in the first place? Given that we're not actually allowed casting from String
to Boolean
. The casting result will always be false
for items equals to first
element (which is physically equal to 0
) and true
for the rest, this seems pointless.
FYI this seems to be true for all logical dtypes, not just cats/enums:
import polars as pl
from datetime import date, datetime, time, duration
df = pl.DataFrame({
"date": [date(2024, 1, 1)],
"datetime": [datetime(2024, 1, 1)],
"duration": [timedelta(1)],
"time": [time(1)],
"cat": pl.Series(["a"], dtype=pl.Categorical),
"enum": pl.Series(["a"], dtype=pl.Enum("a"))
})
df.select(pl.all_horizontal(pl.all()))
shape: (1, 1)
┌───────┐
│ date │
│ --- │
│ bool │
╞═══════╡
│ false │
└───────┘
Checks
Reproducible example
Log output
No response
Issue description
all_horizontal and any_horizontal allow Categoricals and Enums, interpreting them as booleans based on whether their underlying integer physical representation is equal to 0.
Expected behavior
This should be an error.
Installed versions