-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
DEPR: inplace dtype-changing methods on Categorical #37643
Comments
Also set_categories. All those methods have a |
Hard to think of a use case where changing a Categorical dtype in place would be intended, but easy to think of use cases where it would lead to unexpected errors. Probably best to deprecate this and raise. |
Hi, I've created a pull request to solve this issue for |
take |
I am not sure we should deprecate the inplace ability for all of those. For example, for |
Agreed. It can be expensive to copy all the data (codes) when not necessary. |
i was thinking we'd get a view on the codes, just a new Categorical object. This should be cheap. |
I've added another pull request to deprecate |
@jorisvandenbossche @TomAugspurger the inplace ops here seem like a footgun; sure they may have a small cost (but could be mitgated as @jbrockmendel indicates), but we don't allow anything like this on any other accessor operation. +1 on deprecation. |
@jbrockmendel |
Without looking at the implementation: Categorical.replace should be able to alter the values (i.e. |
It would be nice to be able to control this behaviour, maybe with As a side note, I like the ability to modify these inplace – though I see that mutating the type (if that's what |
all the checkboxes are checked; closing |
Re-opening, never addressed the "option to return a view" part of the issue. |
I'm having second thoughts about this. We currently allow setting categories using The category-setting is a pretty convenient pattern, not sure how to trade this off against modifying-dtype-inplace being an antipattern. |
Categorical.remove_unused_categories
Deprecate inplace in Categorical.remove_unused_categories #37918Cateogrical.remove_categories
Deprecate inplace in Categorical.remove_categories #37981Categorical.add_categories
Deprecate inplace in Categorical.add_categories. #41118Categorical.reorder_categories
Deprecate inplace in Categorical.reorder_categories. #41133Categorical.rename_categories
Deprecate inplace in Categorical.rename_categories #41186Categorical.set_categories
Deprecate inplace in Categorical.set_categories. #41307The ability to alter an existing array's dtype is a footgun. We can return a new object without having to make a copy.
The text was updated successfully, but these errors were encountered: