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

-6
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

+11-10
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

+2-1
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

+3-2
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

+1-1
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

+1-1
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

+1-1
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

+3-3
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

+2-2
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

+1-1
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

pandas/tests/tseries/test_offsets.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
to_datetime, DateParseError)
3434
import pandas.tseries.offsets as offsets
3535
from pandas.io.pickle import read_pickle
36+
from pandas._libs.tslibs import timezones
3637
from pandas._libs.tslib import normalize_date, NaT, Timestamp, Timedelta
3738
import pandas._libs.tslib as tslib
3839
import pandas.util.testing as tm
@@ -288,7 +289,7 @@ def _check_offsetfunc_works(self, offset, funcname, dt, expected,
288289

289290
for tz in self.timezones:
290291
expected_localize = expected.tz_localize(tz)
291-
tz_obj = tslib.maybe_get_tz(tz)
292+
tz_obj = timezones.maybe_get_tz(tz)
292293
dt_tz = tslib._localize_pydatetime(dt, tz_obj)
293294

294295
result = func(dt_tz)

pandas/tests/tseries/test_timezones.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from pandas.core.indexes.datetimes import bdate_range, date_range
1919
from pandas.core.dtypes.dtypes import DatetimeTZDtype
2020
from pandas._libs import tslib
21+
from pandas._libs.tslibs import timezones
2122
from pandas import (Index, Series, DataFrame, isna, Timestamp, NaT,
2223
DatetimeIndex, to_datetime)
2324
from pandas.util.testing import (assert_frame_equal, assert_series_equal,
@@ -943,7 +944,7 @@ def tz(self, tz):
943944
Use tslib.maybe_get_tz so that we get the filename on the tz right
944945
on windows. See #7337.
945946
"""
946-
return tslib.maybe_get_tz('dateutil/' + tz)
947+
return timezones.maybe_get_tz('dateutil/' + tz)
947948

948949
def tzstr(self, tz):
949950
""" Construct a timezone string from a string. Overridden in subclass
@@ -962,7 +963,7 @@ def test_utc_with_system_utc(self):
962963
# Skipped on win32 due to dateutil bug
963964
tm._skip_if_windows()
964965

965-
from pandas._libs.tslib import maybe_get_tz
966+
from pandas._libs.tslibs.timezones import maybe_get_tz
966967

967968
# from system utc to real utc
968969
ts = Timestamp('2001-01-05 11:56', tz=maybe_get_tz('dateutil/UTC'))
@@ -1133,7 +1134,7 @@ def test_tzlocal(self):
11331134
assert ts.tz == dateutil.tz.tzlocal()
11341135
assert "tz='tzlocal()')" in repr(ts)
11351136

1136-
tz = tslib.maybe_get_tz('tzlocal()')
1137+
tz = timezones.maybe_get_tz('tzlocal()')
11371138
assert tz == dateutil.tz.tzlocal()
11381139

11391140
# get offset using normal datetime for test
@@ -1176,12 +1177,13 @@ def test_cache_keys_are_distinct_for_pytz_vs_dateutil(self):
11761177
if tz_name == 'UTC':
11771178
# skip utc as it's a special case in dateutil
11781179
continue
1179-
tz_p = tslib.maybe_get_tz(tz_name)
1180-
tz_d = tslib.maybe_get_tz('dateutil/' + tz_name)
1180+
tz_p = timezones.maybe_get_tz(tz_name)
1181+
tz_d = timezones.maybe_get_tz('dateutil/' + tz_name)
11811182
if tz_d is None:
11821183
# skip timezones that dateutil doesn't know about.
11831184
continue
1184-
assert tslib.p_tz_cache_key(tz_p) != tslib.p_tz_cache_key(tz_d)
1185+
assert (timezones.p_tz_cache_key(tz_p) !=
1186+
timezones.p_tz_cache_key(tz_d))
11851187

11861188

11871189
class TestTimeZones(object):
@@ -1743,13 +1745,13 @@ def compare_local_to_utc(tz_didx, utc_didx):
17431745

17441746
# Check empty array
17451747
result = tslib.tz_convert(np.array([], dtype=np.int64),
1746-
tslib.maybe_get_tz('US/Eastern'),
1747-
tslib.maybe_get_tz('Asia/Tokyo'))
1748+
timezones.maybe_get_tz('US/Eastern'),
1749+
timezones.maybe_get_tz('Asia/Tokyo'))
17481750
tm.assert_numpy_array_equal(result, np.array([], dtype=np.int64))
17491751

17501752
# Check all-NaT array
17511753
result = tslib.tz_convert(np.array([tslib.iNaT], dtype=np.int64),
1752-
tslib.maybe_get_tz('US/Eastern'),
1753-
tslib.maybe_get_tz('Asia/Tokyo'))
1754+
timezones.maybe_get_tz('US/Eastern'),
1755+
timezones.maybe_get_tz('Asia/Tokyo'))
17541756
tm.assert_numpy_array_equal(result, np.array(
17551757
[tslib.iNaT], dtype=np.int64))

0 commit comments

Comments
 (0)