Skip to content

BUG: AmbiguousTimeError when resampling "Atlantic/Azores" to weekly resolution #51211

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

Open
2 of 3 tasks
kdebrab opened this issue Feb 7, 2023 · 1 comment
Open
2 of 3 tasks
Labels
Bug Resample resample method Timezones Timezone data dtype

Comments

@kdebrab
Copy link
Contributor

kdebrab commented Feb 7, 2023

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
ts = pd.Series(1, pd.date_range("2022-10-28", "2022-11-10", tz="Atlantic/Azores", freq="15min"))
ts.resample("W").sum()

Issue Description

Above code raises:

pytz.exceptions.AmbiguousTimeError: Cannot infer dst time from 2022-10-30 00:00:00, try using the 'ambiguous' argument

At first, I thought, maybe that's indeed not possible.

Expected Behavior

But then I saw that no error is raised when resampling to daily resolution:

import pandas as pd
ts = pd.Series(1, pd.date_range("2022-10-28", "2022-11-10", tz="Atlantic/Azores", freq="15min"))
ts.resample("D").sum()

So, if resampling to daily works, shouldn't it also work when resampling to weekly?

Installed Versions

INSTALLED VERSIONS

commit : 2e218d1
python : 3.10.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 140 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_Belgium.1252
pandas : 1.5.3
numpy : 1.24.2
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 67.1.0
pip : 23.0
Cython : None
pytest : 6.2.4
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.0.7
lxml.etree : 4.9.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.4.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : 1.3.6
brotli : None
fastparquet : 2023.1.0
fsspec : 2021.11.0
gcsfs : None
matplotlib : 3.6.2
numba : None
numexpr : 2.8.4
odfpy : None
openpyxl : 3.0.10
pandas_gbq : None
pyarrow : 11.0.0
pyreadstat : None
pyxlsb : None
s3fs : 2021.11.0
scipy : 1.10.0
snappy : None
sqlalchemy : None
tables : None
tabulate : 0.8.10
xarray : 2022.12.0
xlrd : None
xlwt : None
zstandard : None
tzdata : None

@kdebrab kdebrab added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 7, 2023
@topper-123
Copy link
Contributor

This is very weird. I've found that this can be boiled down to:

>>> import pandas as pd
>>> stamp = pd.Timestamp('2022-10-28 00:00:00+0000', tz='Atlantic/Azores')
>>> freq = pd.tseries.offsets.Week(weekday=6)
>>> stamp + freq
AmbiguousTimeError: Cannot infer dst time from 2022-10-30 00:00:00, try using the 'ambiguous' argument

The issue above is that the DST switch happens between 2022-10-30 00:00:00 to 2022-10-30 00:01:00 and it complains about it being badly defined.

I'm not knowledgeable enough about DST to know the correct behavior, i.e. if we should use ambiguous or the above addition should pass and give the same time 7 days forward.

So, I'll leave this open as a bug. We could use some input and/or a PR to fix this.

@topper-123 topper-123 added Timezones Timezone data dtype Resample resample method and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Resample resample method Timezones Timezone data dtype
Projects
None yet
Development

No branches or pull requests

2 participants