Description
-
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
import pandas as pd
dt = pd.Timestamp("2020-10-25 02:00:00").tz_localize("Europe/Brussels", ambiguous=False).round('min')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pandas/_libs/tslibs/timestamps.pyx", line 489, in pandas._libs.tslibs.timestamps.Timestamp.round
File "pandas/_libs/tslibs/timestamps.pyx", line 443, in pandas._libs.tslibs.timestamps.Timestamp._round
File "pandas/_libs/tslibs/timestamps.pyx", line 826, in pandas._libs.tslibs.timestamps.Timestamp.tz_localize
File "pandas/_libs/tslibs/tzconversion.pyx", line 232, in pandas._libs.tslibs.tzconversion.tz_localize_to_utc
pytz.exceptions.AmbiguousTimeError: Cannot infer dst time from 2020-10-25 02:00:00, try using the 'ambiguous' argument
import pandas as pd
dt = pd.Timestamp("2020-10-25 02:00:00").tz_localize("Europe/Brussels", ambiguous=True).round('min')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pandas/_libs/tslibs/timestamps.pyx", line 489, in pandas._libs.tslibs.timestamps.Timestamp.round
File "pandas/_libs/tslibs/timestamps.pyx", line 443, in pandas._libs.tslibs.timestamps.Timestamp._round
File "pandas/_libs/tslibs/timestamps.pyx", line 826, in pandas._libs.tslibs.timestamps.Timestamp.tz_localize
File "pandas/_libs/tslibs/tzconversion.pyx", line 232, in pandas._libs.tslibs.tzconversion.tz_localize_to_utc
pytz.exceptions.AmbiguousTimeError: Cannot infer dst time from 2020-10-25 02:00:00, try using the 'ambiguous' argument
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
pandas.Timestamp("2020-10-25 02:00:00+01:00").round('min')
respectively
pandas.Timestamp("2020-10-25 02:00:0+02:00").round('min')
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