REGR: Replacing a category with itself replaces it with np.nan #33288
Labels
Categorical
Categorical Data Type
Regression
Functionality that used to work in a prior pandas version
Milestone
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
Operating on the categorical array directly, i.e.
pd.Categorical(["a", "b"]).replace("a", "a")
yields the same result.Problem description
Replacing a category with itself replaces it with
np.nan
. This problem was introduced with 1.0.0.Expected Output
I would have expected the behavior from 0.25.3:
Note that if we work with lists, we get
which is also not what I would expect, because we're now losing the dtype. This behavior has been described elsewhere (e.g. #31734 (comment)) and it's consistent with 0.25.3.
Output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: