@@ -902,6 +902,88 @@ 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_tz_convert_hour_overflow_dst (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' ,
911
+ '2008-12-12 09:50:35' ,
912
+ '2009-05-12 09:50:32' ]
913
+ tt = to_datetime (ts ).tz_localize ('US/Eastern' )
914
+ ut = tt .tz_convert ('UTC' )
915
+ expected = np .array ([13 , 14 , 13 ], dtype = np .int32 )
916
+ self .assert_numpy_array_equal (ut .hour , expected )
917
+
918
+ # sorted case UTC -> US/Eastern
919
+ ts = ['2008-05-12 13:50:00' ,
920
+ '2008-12-12 14:50:35' ,
921
+ '2009-05-12 13:50:32' ]
922
+ tt = to_datetime (ts ).tz_localize ('UTC' )
923
+ ut = tt .tz_convert ('US/Eastern' )
924
+ expected = np .array ([9 , 9 , 9 ], 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' ,
929
+ '2008-12-12 09:50:35' ,
930
+ '2008-05-12 09:50:32' ]
931
+ tt = to_datetime (ts ).tz_localize ('US/Eastern' )
932
+ ut = tt .tz_convert ('UTC' )
933
+ expected = np .array ([13 , 14 , 13 ], dtype = np .int32 )
934
+ self .assert_numpy_array_equal (ut .hour , expected )
935
+
936
+ # unsorted case UTC -> US/Eastern
937
+ ts = ['2008-05-12 13:50:00' ,
938
+ '2008-12-12 14:50:35' ,
939
+ '2008-05-12 13:50:32' ]
940
+ tt = to_datetime (ts ).tz_localize ('UTC' )
941
+ ut = tt .tz_convert ('US/Eastern' )
942
+ expected = np .array ([9 , 9 , 9 ], dtype = np .int32 )
943
+ self .assert_numpy_array_equal (ut .hour , expected )
944
+
945
+ def test_tz_convert_hour_overflow_dst_timestamps (self ):
946
+ # Regression test for:
947
+ # https://github.com/pydata/pandas/issues/13306
948
+
949
+ tz = self .tzstr ('US/Eastern' )
950
+
951
+ # sorted case US/Eastern -> UTC
952
+ ts = [Timestamp ('2008-05-12 09:50:00' , tz = tz ),
953
+ Timestamp ('2008-12-12 09:50:35' , tz = tz ),
954
+ Timestamp ('2009-05-12 09:50:32' , tz = tz )]
955
+ tt = to_datetime (ts )
956
+ ut = tt .tz_convert ('UTC' )
957
+ expected = np .array ([13 , 14 , 13 ], dtype = np .int32 )
958
+ self .assert_numpy_array_equal (ut .hour , expected )
959
+
960
+ # sorted case UTC -> US/Eastern
961
+ ts = [Timestamp ('2008-05-12 13:50:00' , tz = 'UTC' ),
962
+ Timestamp ('2008-12-12 14:50:35' , tz = 'UTC' ),
963
+ Timestamp ('2009-05-12 13:50:32' , tz = 'UTC' )]
964
+ tt = to_datetime (ts )
965
+ ut = tt .tz_convert ('US/Eastern' )
966
+ expected = np .array ([9 , 9 , 9 ], dtype = np .int32 )
967
+ self .assert_numpy_array_equal (ut .hour , expected )
968
+
969
+ # unsorted case US/Eastern -> UTC
970
+ ts = [Timestamp ('2008-05-12 09:50:00' , tz = tz ),
971
+ Timestamp ('2008-12-12 09:50:35' , tz = tz ),
972
+ Timestamp ('2008-05-12 09:50:32' , tz = tz )]
973
+ tt = to_datetime (ts )
974
+ ut = tt .tz_convert ('UTC' )
975
+ expected = np .array ([13 , 14 , 13 ], dtype = np .int32 )
976
+ self .assert_numpy_array_equal (ut .hour , expected )
977
+
978
+ # unsorted case UTC -> US/Eastern
979
+ ts = [Timestamp ('2008-05-12 13:50:00' , tz = 'UTC' ),
980
+ Timestamp ('2008-12-12 14:50:35' , tz = 'UTC' ),
981
+ Timestamp ('2008-05-12 13:50:32' , tz = 'UTC' )]
982
+ tt = to_datetime (ts )
983
+ ut = tt .tz_convert ('US/Eastern' )
984
+ expected = np .array ([9 , 9 , 9 ], dtype = np .int32 )
985
+ self .assert_numpy_array_equal (ut .hour , expected )
986
+
905
987
def test_tslib_tz_convert_trans_pos_plus_1__bug (self ):
906
988
# Regression test for tslib.tz_convert(vals, tz1, tz2).
907
989
# See https://github.com/pydata/pandas/issues/4496 for details.
0 commit comments