BUG: Regression - AmbiguousTimeError creating DataFrame
See original GitHub issue-
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.
Code Sample, a copy-pastable example
Pandas 1.25:
import pandas as pd
dt = pd.to_datetime('2019-11-03 01:00:00-0700').tz_convert('America/Los_Angeles')
pd.DataFrame({'dt': dt, 'value': [1]})
# dt value
# 0 2019-11-03 01:00:00-07:00 1
Pandas 1.3:
import pandas as pd
dt = pd.to_datetime('2019-11-03 01:00:00-0700').tz_convert('America/Los_Angeles')
pd.DataFrame({'dt': dt, 'value': [1]})
# File "pandas/_libs/tslibs/tzconversion.pyx", line 284, in pandas._libs.tslibs.tzconversion.tz_localize_to_utc
# pytz.exceptions.AmbiguousTimeError: Cannot infer dst time from 2019-11-03 01:00:00, try using the 'ambiguous' argument
Problem description
The dt
object already has a timezone attribute, so it shouldn’t be converting/inferring at all.
Expected Output
1.25 and 1.3.0 should have the same output.
Output of pd.show_versions()
INSTALLED VERSIONS
commit : f00ed8f47020034e752baf0250483053340971b0 python : 3.7.3.final.0 python-bits : 64 OS : Darwin OS-release : 20.5.0 Version : Darwin Kernel Version 20.5.0: Sat May 8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64 machine : x86_64 processor : i386 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8
pandas : 1.3.0 numpy : 1.21.0 pytz : 2021.1 dateutil : 2.8.1 pip : 21.1.2 setuptools : 57.0.0 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : 2.9.1 (dt dec pq3 ext lo64) jinja2 : None IPython : None pandas_datareader: None bs4 : None bottleneck : None fsspec : None fastparquet : None gcsfs : None matplotlib : 3.2.2 numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyxlsb : None s3fs : None scipy : 1.7.0 sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None xlwt : None numba : None
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (10 by maintainers)
@mzeitlin11 - I think standard practice is to cc the author of a PR where a regression has (or may have) occurred.
cc @jbrockmendel
Best guess remains sequence_to_dt64ns (https://github.com/pandas-dev/pandas/issues/42505#issuecomment-881730012). i’ll try to confirm this guess today.