50
50
from pandas ._libs import (lib , index as libindex , tslib as libts ,
51
51
algos as libalgos , join as libjoin ,
52
52
Timestamp , period as libperiod )
53
-
53
+ from pandas . _libs . tslibs import timezones
54
54
55
55
def _utc ():
56
56
import pytz
@@ -372,7 +372,7 @@ def __new__(cls, data=None,
372
372
tz = subarr .tz
373
373
else :
374
374
if tz is not None :
375
- tz = libts .maybe_get_tz (tz )
375
+ tz = timezones .maybe_get_tz (tz )
376
376
377
377
if (not isinstance (data , DatetimeIndex ) or
378
378
getattr (data , 'tz' , None ) is None ):
@@ -447,17 +447,18 @@ def _generate(cls, start, end, periods, name, offset,
447
447
raise TypeError ('Start and end cannot both be tz-aware with '
448
448
'different timezones' )
449
449
450
- inferred_tz = libts .maybe_get_tz (inferred_tz )
450
+ inferred_tz = timezones .maybe_get_tz (inferred_tz )
451
451
452
452
# these may need to be localized
453
- tz = libts .maybe_get_tz (tz )
453
+ tz = timezones .maybe_get_tz (tz )
454
454
if tz is not None :
455
455
date = start or end
456
456
if date .tzinfo is not None and hasattr (tz , 'localize' ):
457
457
tz = tz .localize (date .replace (tzinfo = None )).tzinfo
458
458
459
459
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 )):
461
462
raise AssertionError ("Inferred time zone not equal to passed "
462
463
"time zone" )
463
464
@@ -593,7 +594,7 @@ def _simple_new(cls, values, name=None, freq=None, tz=None,
593
594
result ._data = values
594
595
result .name = name
595
596
result .offset = freq
596
- result .tz = libts .maybe_get_tz (tz )
597
+ result .tz = timezones .maybe_get_tz (tz )
597
598
result ._reset_identity ()
598
599
return result
599
600
@@ -607,7 +608,7 @@ def tzinfo(self):
607
608
@cache_readonly
608
609
def _timezone (self ):
609
610
""" Comparable timezone both for pytz / dateutil"""
610
- return libts .get_timezone (self .tzinfo )
611
+ return timezones .get_timezone (self .tzinfo )
611
612
612
613
def _has_same_tz (self , other ):
613
614
zzone = self ._timezone
@@ -616,7 +617,7 @@ def _has_same_tz(self, other):
616
617
if isinstance (other , np .datetime64 ):
617
618
# convert to Timestamp as np.datetime64 doesn't have tz attr
618
619
other = Timestamp (other )
619
- vzone = libts .get_timezone (getattr (other , 'tzinfo' , '__no_tz__' ))
620
+ vzone = timezones .get_timezone (getattr (other , 'tzinfo' , '__no_tz__' ))
620
621
return zzone == vzone
621
622
622
623
@classmethod
@@ -1779,7 +1780,7 @@ def tz_convert(self, tz):
1779
1780
TypeError
1780
1781
If DatetimeIndex is tz-naive.
1781
1782
"""
1782
- tz = libts .maybe_get_tz (tz )
1783
+ tz = timezones .maybe_get_tz (tz )
1783
1784
1784
1785
if self .tz is None :
1785
1786
# tz naive, use tz_localize
@@ -1839,7 +1840,7 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'):
1839
1840
else :
1840
1841
raise TypeError ("Already tz-aware, use tz_convert to convert." )
1841
1842
else :
1842
- tz = libts .maybe_get_tz (tz )
1843
+ tz = timezones .maybe_get_tz (tz )
1843
1844
# Convert to UTC
1844
1845
1845
1846
new_dates = libts .tz_localize_to_utc (self .asi8 , tz ,
0 commit comments