Skip to content

Commit 5810306

Browse files
committed
Use tslib._dateutil_gettz
Instead of calculating the platform dependend import each again we can use the compatibility function already present. Signed-off-by: Justin Lecher <[email protected]>
1 parent e8b2ab9 commit 5810306

File tree

6 files changed

+25
-24
lines changed

6 files changed

+25
-24
lines changed

pandas/compat/__init__.py

+17
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
2727
Other items:
2828
* OrderedDefaultDict
29+
* platform checker
2930
"""
3031
# pylint disable=W0611
3132
import functools
@@ -754,3 +755,19 @@ def __missing__(self, key):
754755
def __reduce__(self): # optional, for pickle support
755756
args = self.default_factory if self.default_factory else tuple()
756757
return type(self), args, None, None, list(self.items())
758+
759+
760+
# https://github.com/pydata/pandas/pull/9123
761+
def is_platform_windows():
762+
if sys.platform == 'win32' or sys.platform == 'cygwin':
763+
return True
764+
765+
766+
def is_platform_linux():
767+
if sys.platform == 'linux2':
768+
return True
769+
770+
771+
def is_platform_mac():
772+
if sys.platform == 'darwin':
773+
return True

pandas/tests/test_series.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -5398,10 +5398,8 @@ def test_getitem_setitem_datetime_tz_pytz(self):
53985398
def test_getitem_setitem_datetime_tz_dateutil(self):
53995399
tm._skip_if_no_dateutil();
54005400
from dateutil.tz import tzutc
5401-
if sys.platform != 'win32':
5402-
from dateutil.tz import gettz
5403-
else:
5404-
from dateutil.zoneinfo import gettz
5401+
from pandas.tslib import _dateutil_gettz as gettz
5402+
54055403
tz = lambda x: tzutc() if x == 'UTC' else gettz(x) # handle special case for utc in dateutil
54065404

54075405
from pandas import date_range

pandas/tseries/tests/test_daterange.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,7 @@ def test_month_range_union_tz_pytz(self):
441441
def test_month_range_union_tz_dateutil(self):
442442
_skip_if_windows_python_3()
443443
tm._skip_if_no_dateutil()
444-
if sys.platform != 'win32':
445-
from dateutil.tz import gettz as timezone
446-
else:
447-
from dateutil.zoneinfo import gettz as timezone
444+
from pandas.tslib import _dateutil_gettz as timezone
448445
tz = timezone('US/Eastern')
449446

450447
early_start = datetime(2011, 1, 1)

pandas/tseries/tests/test_period.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,13 @@ def test_timestamp_tz_arg(self):
101101
pytz.timezone('Europe/Brussels').normalize(p).tzinfo)
102102

103103
def test_timestamp_tz_arg_dateutil(self):
104-
if sys.platform != 'win32':
105-
from dateutil.tz import gettz
106-
else
107-
from dateutil.zoneinfo import gettz
104+
from pandas.tslib import _dateutil_gettz as gettz
108105
from pandas.tslib import maybe_get_tz
109106
p = Period('1/1/2005', freq='M').to_timestamp(tz=maybe_get_tz('dateutil/Europe/Brussels'))
110107
self.assertEqual(p.tz, gettz('Europe/Brussels'))
111108

112109
def test_timestamp_tz_arg_dateutil_from_string(self):
113-
if sys.platform != 'win32':
114-
from dateutil.tz import gettz
115-
else
116-
from dateutil.zoneinfo import gettz
110+
from pandas.tslib import _dateutil_gettz as gettz
117111
p = Period('1/1/2005', freq='M').to_timestamp(tz='dateutil/Europe/Brussels')
118112
self.assertEqual(p.tz, gettz('Europe/Brussels'))
119113

pandas/tseries/tests/test_timeseries.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,7 @@ def test_timestamp_to_datetime_explicit_pytz(self):
417417
def test_timestamp_to_datetime_explicit_dateutil(self):
418418
_skip_if_windows_python_3()
419419
tm._skip_if_no_dateutil()
420-
if sys.platform != 'win32':
421-
from dateutil.tz import gettz
422-
else:
423-
from dateutil.zoneinfo import gettz
420+
from pandas.tslib import _dateutil_gettz as gettz
424421
rng = date_range('20090415', '20090519',
425422
tz=gettz('US/Eastern'))
426423

@@ -1810,10 +1807,7 @@ def test_append_concat_tz_explicit_pytz(self):
18101807
def test_append_concat_tz_dateutil(self):
18111808
# GH 2938
18121809
tm._skip_if_no_dateutil()
1813-
if sys.platform != 'win32':
1814-
from dateutil.tz import gettz as timezone
1815-
else:
1816-
from dateutil.zoneinfo import gettz as timezone
1810+
from pandas.tslib import _dateutil_gettz as timezone
18171811

18181812
rng = date_range('5/8/2012 1:45', periods=10, freq='5T',
18191813
tz='dateutil/US/Eastern')

pandas/tslib.pyx

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ from datetime import time as datetime_time
4141
# dateutil compat
4242
from dateutil.tz import (tzoffset, tzlocal as _dateutil_tzlocal, tzfile as _dateutil_tzfile,
4343
tzutc as _dateutil_tzutc)
44+
import sys
4445
if sys.platform != 'win32':
4546
from dateutil.tz import gettz as _dateutil_gettz
4647
else:

0 commit comments

Comments
 (0)