From dcf5bc855599e7dd80a5060f4bb1986e95f022bb Mon Sep 17 00:00:00 2001 From: Justin Lecher Date: Sun, 21 Dec 2014 19:31:04 +0100 Subject: [PATCH] Use tz.gettz() instead of zoneinfo.gettz() zoneinfo.gettz() seems to have problems (1 & 2) on system which do not install the zoninfo tarball (e.g. Debian, Gentoo and Fedora) but rely on the system zoneinfo files. This results in test failures (3 & 4) tz.gettz() doesn't suffer from this problem. 1 https://github.com/dateutil/dateutil/issues/8 2 https://github.com/dateutil/dateutil/issues/11 3 https://github.com/pydata/pandas/issues/9059 4 https://github.com/pydata/pandas/issues/8639 Signed-off-by: Justin Lecher --- pandas/tests/test_series.py | 2 +- pandas/tseries/tests/test_daterange.py | 2 +- pandas/tseries/tests/test_period.py | 4 ++-- pandas/tseries/tests/test_timeseries.py | 4 ++-- pandas/tslib.pyx | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py index 22f8aee1e0a4e..9b2b49895a498 100644 --- a/pandas/tests/test_series.py +++ b/pandas/tests/test_series.py @@ -5398,7 +5398,7 @@ def test_getitem_setitem_datetime_tz_pytz(self): def test_getitem_setitem_datetime_tz_dateutil(self): tm._skip_if_no_dateutil(); from dateutil.tz import tzutc - from dateutil.zoneinfo import gettz + from dateutil.tz import gettz tz = lambda x: tzutc() if x == 'UTC' else gettz(x) # handle special case for utc in dateutil from pandas import date_range diff --git a/pandas/tseries/tests/test_daterange.py b/pandas/tseries/tests/test_daterange.py index 841d81c15b4e9..b05aa618d1efb 100644 --- a/pandas/tseries/tests/test_daterange.py +++ b/pandas/tseries/tests/test_daterange.py @@ -441,7 +441,7 @@ def test_month_range_union_tz_pytz(self): def test_month_range_union_tz_dateutil(self): _skip_if_windows_python_3() tm._skip_if_no_dateutil() - from dateutil.zoneinfo import gettz as timezone + from dateutil.tz import gettz as timezone tz = timezone('US/Eastern') early_start = datetime(2011, 1, 1) diff --git a/pandas/tseries/tests/test_period.py b/pandas/tseries/tests/test_period.py index 70c706fc66398..a2abb22ed9a6e 100644 --- a/pandas/tseries/tests/test_period.py +++ b/pandas/tseries/tests/test_period.py @@ -104,12 +104,12 @@ def test_timestamp_tz_arg_dateutil(self): import dateutil from pandas.tslib import maybe_get_tz p = Period('1/1/2005', freq='M').to_timestamp(tz=maybe_get_tz('dateutil/Europe/Brussels')) - self.assertEqual(p.tz, dateutil.zoneinfo.gettz('Europe/Brussels')) + self.assertEqual(p.tz, dateutil.tz.gettz('Europe/Brussels')) def test_timestamp_tz_arg_dateutil_from_string(self): import dateutil p = Period('1/1/2005', freq='M').to_timestamp(tz='dateutil/Europe/Brussels') - self.assertEqual(p.tz, dateutil.zoneinfo.gettz('Europe/Brussels')) + self.assertEqual(p.tz, dateutil.tz.gettz('Europe/Brussels')) def test_timestamp_nat_tz(self): t = Period('NaT', freq='M').to_timestamp() diff --git a/pandas/tseries/tests/test_timeseries.py b/pandas/tseries/tests/test_timeseries.py index 0c4961d80a5f4..3895e800353c1 100644 --- a/pandas/tseries/tests/test_timeseries.py +++ b/pandas/tseries/tests/test_timeseries.py @@ -419,7 +419,7 @@ def test_timestamp_to_datetime_explicit_dateutil(self): tm._skip_if_no_dateutil() import dateutil rng = date_range('20090415', '20090519', - tz=dateutil.zoneinfo.gettz('US/Eastern')) + tz=dateutil.tz.gettz('US/Eastern')) stamp = rng[0] dtval = stamp.to_pydatetime() @@ -1807,7 +1807,7 @@ def test_append_concat_tz_explicit_pytz(self): def test_append_concat_tz_dateutil(self): # GH 2938 tm._skip_if_no_dateutil() - from dateutil.zoneinfo import gettz as timezone + from dateutil.tz import gettz as timezone rng = date_range('5/8/2012 1:45', periods=10, freq='5T', tz='dateutil/US/Eastern') diff --git a/pandas/tslib.pyx b/pandas/tslib.pyx index 40dbbd7584c7a..315e349a60923 100644 --- a/pandas/tslib.pyx +++ b/pandas/tslib.pyx @@ -41,7 +41,7 @@ from datetime import time as datetime_time # dateutil compat from dateutil.tz import (tzoffset, tzlocal as _dateutil_tzlocal, tzfile as _dateutil_tzfile, tzutc as _dateutil_tzutc) -from dateutil.zoneinfo import gettz as _dateutil_gettz +from dateutil.tz import gettz as _dateutil_gettz from pytz.tzinfo import BaseTzInfo as _pytz_BaseTzInfo from pandas.compat import parse_date, string_types, PY3, iteritems