BUG: Groupby iteration replaces None with NaN #55419
Labels
Bug
Closing Candidate
May be closeable, needs more eyeballs
Needs Triage
Issue that has not been reviewed by a pandas team member
Uh oh!
There was an error while loading. Please reload this page.
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
This results in
The problem is I would expect
group_key1
to be the same asgroup_key2
.Issue Description
When iterating over a
pandas.core.groupby.generic.DataFrameGroupBy
object, the returned group values replaceNone
withnan
.Expected Behavior
I would have expected
group_key1
andgroup_key2
to be the same in each iteration. Namely, I would think the value for "a" should always be "None" because that's what's in my DataFrame, but the set of unique values returned when iterating over the result of groupby seems to be replacing Nones with nans.I did do a search for this issue, and I didn't find anything that matched it, but I'm also not confident that I didn't miss anything. I'm also not sure that this isn't expected behavior. Looking at the docstring for
pandas.core.groupby.generic.DataFrameGroupBy
orpandas.core.groupby.generic.DataFrameGroupBy.__iter__
didn't show anything. If this is expected behavior, any pointer to documenation would be helpful.In the meantime simply using the first set of values in the returned group does seem to work fine, but it's odd to me the tuple of "group values" doesn't come directly from the underlying dataframe.
Installed Versions
INSTALLED VERSIONS
commit : e86ed37
python : 3.12.0.final.0
python-bits : 64
OS : Linux
OS-release : 6.2.0-33-generic
Version : #33~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Sep 7 10:33:52 UTC 2
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.1.1
numpy : 1.26.0
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : None
pip : 23.2.1
Cython : None
pytest : 7.4.2
hypothesis : None
sphinx : 7.2.6
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.16.1
pandas_datareader : None
bs4 : None
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
The text was updated successfully, but these errors were encountered: