-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
BUG: Resampling to monthly/quarterly/yearly ignores offset parameter #49697
Comments
I agree that it would be consistent if resample with offset always generated an index where the offset was specified. Currently, the offset is specified for I'm not sure what the expected labels should be for instead of
should it be a)
or b)
or c)
|
The # uniform 1 for every hour in March
hours = pd.Series(1, pd.date_range('2022-03', '2022-04', freq='H', inclusive='left'))
# resampling to "month-end":
hours.resample('M').sum()
# 2022-03-31 744
# Freq: M, dtype: int64
# let's look at that timestamp
hours.resample('M').sum().index[0]
# Timestamp('2022-03-31 00:00:00', freq='M') Now, it's certainly a bit strange, in that |
\take |
Hi, very similar/same issue with business day frequency. Example: s = pd.Series(data=1, index=[
pd.Timestamp('2019-01-01 01:00:00'),
pd.Timestamp('2019-01-01 08:00:00'),
pd.Timestamp('2019-01-02 03:00:00'),
pd.Timestamp('2019-01-02 04:00:00'),
pd.Timestamp('2019-01-03 05:00:00'),
pd.Timestamp('2019-01-03 09:00:00'),
pd.Timestamp('2019-01-04 10:00:00'),
pd.Timestamp('2019-01-04 11:00:00'),
pd.Timestamp('2019-01-05 12:00:00'),
pd.Timestamp('2019-01-05 13:00:00'),
pd.Timestamp('2019-01-06 14:00:00'),
pd.Timestamp('2019-01-06 15:00:00'),
pd.Timestamp('2019-01-07 16:00:00'),
pd.Timestamp('2019-01-07 17:00:00'),
pd.Timestamp('2019-01-08 18:00:00'),
pd.Timestamp('2019-01-08 19:00:00'),
pd.Timestamp('2019-01-09 20:00:00'),
pd.Timestamp('2019-01-09 21:00:00'),
]).sort_index()
# with D the offset works
print(s.resample('D', offset='7H', closed='right', label='right').sum())
# output:
# 2019-01-01 07:00:00 1
# 2019-01-02 07:00:00 3
# 2019-01-03 07:00:00 1
# 2019-01-04 07:00:00 1
# 2019-01-05 07:00:00 2
# 2019-01-06 07:00:00 2
# 2019-01-07 07:00:00 2
# 2019-01-08 07:00:00 2
# 2019-01-09 07:00:00 2
# 2019-01-10 07:00:00 2
# Freq: D, dtype: int64
# with B the offset is ignored
print(s.resample('B', offset='7H', closed='right', label='right').sum())
# output:
# 2019-01-01 2
# 2019-01-02 2
# 2019-01-03 2
# 2019-01-04 2
# 2019-01-07 6
# 2019-01-08 2
# 2019-01-09 2 Many thanks for looking into this! By the way: could be related to #41943. |
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
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
Installed Versions
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
The text was updated successfully, but these errors were encountered: