Skip to content

BUG: DatetimeIndexResampler inconsistent behaviour between sum() and mean() aggregate functions #50256

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
Armannas opened this issue Dec 14, 2022 · 1 comment
Closed
2 of 3 tasks
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@Armannas
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
index = pd.date_range('1/1/2000', periods=9, freq='30S')
series = pd.Series(range(9), index=index).reset_index().drop([4,5]).set_index('index')

print(series.resample('1T').mean()) # Uses NaN as fill_value for minute 2, because there is no data in that minute

print(series.resample('1T').sum()) # Uses 0 as fill_value for minute 2, which is misleading

Issue Description

I am downsampling with datetime indices where sometimes there are gaps in the timestamps and therefore in those cases there is no data for the aggregate function. I would expect the output to be NaN for these resampled timestamps and this is true for the mean, but the sum function gives 0, which is misleading and ambiguous. Shouldn't it give NaN?

Expected Behavior

I would expect the sum() aggregate function to give as output NaN when there is a resampled timestamp that has no corresponding data in the original series/frame

Installed Versions

INSTALLED VERSIONS

commit : e8093ba
python : 3.8.13.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-135-generic
Version : #152-Ubuntu SMP Wed Nov 23 20:19:22 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.4.3
numpy : 1.22.3
pytz : 2022.5
dateutil : 2.8.2
setuptools : 65.5.0
pip : 22.3
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.4.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : 1.3.5
brotli :
fastparquet : None
fsspec : None
gcsfs : None
markupsafe : 2.1.1
matplotlib : 3.6.1
numba : 0.56.3
numexpr : 2.8.3
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.7.3
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None

@Armannas Armannas added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 14, 2022
@Armannas Armannas changed the title BUG: BUG: DatetimeIndexResampler inconsistent behaviour between sum() and mean() aggregate functions Dec 14, 2022
@mroeschke
Copy link
Member

This is the intended behavior as the sum of an empty interval is defined as 0 in pandas so closing as a usage question

In [28]: pd.Series([]).sum()
Out[28]: 0

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