Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

BUG: df reassignment following reorder_categories changed behavior in 1.1.0rc0 #35369

Copy link
Copy link
Closed
@MaozGelbart

Description

@MaozGelbart
Issue body actions
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

import pandas as pd

h = pd.Series(list("mn")).astype("category")
df = pd.DataFrame({"h":h})

df.h = df.h.cat.reorder_categories(["n", "m"])
print(df.h.cat.categories)

h = h.cat.reorder_categories(["n","m"])
print(h.cat.categories)

Problem description

Output with 1.1.0rc0:

Index(['m', 'n'], dtype='object')
Index(['n', 'm'], dtype='object')

The assignment of the reordered series back into the dataframe seems to remove the new order. This has changed from 1.0.5 but I could not find a note on this under the release notes.

Expected Output

As with 1.0.5:

Index(['n', 'm'], dtype='object')
Index(['n', 'm'], dtype='object')

Output of pd.show_versions()

INSTALLED VERSIONS

commit : bfac136
python : 3.8.3.final.0
python-bits : 64
OS : Darwin
OS-release : 19.5.0
Version : Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8

pandas : 1.1.0rc0
numpy : 1.19.0
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 49.2.0.post20200712
Cython : None
pytest : 5.4.3
hypothesis : None
sphinx : 2.3.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.15.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.0
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugCategoricalCategorical Data TypeCategorical Data TypeRegressionFunctionality that used to work in a prior pandas versionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.