Skip to content

BUG: Group keys contain NA values despite dropping them in groupby method #55919

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
2 of 3 tasks
olim-ibragimov opened this issue Nov 10, 2023 · 1 comment · Fixed by #55738
Closed
2 of 3 tasks

BUG: Group keys contain NA values despite dropping them in groupby method #55919

olim-ibragimov opened this issue Nov 10, 2023 · 1 comment · Fixed by #55738
Labels
Bug Groupby Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

Comments

@olim-ibragimov
Copy link

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

import pandas as pd
import numpy as np

data = [
    [1, 2, 3],
    [4, np.nan, 6],
    [7, 8, 9],
    [10, 11, 12]
]
cols = ['a', 'b', 'c']

df = pd.DataFrame(data=data, columns=cols)

groupby_cols = ['a', 'b']

group_keys = df.groupby(groupby_cols, dropna=True).groups.keys()

Issue Description

group_keys contains NA values even though the dropna parameter is set to True.

dict_keys([(1, 2.0), (4, nan), (7, 8.0), (10, 11.0)])

Expected Behavior

Expected values for group_keys:

dict_keys([(1, 2.0), (7, 8.0), (10, 11.0)])

Installed Versions

INSTALLED VERSIONS

commit : 2a953cf
python : 3.10.11.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22623
machine : AMD64
processor : AMD64 Family 23 Model 8 Stepping 2, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252

pandas : 2.1.3
numpy : 1.26.1
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.2.0
pip : 23.2.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.17.2
pandas_datareader : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat: None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

@olim-ibragimov olim-ibragimov added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 10, 2023
@rhshadrach
Copy link
Member

Thanks for the report! This would be fixed by #55738

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Groupby Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants