Skip to content
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 summing over infinity values yields NaN #54161

Closed
3 tasks done
FabianHofmann opened this issue Jul 17, 2023 · 3 comments
Closed
3 tasks done

BUG: Groupby summing over infinity values yields NaN #54161

FabianHofmann opened this issue Jul 17, 2023 · 3 comments
Labels
Bug Closing Candidate May be closeable, needs more eyeballs Groupby Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

Comments

@FabianHofmann
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

ser = pd.Series([np.inf, np.inf])

ser.sum() == np.inf # True, all fine



grouper = pd.Series(['a', 'a'])

ser.groupby(grouper).sum() # yields NaN, expected infinity

ser.groupby(grouper).agg("sum") # yields NaN, expected infinity

Issue Description

When performing a groupby operation with a sum over values which include infinity values, the result yield NaN values instead of infinity.

Expected Behavior

Expected infinity as a result (as in accord to directly summing over multiple infinity values)

Installed Versions

INSTALLED VERSIONS

commit : 0f43794
python : 3.11.3.final.0
python-bits : 64
OS : Linux
OS-release : 6.3.3-060303-generic
Version : #202305171336 SMP PREEMPT_DYNAMIC Wed May 17 13:45:19 UTC 2023
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.0.3
numpy : 1.24.3
pytz : 2022.7
dateutil : 2.8.2
setuptools : 66.0.0
pip : 23.0.1
Cython : 0.29.33
pytest : 7.3.1
hypothesis : None
sphinx : 5.0.2
blosc : None
feather : None
xlsxwriter : 3.0.3
lxml.etree : 4.9.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.13.2
pandas_datareader: None
bs4 : 4.12.2
bottleneck : 1.3.5
brotli :
fastparquet : None
fsspec : 2023.4.0
gcsfs : None
matplotlib : 3.7.1
numba : None
numexpr : 2.8.4
odfpy : None
openpyxl : 3.0.10
pandas_gbq : None
pyarrow : 11.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.11.1
snappy : None
sqlalchemy : None
tables : 3.7.0
tabulate : 0.8.10
xarray : 2022.6.1.dev398+ge739df7d
xlrd : 2.0.1
zstandard : 0.19.0
tzdata : 2023.3
qtpy : 2.2.0
pyqt5 : None

@FabianHofmann FabianHofmann added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 17, 2023
@lithomas1
Copy link
Member

lithomas1 commented Jul 17, 2023

This works on main for me.

>>> import pandas as pd
>>> import numpy as np
>>> 
>>> ser = pd.Series([np.inf, np.inf])
>>> 
>>> ser.sum() == np.inf # True, all fine
True
>>> 
>>> 
>>> 
>>> grouper = pd.Series(['a', 'a'])
>>> 
>>> ser.groupby(grouper).sum() # yields NaN, expected infinity
a    inf
dtype: float64
>>> 
>>> ser.groupby(grouper).agg("sum") # yields NaN, expected infinity
a    inf
dtype: float64

@lithomas1 lithomas1 added Groupby Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Closing Candidate May be closeable, needs more eyeballs and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 17, 2023
@lithomas1
Copy link
Member

2.1 will be out in ~ a months time, maybe you can wait until then?

@rhshadrach
Copy link
Member

Closing as a duplicate of #53606 and #43292

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

No branches or pull requests

3 participants