Skip to content

Unnecessary pytz.exceptions.AmbiguousTimeError #14959

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

Closed
Dmitrii-I opened this issue Dec 22, 2016 · 3 comments
Closed

Unnecessary pytz.exceptions.AmbiguousTimeError #14959

Dmitrii-I opened this issue Dec 22, 2016 · 3 comments
Labels
Duplicate Report Duplicate issue or pull request Timezones Timezone data dtype

Comments

@Dmitrii-I
Copy link

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

@rockg
Copy link
Contributor

rockg commented Dec 22, 2016

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.

@Dmitrii-I
Copy link
Author

Correct, that day the DST changed at 2 AM.

@jreback
Copy link
Contributor

jreback commented Dec 22, 2016

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:
#7825

which does incorrect consruction from strings WHEN a tz is specified.

@rockg if you happen to have a chance :>

@jreback jreback closed this as completed Dec 22, 2016
@jreback jreback added Duplicate Report Duplicate issue or pull request Timezones Timezone data dtype labels Dec 22, 2016
@jreback jreback added this to the No action milestone Dec 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request Timezones Timezone data dtype
Projects
None yet
Development

No branches or pull requests

3 participants