Skip to content

BUG: groupby drops na values of categorical even if dropna=False is set #39573

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

Closed
1 task
atkrueger opened this issue Feb 3, 2021 · 1 comment
Closed
1 task
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@atkrueger
Copy link

  • [ x] I have checked that this issue has not already been reported.

  • [x ] 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.


df = pd.DataFrame({'a': [1,2,3]})
dtype = pd.api.types.CategoricalDtype([1,2])
df['b'] =df.a.astype(dtype)
df.groupby('b',dropna=False).size()

Problem description

observations for categorical variables with na values are dropped from groupby() even if dropna=False is specified.

Expected Output

b
nan 1
1 1
2 1

Actual output

b
1 1
2 1

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 9d598a5
python : 3.9.0.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : AMD64 Family 25 Model 33 Stepping 0, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : en.UTF-8
LOCALE : English_United States.1252

pandas : 1.2.1
numpy : 1.19.5
pytz : 2020.5
dateutil : 2.8.1
pip : 20.3.1
setuptools : 50.3.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
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 : 3.0.0
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@atkrueger atkrueger added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 3, 2021
@rhshadrach
Copy link
Member

rhshadrach commented Feb 3, 2021

Thanks for the report! This is a duplicate of #36327

@rhshadrach rhshadrach marked this as a duplicate of #36327 Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

2 participants