Skip to content

BUG: Resampling to monthly/quarterly/yearly ignores offset parameter #49697

Open
@rwijtvliet

Description

@rwijtvliet

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
# Quarterly values at 06:00
quarterly = pd.Series(1.0, pd.date_range('2020-01-01 06:00', freq = 'QS', periods=4))
# 2020-01-01 06:00:00    1.0
# 2020-04-01 06:00:00    1.0
# 2020-07-01 06:00:00    1.0
# 2020-10-01 06:00:00    1.0
# Freq: QS-JAN, dtype: float64

# If we upsample to daily values we need to specify the offset parameter, e.g.
offset = pd.Timedelta('06:00:00')
quarterly.resample('D', offset=offset).asfreq().ffill()
# 2020-01-01 06:00:00    1.0
# 2020-01-02 06:00:00    1.0
# 2020-01-03 06:00:00    1.0
#                       ... 
# 2020-09-29 06:00:00    1.0
# 2020-09-30 06:00:00    1.0
# 2020-10-01 06:00:00    1.0
# Freq: D, Length: 275, dtype: float64

# However, if we upsample to monthly values, this does not work (=bug):
quarterly.resample('MS', offset=offset).asfreq().ffill()
# 2020-01-01   NaN
# 2020-02-01   NaN
# 2020-03-01   NaN
# 2020-04-01   NaN
# 2020-05-01   NaN
# 2020-06-01   NaN
# 2020-07-01   NaN
# 2020-08-01   NaN
# 2020-09-01   NaN
# 2020-10-01   NaN
# Freq: MS, dtype: float64

Issue Description

Resampling to monthly, quarterly, or yearly values does not take the offset parameter into account. This is an issue in both up- and downsampling. For a downsampling example, see here.

Expected Behavior

# 2020-01-01 06:00:00  1.0
# 2020-02-01 06:00:00  1.0
# 2020-03-01 06:00:00  1.0
# 2020-04-01 06:00:00  1.0
# 2020-05-01 06:00:00  1.0
# 2020-06-01 06:00:00  1.0
# 2020-07-01 06:00:00  1.0
# 2020-08-01 06:00:00  1.0
# 2020-09-01 06:00:00  1.0
# 2020-10-01 06:00:00  1.0
# Freq: MS, dtype: float64

Installed Versions

INSTALLED VERSIONS ------------------ commit : 91111fd python : 3.9.13.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.19045 machine : AMD64 processor : Intel64 Family 6 Model 165 Stepping 2, GenuineIntel byteorder : little LC_ALL : None LANG : None LOCALE : de_DE.cp1252

pandas : 1.5.1
numpy : 1.23.4
pytz : 2022.6
dateutil : 2.8.2
setuptools : 63.4.1
pip : 22.2.2
Cython : None
pytest : 7.1.3
hypothesis : None
sphinx : 5.3.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.5.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.6.2
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.10
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : 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