@@ -902,6 +902,46 @@ def test_utc_with_system_utc(self):
902
902
# check that the time hasn't changed.
903
903
self .assertEqual (ts , ts .tz_convert (dateutil .tz .tzutc ()))
904
904
905
+ def test_tslib_tz_convert_hour_overflow_dst_bug (self ):
906
+ # Regression test for:
907
+ # https://github.com/pydata/pandas/issues/13306
908
+
909
+ # sorted case US/Eastern -> UTC
910
+ ts = ['2008-05-12 09:50:00-04:00' ,
911
+ '2008-12-12 09:50:35-05:00' ,
912
+ '2009-05-12 09:50:32-04:00' ]
913
+ tt = to_datetime (ts ).tz_localize ('US/Eastern' )
914
+ ut = tt .tz_convert ('UTC' )
915
+ expected = np .array ([17 , 19 , 17 ], dtype = np .int32 )
916
+ self .assert_numpy_array_equal (ut .hour , expected )
917
+
918
+ # sorted case UTC -> US/Eastern
919
+ ts = ['2008-05-12 17:50:00' ,
920
+ '2008-12-12 19:50:35' ,
921
+ '2009-05-12 17:50:32' ]
922
+ tt = to_datetime (ts ).tz_localize ('UTC' )
923
+ ut = tt .tz_convert ('US/Eastern' )
924
+ expected = np .array ([13 , 14 , 13 ], dtype = np .int32 )
925
+ self .assert_numpy_array_equal (ut .hour , expected )
926
+
927
+ # unsorted case US/Eastern -> UTC
928
+ ts = ['2008-05-12 09:50:00-04:00' ,
929
+ '2008-12-12 09:50:35-05:00' ,
930
+ '2008-05-12 09:50:32-04:00' ]
931
+ tt = to_datetime (ts ).tz_localize ('US/Eastern' )
932
+ ut = tt .tz_convert ('UTC' )
933
+ expected = np .array ([17 , 19 , 17 ], dtype = np .int32 )
934
+ self .assert_numpy_array_equal (ut .hour , expected )
935
+
936
+ # unsorted case UTC -> US/Eastern
937
+ ts = ['2008-05-12 17:50:00' ,
938
+ '2008-12-12 19:50:35' ,
939
+ '2008-05-12 17:50:32' ]
940
+ tt = to_datetime (ts ).tz_localize ('UTC' )
941
+ ut = tt .tz_convert ('US/Eastern' )
942
+ expected = np .array ([13 , 14 , 13 ], dtype = np .int32 )
943
+ self .assert_numpy_array_equal (ut .hour , expected )
944
+
905
945
def test_tslib_tz_convert_trans_pos_plus_1__bug (self ):
906
946
# Regression test for tslib.tz_convert(vals, tz1, tz2).
907
947
# See https://github.com/pydata/pandas/issues/4496 for details.
0 commit comments