pd.Timestamp() raises what seems to me an unnecessary error.
import pandas as pd
# this throws error:
>>> pd.Timestamp(pd.Timestamp('2016-10-30 02:44:04.663323'), tz='Europe/Zurich')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pandas/tslib.pyx", line 405, in pandas.tslib.Timestamp.__new__ (pandas/tslib.c:9932)
File "pandas/tslib.pyx", line 1446, in pandas.tslib.convert_to_tsobject (pandas/tslib.c:26009)
File "pandas/tslib.pyx", line 1624, in pandas.tslib._localize_pydatetime (pandas/tslib.c:28710)
File "pandas/tslib.pyx", line 620, in pandas.tslib.Timestamp.tz_localize (pandas/tslib.c:13016)
File "pandas/tslib.pyx", line 4297, in pandas.tslib.tz_localize_to_utc (pandas/tslib.c:70327)
pytz.exceptions.AmbiguousTimeError: Cannot infer dst time from Timestamp('2016-10-30 02:44:04.663323'), try using the 'ambiguous' argument
# this works though
>>> pd.Timestamp(str(pd.Timestamp('2016-10-30 02:44:04.663323')), tz='Europe/Zurich')
Timestamp('2016-10-30 02:44:04.663323+0100', tz='Europe/Zurich')
INSTALLED VERSIONS
------------------
commit: None
python: 3.4.3.final.0
python-bits: 64
OS: Linux
OS-release: 3.19.0-66-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.19.0
nose: None
pip: 1.5.4
setuptools: 3.3
Cython: 0.24.1
numpy: 1.11.2
scipy: 0.17.1
statsmodels: 0.6.1
xarray: None
IPython: 4.0.0
sphinx: None
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2016.7
blosc: None
bottleneck: None
tables: 3.2.2
numexpr: 2.4.6
matplotlib: 1.5.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999
httplib2: 0.9.2
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: 2.6.1 (dt dec pq3 ext lo64)
jinja2: 2.8
boto: None
pandas_datareader: None
Comment From: rockg
There are two hour 2:00-2:59 on that particular day, correct? If so, then it is ambiguous and I would consider the second one that works a bug as it is making assumptions about what hour you may actually want.
Comment From: Dmitrii-I
Correct, that day the DST changed at 2 AM.
Comment From: jreback
This is why we have the ambiguous flag.
In [31]: pd.Timestamp('2016-10-30 02:44:04.663323').tz_localize('Europe/Zurich', ambiguous=0)
Out[31]: Timestamp('2016-10-30 02:44:04.663323+0100', tz='Europe/Zurich')
In [32]: pd.Timestamp('2016-10-30 02:44:04.663323').tz_localize('Europe/Zurich', ambiguous=1)
Out[32]: Timestamp('2016-10-30 02:44:04.663323+0200', tz='Europe/Zurich')
This is just showing our original issue: https://github.com/pandas-dev/pandas/issues/7825
which does incorrect consruction from strings WHEN a tz is specified.
@rockg if you happen to have a chance :>