BUG: Categorical dtype in MultiIndex levels is lost during set operations (difference, union, intersection,...) #40080
Labels
Bug
Categorical
Categorical Data Type
Dtype Conversions
Unexpected or buggy dtype conversions
MultiIndex
setops
union, intersection, difference, symmetric_difference
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.
Coming from here, I tried my issue on current HEAD@master and the erroneous behaviour still persists.
Code Sample, a copy-pastable example
Problem description
In contrast to set operations involving flat categorical indices, the same operations on multi-indices with categorical level values revert the result back to the underlying datatype.
Expected Output
The set-operations on multi-indices should preserve the categorical dtype of level values.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : ab687ae
python : 3.8.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : Intel64 Family 6 Model 94 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : de_DE.cp1252
pandas : 1.3.0.dev0+849.gab687aec38
numpy : 1.19.5
pytz : 2021.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 53.1.0
Cython : 0.29.22
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: