-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
Closed
Labels
BugCategoricalCategorical Data TypeCategorical Data TypeIndexRelated to the Index class or subclassesRelated to the Index class or subclasses
Description
Pandas version checks
-
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 main branch of pandas.
Reproducible Example
import pandas as pd
pdf = pd.DataFrame(
{
"a": pd.Categorical([1, 2, 3, 1, 2, 3]),
},
index=pd.Categorical([10, 20, 30, 20, 30, 10], categories=[30, 10, 20], ordered=True),
)
pidx = pdf.index
pidx.categories = ["z", "y", "x"]
pidx.dtypeIssue Description
categories set failed
>>> pidx.dtype
CategoricalDtype(categories=[30, 10, 20], ordered=True)
Expected Behavior
>>> pidx.dtype
CategoricalDtype(categories=['z', 'y', 'x'], ordered=True)
(also a behavior before 1.4.x)
Installed Versions
Details
1.4.0+
Metadata
Metadata
Assignees
Labels
BugCategoricalCategorical Data TypeCategorical Data TypeIndexRelated to the Index class or subclassesRelated to the Index class or subclasses