-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: Groupby drops NA even though dropna=False with categorical dtype #48492
Comments
First as a disclaimer, I'm not a regular here but I tried looking into this and I think this is expected behavior but this could be highlighted better maybe as a warning or something. From what I found, NaN cannot be a valid category type. Also, when you specify restricted categorical types like |
Hi @goodyguts , I would like to pick this up. Can you assign it to me? |
Is this a duplicate of #36327 ? |
Yes it is |
Thanks @CBMollerup; the output of the last line in the OP is now:
which is correct. As identified, this was closed by #49652. |
The bug is back in 1.5.1. I didn't find an open issue to fix this is a future release. What's the plan? |
@mdruiter Perhaps @rhshadrach can confirm if that's the case but #49652 is in milestone 2.0 so the bug will not be fixed during 1.5 - however, the solution has been implemented and will be released at some point in the future. |
Yes - that's correct. I believe we're aiming to have a release candidate in early February and then release 2.0 several weeks later. |
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
Issue Description
Although dropna=False, pandas drops the NA in the categorical column. This can be seen because it has not shown up in the produced series.
If the data type is not categorical, the groupby correctly keeps the NA in the column, as shown by
df_normal
Expected Behavior
Installed Versions
INSTALLED VERSIONS
commit : ca60aab
python : 3.9.13.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19043
machine : AMD64
processor : Intel64 Family 6 Model 94 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : English_United Kingdom.1252
pandas : 1.4.4
numpy : 1.23.3
pytz : 2022.2.1
dateutil : 2.8.2
setuptools : 58.1.0
pip : 22.0.4
Cython : None
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
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
markupsafe : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
None
The text was updated successfully, but these errors were encountered: