BUG: v1.3.0 Introduces Unexpected Retyping of Categorical Column with NaN inside #43996
Closed
3 tasks done
Labels
Bug
Categorical
Categorical Data Type
Missing-data
np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Needs Tests
Unit test(s) needed to prevent regressions
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.
Reproducible Example
Issue Description
In the above reproducible example, using pandas v1.3.0 will return a int64 type. However, the column was initially a categorical type.
The behaviour is very esoteric. In v1.2.5, this code works properly and keeps the categorical type. If the column "b" is removed, then it works correctly in v1.3.0. If the np.nan is replaced with a value such as 1 in the "a" column, this code works correctly.
After performing a
git bisect
, the offending commit is 8022743. Its parent (4ecba51) returns a category. Something in 802274... introduces this bug.Expected Behavior
The last print returns a category type, not an int64 which is the correct and expected behaviour.
Installed Versions
INSTALLED VERSIONS
commit : 8022743
python : 3.9.7.final.0
python-bits : 64
OS : Darwin
OS-release : 20.6.0
Version : Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:27 PDT 2021; root:xnu-7195.141.2~5/RELEASE_ARM64_T8101
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8
pandas : 1.3.0.dev0+435.g80227439db
numpy : 1.21.2
pytz : 2021.3
dateutil : 2.8.2
pip : 21.3
setuptools : 58.2.0
Cython : 0.29.24
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: