-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: round() on tz-aware DateTimeIndex (spanning DST switch) throws AmbiguousTimeError as if tz-unaware #37485
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
Comments
Note that a workaround exists by converting to UTC first: >>> pd.Timestamp("2020-10-25 02:00:00").tz_localize("Europe/Brussels", ambiguous=True).astimezone("UTC").round('min').astimezone("Europe/Brussels") |
@mroeschke enough of these are building up that I think we can make the Day -> DayDST switch and call it a bugfix instead of an API change. what do you think? |
100% in support for I think it would affect several of operations though (IIRC |
Same issue with import pandas as pd
pd.Timestamp('2021-10-31 01:30:12+02', tzinfo=dateutil.tz.gettz('Europe/Brussels')).ceil('H')
|
see #44287 this is as expected |
Yes, and the documentation will be updated in #44357 (available in version 1.4) to reflect this. Closing. |
A similar behavior has occurred in Pandas: [1.4.1].
AmbiguousTimeError Traceback (most recent call last) ~\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\indexes\datetimelike.py in shift(self, periods, freq) ~\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\arrays\datetimelike.py in _time_shift(self, periods, freq) ~\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\arrays\datetimes.py in _generate_range(cls, start, end, periods, freq, tz, normalize, ambiguous, nonexistent, inclusive) ~\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas_libs\tslibs\tzconversion.pyx in pandas._libs.tslibs.tzconversion.tz_localize_to_utc() AmbiguousTimeError: Cannot infer dst time from 2021-11-07 01:00:00, try using the 'ambiguous' argument |
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Problem description
A localized Timestamp does not give an error when rounding.
A Series of a localized DateTimeIndex shouldn't either.
[this should explain why the current behaviour is a problem and why the expected output is a better solution]
Expected Output
Output is expected to be identical as for
respectively
i.e. without AmbiguousTimeError
Output of
pd.show_versions()
[paste the output of
pd.show_versions()
here leaving a blank line after the details tag]INSTALLED VERSIONS
commit : db08276
python : 3.8.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.9.1-050901-generic
Version : #202010170731 SMP Sat Oct 17 07:42:59 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.3
numpy : 1.19.3
pytz : 2020.1
dateutil : 2.8.1
pip : 20.0.2
setuptools : 44.0.0
rest is not installed
The text was updated successfully, but these errors were encountered: