Skip to content

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

Open
@torext

Description

@torext

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions