-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: astype('category', categories=...) failes on a series of categorical type #10696
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
Comments
Actually I think can just blow away this entire function As the top-level is ok for this. I think an astype to a different astype (with different categories) is ok, though not efficient |
The workaround was due to a bug in pandas, pandas-dev/pandas#10409 that has been fixed. When that was fixed upstream, the local fix led to another bug, pandas-dev/pandas#10696!!
For users looking waiting for a fix, I'm using this inefficient hack of changing a category to an object, then immediately back to a category with new levels.:
|
this is fixed in 0.21.0; @Aylr would you like to put up a validation test?
the original useage with passing |
@jreback happy to write some tests. Should I create a new issue number? What branch should I submit a PR to? |
no need to create a new issue. submit to master (we will then back port to 0.21.1) |
This is actually not really fixed, as the resulting categories differ from the one specified in the dtype in I am not fully sure what is the best behaviour. But either the output categories should be conformed to the passed categories (like (anyhow, since it is not a regression and already present for a longer time, removed from 0.21.1 milestone) |
@jorisvandenbossche this is not fixed at all |
That's what I am saying? |
s.astype('category', categories=['a', 'b', 'c'])
fails when the series is already of Categorical dtype:I am not sure if this should work (it would then be equivalent to
set_categories
?), but in any case the current error message is not informative:The text was updated successfully, but these errors were encountered: