-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cast(pl.Enum, strict=False)
fails when casting from another enum/categorical
#14900
Comments
I put p-low since it seems this is a corner case that wouldn't be too tough to work around. As a tangent: Is it better (from the issue author's perspective) to be in "needs triage' or "P-low" |
It's not super easy to work around without going back through |
Re: your question, I'm not sure how to answer that. I would obviously personally prefer "needs triage" (haven't assigned a priority) to "low priority", since the latter is basically a worst-case of the former from a "this is going to be resolved quickly" perspective. But the priority itself should be based on the assessment of the maintainers regarding how important they feel this update would be to the general population, and not on my desire for it to be resolved. |
I'm assuming that your real goal isn't to get the null values and that you're more interested in getting them together without casting them to string and back. Does this idea help?
As to the priority I'm rethinking it given that it should really respect the |
My use case is building a new enum from an old list of values with slightly different categories: import polars as pl
from polars import col, when
orig_enum = pl.Enum(["a", "b", "c"])
new_enum = pl.Enum(["a", "b", "d"])
df = pl.DataFrame({"a": pl.Series(["a", "b", "c"], dtype=old_enum)})
df.with_columns(
when(col("a") == "c").then(pl.lit("d", dtype=new_enum))
.otherwise(col("a").cast(new_enum))
) Then |
alright I got carried away
so with that then you can do
Since the Enum is part of the schema it works with eager and lazy |
Haha thanks @deanm0000. I actually have an incoming PR, but there might be discussion on it in which case I may resort to your carried-away solutions :D. |
Checks
Reproducible example
Issue description
#14728 enabled non-strict casting to an Enum, whereby elements not in the Enum set are set to null. However, this fails when the source series is already a categorical or enum.
Installed versions
The text was updated successfully, but these errors were encountered: