Skip to content

Commit 5fa670e

Browse files
committed
Import timezone funcs directly from tslibs.timezones
1 parent acf6dbd commit 5fa670e

File tree

12 files changed

+39
-39
lines changed

12 files changed

+39
-39
lines changed

pandas/_libs/tslib.pyx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,6 @@ from tslibs.timezones cimport (
105105
get_timezone, get_utcoffset, maybe_get_tz,
106106
get_dst_info
107107
)
108-
from tslibs.timezones import ( # noqa
109-
get_timezone, get_utcoffset, maybe_get_tz,
110-
p_tz_cache_key, dst_cache,
111-
unbox_utcoffsets,
112-
dateutil_gettz
113-
)
114108

115109

116110
cdef inline object create_timestamp_from_ts(

pandas/core/indexes/datetimes.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
from pandas._libs import (lib, index as libindex, tslib as libts,
5151
algos as libalgos, join as libjoin,
5252
Timestamp, period as libperiod)
53-
53+
from pandas._libs.tslibs import timezones
5454

5555
def _utc():
5656
import pytz
@@ -372,7 +372,7 @@ def __new__(cls, data=None,
372372
tz = subarr.tz
373373
else:
374374
if tz is not None:
375-
tz = libts.maybe_get_tz(tz)
375+
tz = timezones.maybe_get_tz(tz)
376376

377377
if (not isinstance(data, DatetimeIndex) or
378378
getattr(data, 'tz', None) is None):
@@ -447,17 +447,18 @@ def _generate(cls, start, end, periods, name, offset,
447447
raise TypeError('Start and end cannot both be tz-aware with '
448448
'different timezones')
449449

450-
inferred_tz = libts.maybe_get_tz(inferred_tz)
450+
inferred_tz = timezones.maybe_get_tz(inferred_tz)
451451

452452
# these may need to be localized
453-
tz = libts.maybe_get_tz(tz)
453+
tz = timezones.maybe_get_tz(tz)
454454
if tz is not None:
455455
date = start or end
456456
if date.tzinfo is not None and hasattr(tz, 'localize'):
457457
tz = tz.localize(date.replace(tzinfo=None)).tzinfo
458458

459459
if tz is not None and inferred_tz is not None:
460-
if not libts.get_timezone(inferred_tz) == libts.get_timezone(tz):
460+
if not (timezones.get_timezone(inferred_tz) ==
461+
timezones.get_timezone(tz)):
461462
raise AssertionError("Inferred time zone not equal to passed "
462463
"time zone")
463464

@@ -593,7 +594,7 @@ def _simple_new(cls, values, name=None, freq=None, tz=None,
593594
result._data = values
594595
result.name = name
595596
result.offset = freq
596-
result.tz = libts.maybe_get_tz(tz)
597+
result.tz = timezones.maybe_get_tz(tz)
597598
result._reset_identity()
598599
return result
599600

@@ -607,7 +608,7 @@ def tzinfo(self):
607608
@cache_readonly
608609
def _timezone(self):
609610
""" Comparable timezone both for pytz / dateutil"""
610-
return libts.get_timezone(self.tzinfo)
611+
return timezones.get_timezone(self.tzinfo)
611612

612613
def _has_same_tz(self, other):
613614
zzone = self._timezone
@@ -616,7 +617,7 @@ def _has_same_tz(self, other):
616617
if isinstance(other, np.datetime64):
617618
# convert to Timestamp as np.datetime64 doesn't have tz attr
618619
other = Timestamp(other)
619-
vzone = libts.get_timezone(getattr(other, 'tzinfo', '__no_tz__'))
620+
vzone = timezones.get_timezone(getattr(other, 'tzinfo', '__no_tz__'))
620621
return zzone == vzone
621622

622623
@classmethod
@@ -1779,7 +1780,7 @@ def tz_convert(self, tz):
17791780
TypeError
17801781
If DatetimeIndex is tz-naive.
17811782
"""
1782-
tz = libts.maybe_get_tz(tz)
1783+
tz = timezones.maybe_get_tz(tz)
17831784

17841785
if self.tz is None:
17851786
# tz naive, use tz_localize
@@ -1839,7 +1840,7 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'):
18391840
else:
18401841
raise TypeError("Already tz-aware, use tz_convert to convert.")
18411842
else:
1842-
tz = libts.maybe_get_tz(tz)
1843+
tz = timezones.maybe_get_tz(tz)
18431844
# Convert to UTC
18441845

18451846
new_dates = libts.tz_localize_to_utc(self.asi8, tz,

pandas/core/tools/datetimes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from collections import MutableMapping
44

55
from pandas._libs import lib, tslib
6+
from pandas._libs.tslibs.timezones import get_timezone
67

78
from pandas.core.dtypes.common import (
89
_ensure_object,
@@ -44,7 +45,7 @@ def _infer_tzinfo(start, end):
4445
def _infer(a, b):
4546
tz = a.tzinfo
4647
if b and b.tzinfo:
47-
if not (tslib.get_timezone(tz) == tslib.get_timezone(b.tzinfo)):
48+
if not (get_timezone(tz) == get_timezone(b.tzinfo)):
4849
raise AssertionError('Inputs must both have the same timezone,'
4950
' {timezone1} != {timezone2}'
5051
.format(timezone1=tz, timezone2=b.tzinfo))

pandas/io/pytables.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from pandas.core.computation.pytables import Expr, maybe_expression
4848

4949
from pandas._libs import tslib, algos, lib
50+
from pandas._libs.tslibs import timezones
5051

5152
from distutils.version import LooseVersion
5253

@@ -4379,7 +4380,7 @@ def _get_info(info, name):
43794380

43804381
def _get_tz(tz):
43814382
""" for a tz-aware type, return an encoded zone """
4382-
zone = tslib.get_timezone(tz)
4383+
zone = timezones.get_timezone(tz)
43834384
if zone is None:
43844385
zone = tz.utcoffset().total_seconds()
43854386
return zone
@@ -4401,7 +4402,7 @@ def _set_tz(values, tz, preserve_UTC=False, coerce=False):
44014402
if tz is not None:
44024403
name = getattr(values, 'name', None)
44034404
values = values.ravel()
4404-
tz = tslib.get_timezone(_ensure_decoded(tz))
4405+
tz = timezones.get_timezone(_ensure_decoded(tz))
44054406
values = DatetimeIndex(values, name=name)
44064407
if values.tz is None:
44074408
values = values.tz_localize('UTC').tz_convert(tz)

pandas/tests/indexes/datetimes/test_date_range.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def test_range_tz_dateutil(self):
394394
# see gh-2906
395395

396396
# Use maybe_get_tz to fix filename in tz under dateutil.
397-
from pandas._libs.tslib import maybe_get_tz
397+
from pandas._libs.tslibs.timezones import maybe_get_tz
398398
tz = lambda x: maybe_get_tz('dateutil/' + x)
399399

400400
start = datetime(2011, 1, 1, tzinfo=tz('US/Eastern'))

pandas/tests/indexes/datetimes/test_setops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def test_month_range_union_tz_pytz(self):
325325
def test_month_range_union_tz_dateutil(self):
326326
tm._skip_if_windows_python_3()
327327

328-
from pandas._libs.tslib import dateutil_gettz as timezone
328+
from pandas._libs.tslibs.timezones import dateutil_gettz as timezone
329329
tz = timezone('US/Eastern')
330330

331331
early_start = datetime(2011, 1, 1)

pandas/tests/io/test_pytables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5421,7 +5421,7 @@ def test_append_with_timezones_dateutil(self):
54215421

54225422
# use maybe_get_tz instead of dateutil.tz.gettz to handle the windows
54235423
# filename issues.
5424-
from pandas._libs.tslib import maybe_get_tz
5424+
from pandas._libs.tslibs.timezones import maybe_get_tz
54255425
gettz = lambda x: maybe_get_tz('dateutil/' + x)
54265426

54275427
# as columns

pandas/tests/scalar/test_period.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ def test_timestamp_tz_arg(self):
245245
assert p.tz == exp.tz
246246

247247
def test_timestamp_tz_arg_dateutil(self):
248-
from pandas._libs.tslib import dateutil_gettz as gettz
249-
from pandas._libs.tslib import maybe_get_tz
248+
from pandas._libs.tslibs.timezones import dateutil_gettz as gettz
249+
from pandas._libs.tslibs.timezones import maybe_get_tz
250250
for case in ['dateutil/Europe/Brussels', 'dateutil/Asia/Tokyo',
251251
'dateutil/US/Pacific']:
252252
p = Period('1/1/2005', freq='M').to_timestamp(
@@ -264,7 +264,7 @@ def test_timestamp_tz_arg_dateutil(self):
264264
assert p.tz == exp.tz
265265

266266
def test_timestamp_tz_arg_dateutil_from_string(self):
267-
from pandas._libs.tslib import dateutil_gettz as gettz
267+
from pandas._libs.tslibs.timezones import dateutil_gettz as gettz
268268
p = Period('1/1/2005',
269269
freq='M').to_timestamp(tz='dateutil/Europe/Brussels')
270270
assert p.tz == gettz('Europe/Brussels')

pandas/tests/scalar/test_timestamp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import pandas.util.testing as tm
1818
from pandas.tseries import offsets, frequencies
1919
from pandas._libs import tslib, period
20-
from pandas._libs.tslib import get_timezone
20+
from pandas._libs.tslibs.timezones import get_timezone
2121

2222
from pandas.compat import lrange, long
2323
from pandas.util.testing import assert_series_equal
@@ -1295,7 +1295,7 @@ def test_timestamp_to_datetime_explicit_pytz(self):
12951295
def test_timestamp_to_datetime_explicit_dateutil(self):
12961296
tm._skip_if_windows_python_3()
12971297

1298-
from pandas._libs.tslib import dateutil_gettz as gettz
1298+
from pandas._libs.tslibs.timezones import dateutil_gettz as gettz
12991299
rng = date_range('20090415', '20090519', tz=gettz('US/Eastern'))
13001300

13011301
stamp = rng[0]

pandas/tests/series/test_indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ def test_getitem_setitem_datetime_tz_pytz(self):
387387

388388
def test_getitem_setitem_datetime_tz_dateutil(self):
389389
from dateutil.tz import tzutc
390-
from pandas._libs.tslib import dateutil_gettz as gettz
390+
from pandas._libs.tslibs.timezones import dateutil_gettz as gettz
391391

392392
tz = lambda x: tzutc() if x == 'UTC' else gettz(
393393
x) # handle special case for utc in dateutil

0 commit comments

Comments
 (0)