Skip to content

BUG: Resampling to "B" frequency with closed="right" and label="right" adds empty bins #59495

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

Open
3 tasks done
torext opened this issue Aug 13, 2024 · 5 comments
Open
3 tasks done
Labels
Bug Resample resample method

Comments

@torext
Copy link
Contributor

torext commented Aug 13, 2024

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

idx = pd.date_range("5Aug2024", "13Aug2024", freq="D")  # Mon to Tue the week after
x = pd.Series(range(len(idx)), idx) + 1

# this gives unexpected output
x.resample("B", closed="right", label="right").sum()

# my expected output of the above is what the following code instead gives
x.resample("B", closed="right", label="right").sum().iloc[:-1]

# curiously, in the following different scenario the output is what I'd expect
x.resample("B", closed="left", label="left").sum()

Issue Description

When resampleing D frequency data to B frequency using closed="right" and label="right" I wouldn't expect to get the trailing empty bin. Indeed, resampling similarly with closed="left" and label="left" doesn't give any leading empty bin (which, even if undesirable, at least would be consistent with the "right" behaviour).

Expected Behavior

The output of the first resampling call in the MRE above should be what is currently output by the second resampling call in the MRE.

Installed Versions

commit : d9cdd2e
python : 3.11.9.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.0-105-generic
Version : #115~20.04.1-Ubuntu SMP Mon Apr 15 17:33:04 UTC 2024
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.2.2
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.9.0
setuptools : 69.5.1
pip : 24.0
Cython : None
pytest : 8.2.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 5.2.1
html5lib : None
pymysql : None
psycopg2 : 2.9.9
jinja2 : 3.1.3
IPython : 8.22.2
pandas_datareader : 0.10.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.4
numba : 0.59.1
numexpr : None
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 15.0.2
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.13.0
sqlalchemy : 2.0.29
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : 2.4.1
pyqt5 : None

@torext torext added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 13, 2024
@rhshadrach rhshadrach added Resample resample method and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 25, 2024
@rhshadrach
Copy link
Member

Confirmed on main. Further investigations and PRs to fix are welcome!

@natmokval
Copy link
Contributor

I would like to work on this.

@torext
Copy link
Contributor Author

torext commented Aug 27, 2024

FWIW, git bisect seems to suggest that 98f5a78 was the commit to introduce the bug.

@natmokval
Copy link
Contributor

FWIW, git bisect seems to suggest that 98f5a78 was the commit to introduce the bug.

Thanks, @torext. I agree it seems like this commit broke the reproducible example. However, I'm not sure we should roll back these changes. I corrected the definition of _get_time_bins, and it fixed the behavior of the example.

@torext
Copy link
Contributor Author

torext commented Jan 11, 2025

Any news on this? Commenting for visibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Resample resample method
Projects
None yet
3 participants