File tree 3 files changed +15
-5
lines changed
3 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -844,7 +844,7 @@ cdef ndarray _unbox_utcoffsets(object transinfo):
844
844
return arr
845
845
846
846
847
- def tz_localize_array (ndarray[int64_t] vals , object tz ):
847
+ def tz_localize (ndarray[int64_t] vals , object tz ):
848
848
"""
849
849
Localize tzinfo-naive DateRange to given time zone (using pytz). If
850
850
there are ambiguities in the values, raise AmbiguousTimeError.
Original file line number Diff line number Diff line change @@ -968,11 +968,14 @@ def tz_normalize(self, tz):
968
968
-------
969
969
normalized : DatetimeIndex
970
970
"""
971
- from pandas ._tseries import tz_convert
972
971
tz = tools ._maybe_get_tz (tz )
973
- new_dates = tz_convert (self .asi8 , self .tz , tz )
974
- new_dates = new_dates .view ('M8[us]' )
975
972
973
+ if self .tz is None :
974
+ new_dates = lib .tz_localize (self .asi8 , tz )
975
+ else :
976
+ new_dates = lib .tz_convert (self .asi8 , self .tz , tz )
977
+
978
+ new_dates = new_dates .view ('M8[us]' )
976
979
new_dates = new_dates .view (type (self ))
977
980
new_dates .offset = self .offset
978
981
new_dates .tz = tz
@@ -992,7 +995,7 @@ def tz_localize(self, tz):
992
995
"use tz_normalize to convert." )
993
996
tz = tools ._maybe_get_tz (tz )
994
997
995
- new_dates = lib .tz_localize_array (self .asi8 , tz )
998
+ new_dates = lib .tz_localize (self .asi8 , tz )
996
999
new_dates = new_dates .view ('M8[us]' )
997
1000
new_dates = new_dates .view (self .__class__ )
998
1001
new_dates .offset = self .offset
Original file line number Diff line number Diff line change @@ -738,6 +738,13 @@ def test_index_equals_with_tz(self):
738
738
739
739
self .assert_ (not left .equals (right ))
740
740
741
+ def test_tz_normalize_naive (self ):
742
+ rng = date_range ('1/1/2011' , periods = 100 , freq = 'H' )
743
+
744
+ conv = rng .tz_normalize ('US/Pacific' )
745
+ exp = rng .tz_localize ('US/Pacific' )
746
+ self .assert_ (conv .equals (exp ))
747
+
741
748
def test_tz_convert (self ):
742
749
rng = date_range ('1/1/2011' , periods = 100 , freq = 'H' )
743
750
ts = Series (1 , index = rng )
You can’t perform that action at this time.
0 commit comments