BUG: In 2.1.0 .resample extrapolates indexes to any 'origin' defined with Timestamp · Issue #55064 · pandas-dev/pandas (original) (raw)

Pandas version checks

Reproducible Example

import pandas as pd assert pd.version == '2.1.0'

index = pd.date_range( start=pd.Timestamp("2023-09-08 10:00"), end=pd.Timestamp("2023-09-08 10:20"), freq="10T" ) srs = pd.Series([0, 1, 2], index=index)

srs.index

DatetimeIndex(['2023-09-08 10:00:00', '2023-09-08 10:10:00',

'2023-09-08 10:20:00'],

dtype='datetime64[ns]', freq='10T')

origin = pd.Timestamp("2023-09-08 09:10") srs_rs = srs.resample("19T", origin=origin).sum() srs_rs.index

indexes are extrapolated back to the origin...

DatetimeIndex(['2023-09-08 09:10:00', '2023-09-08 09:29:00',

'2023-09-08 09:48:00', '2023-09-08 10:07:00'],

dtype='datetime64[ns]', freq='19T')

Issue Description

In Pandas 2.1.0 passing 'origin' to Series.resample or DataFrame.resample as a Timestamp results in indexes being extrapolated all the way back to the 'origin', whereas prior to 2.1.0 the first resampled index would always fall within one 'rule' of the first index being resampled.

I suspect it's a bug as there is no change in behaviour with origin="start_day" and I couldn't find anything in the 2.1.0 release notes that suggests the change was intended.

Thanks in advance for looking at this.

Expected Behavior

Would have expected behaviour to be unchanged from 2.0.3:

import pandas as pd assert pd.version == '2.0.3'

index = pd.date_range( start=pd.Timestamp("2023-09-08 10:00"), end=pd.Timestamp("2023-09-08 10:20"), freq="10T" ) srs = pd.Series([0, 1, 2], index=index) srs.index

DatetimeIndex(['2023-09-08 10:00:00', '2023-09-08 10:10:00',
               '2023-09-08 10:20:00'],
              dtype='datetime64[ns]', freq='10T')

origin = pd.Timestamp("2023-09-08 09:10") srs_rs = srs.resample("19T", origin=origin).sum() srs_rs.index # first index is within 1 'rule' of first index being resampled...

DatetimeIndex(['2023-09-08 09:48:00', '2023-09-08 10:07:00'], dtype='datetime64[ns]', freq='19T')

origin="start_day" exhibits no change in behaviour (no extrapolation beyond 1 'rule'). The following is the same for Pandas 2.0.3 and 2.1.0:

srs_rs = srs.resample("19T", origin="start_day").sum() srs_rs.index

DatetimeIndex(['2023-09-08 09:49:00', '2023-09-08 10:08:00'], dtype='datetime64[ns]', freq='19T')

Installed Versions

INSTALLED VERSIONS

commit : ba1cccd
python : 3.9.13.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22621
machine : AMD64
processor : Intel64
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United Kingdom.1252

pandas : 2.1.0
numpy : 1.25.2
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 58.1.0
pip : 23.2.1
Cython : 3.0.0
pytest : 7.4.0
hypothesis : 6.82.0
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.14.0
pandas_datareader : None
bs4 : None
bottleneck : None
dataframe-api-compat: None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : 2.8.5
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : 3.8.0
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None