-
-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Description
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
from pandas import Timedelta, Timestamp
df = pd.DataFrame({"col": [1, 2]}, index=pd.to_datetime(["1969-06-01 00:00:00.000000000","1969-06-01 02:01:00.000000001"]))
rule = "7315s"
offset = pd.Timedelta("23min")
df.resample(rule, origin="end_day", offset=offset, closed="right", label="left").agg(None, col_first=("col", "first"), col_count=("col", "count"))
This outputs
col_first col_count
1969-06-01 1 2
Issue Description
The bucket starting at 1969-06-01
should not include the first row from the dataframe. The index is 1969-06-01 00:00:00.000000000
and closed is right
which means that the value is on the opened boundary thus it does not fall into the bucket.
Moreover if the second row is removed we get
import pandas as pd
from pandas import Timedelta, Timestamp
df = pd.DataFrame({"col": [1]}, index=pd.to_datetime(["1969-06-01 00:00:00.000000000"]))
rule = "7315s"
offset = pd.Timedelta("23min")
df.resample(rule, origin="end_day", offset=offset, closed="right", label="left").agg(None, col_first=("col", "first"), col_count=("col", "count"))
Which outputs:
1969-05-31 22:21:05 1 1
Expected Behavior
import pandas as pd
from pandas import Timedelta, Timestamp
df = pd.DataFrame({"col": [1, 2]}, index=pd.to_datetime(["1969-06-01 00:00:00.000000000","1969-06-01 02:01:00.000000001"]))
rule = "7315s"
offset = pd.Timedelta("23min")
df.resample(rule, origin="end_day", offset=offset, closed="right", label="left").agg(None, col_first=("col", "first"), col_count=("col", "count"))
The first row should not be part of the bucket. It's part of the bucket starting at 1969-05-31 22:21:05
but as this is before the first value of the dataframe that bucket is not created.
col_first col_count
1969-06-01 2 1
Installed Versions
INSTALLED VERSIONS
commit : c888af6
python : 3.11.2
python-bits : 64
OS : Linux
OS-release : 6.1.0-38-amd64
Version : #1 SMP PREEMPT_DYNAMIC Debian 6.1.147-1 (2025-08-02)
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.3.1
numpy : 1.26.4
pytz : 2025.2
dateutil : 2.9.0.post0
pip : 25.2
Cython : None
sphinx : None
IPython : 9.3.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.13.4
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : 6.72.4
gcsfs : None
jinja2 : 3.1.6
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : 21.0.0
pyreadstat : None
pytest : 8.4.0
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.2
qtpy : None
pyqt5 : None