Timestamp.tz_localize() NonExistentTimeError handling · Issue #8917 · pandas-dev/pandas (original) (raw)
I'm trying to use pandas to speed up timezone conversions on many datetimes and I can't get around NonExistentTimeErrors
. Pandas tz_localize()
seems to ignore the ambiguous
argument for the non existent time case.
Example:
import pytz import pandas
tz = pytz.timezone('Europe/Warsaw') non_existent = datetime.datetime(2015, 3, 29, 2, 30)
tz.normalize(tz.localize(non_existent)) #2015-03-29 03:30:00+02:00
tz.normalize(tz.localize(non_existent, is_dst=False)) #2015-03-29 03:30:00+02:00
pandas.Timestamp(non_existent).tz_localize(tz)
NonExistentTimeError: 2015-03-29 02:30:00
pandas.Timestamp(non_existent).tz_localize(tz, ambiguous=0)
NonExistentTimeError: 2015-03-29 02:30:00
It would be nice if the ambiguous
argument worked the same as is_dst
in pytz. As it is now, it's impossible afaik to reliably localize a series of datetimes using pandas, since any of them might cause a NonExistentTimeError
and there's no way of guiding pandas what to do with such datetimes.
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.5.final.0
python-bits: 64
OS: Linux
OS-release: 3.13.0-39-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
pandas: 0.15.1
nose: 1.3.4
Cython: None
numpy: 1.9.1
scipy: None
statsmodels: None
IPython: 2.3.1
sphinx: 1.2.2
patsy: None
dateutil: 2.2
pytz: 2013.9
bottleneck: None
tables: None
numexpr: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: 0.9
apiclient: 1.3.1
rpy2: None
sqlalchemy: None
pymysql: None
psycopg2: 2.5.4 (dt dec pq3 ext)