-
-
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
pandas' recommendation on inplace deprecation and categorical column #57104
Comments
I think making rename_categories accept this might make the most sense, the solution you arrived at is probably the best case at the moment but obviously not great |
FWIW I ended up with this (not great either), that I find a bit more readable (but this may depend on the reader 😉): import pandas as pd
df = pd.DataFrame({'col': ["a", "b", "c"]}, dtype="category")
df['col'] = df['col'].astype(object).replace(to_replace="a", value="b").astype("category") |
i think eventually we want users to do |
@jbrockmendel your code gives this warning now:
I'm not sure if you want to remove the warning in this case, or to suggest a different solution? |
The inplace=True keyword was removed from newer Pandas versions, thus the inplace option is replaced by re-assigning the variable, following Pandas recs (pandas-dev/pandas#57104) Changing df['popInd'].cat.set_categories(sim.net.pops.keys(), inplace=True) by df['popInd'] = df['popInd'].cat.set_categories(sim.net.pops.keys()) in analysis/spikes.py
Thanks for this thread.
The warning says:
I would have expected a warning only if I were introducing NEW categories. If I'm just consolidating existing categories, there is no need for the dtype to change (thus, the categories can be preserved, even if some are now unused). Why is a warning necessary at all? |
Working on making scikit-learn's code pandas=2.2.0 compatible, here's a minimal reproducer for where I started:
which results in:
The first pattern doesn't apply here, so from this message, I understand I should do:
But this also fails with:
With a bit of reading docs, it seems I need to do:
which fails with
So
rename_categories
is not the one I want apparently, but reading through the "see also":None of them seem to do what I need to do.
So it seems the way to go would be:
Which is far from what the warning message suggests.
So at the end:
Series.cat
to do this easier?The text was updated successfully, but these errors were encountered: