@@ -787,6 +787,64 @@ def test_utc_with_system_utc(self):
787
787
# check that the time hasn't changed.
788
788
self .assertEqual (ts , ts .tz_convert (dateutil .tz .tzutc ()))
789
789
790
+ def test_tslib_tz_convert_trans_pos_plus_1__bug (self ):
791
+ # Regression test for tslib.tz_convert(vals, tz1, tz2).
792
+ # See https://github.com/pydata/pandas/issues/4496 for details.
793
+ for freq , n in [('H' , 1 ), ('T' , 60 ), ('S' , 3600 )]:
794
+ idx = date_range (datetime (2011 , 3 , 26 , 23 ), datetime (2011 , 3 , 27 , 1 ), freq = freq )
795
+ idx = idx .tz_localize ('UTC' )
796
+ idx = idx .tz_convert ('Europe/Moscow' )
797
+
798
+ expected = np .repeat (np .array ([3 , 4 , 5 ]), np .array ([n , n , 1 ]))
799
+ self .assert_numpy_array_equal (idx .hour , expected )
800
+
801
+ def test_tslib_tz_convert_dst (self ):
802
+ for freq , n in [('H' , 1 ), ('T' , 60 ), ('S' , 3600 )]:
803
+ # Start DST
804
+ idx = date_range ('2014-03-08 23:00' , '2014-03-09 09:00' , freq = freq , tz = 'UTC' )
805
+ idx = idx .tz_convert ('US/Eastern' )
806
+ expected = np .repeat (np .array ([18 , 19 , 20 , 21 , 22 , 23 , 0 , 1 , 3 , 4 , 5 ]),
807
+ np .array ([n , n , n , n , n , n , n , n , n , n , 1 ]))
808
+ self .assert_numpy_array_equal (idx .hour , expected )
809
+
810
+ idx = date_range ('2014-03-08 18:00' , '2014-03-09 05:00' , freq = freq , tz = 'US/Eastern' )
811
+ idx = idx .tz_convert ('UTC' )
812
+ expected = np .repeat (np .array ([23 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]),
813
+ np .array ([n , n , n , n , n , n , n , n , n , n , 1 ]))
814
+ self .assert_numpy_array_equal (idx .hour , expected )
815
+
816
+ # End DST
817
+ idx = date_range ('2014-11-01 23:00' , '2014-11-02 09:00' , freq = freq , tz = 'UTC' )
818
+ idx = idx .tz_convert ('US/Eastern' )
819
+ expected = np .repeat (np .array ([19 , 20 , 21 , 22 , 23 , 0 , 1 , 1 , 2 , 3 , 4 ]),
820
+ np .array ([n , n , n , n , n , n , n , n , n , n , 1 ]))
821
+ self .assert_numpy_array_equal (idx .hour , expected )
822
+
823
+ idx = date_range ('2014-11-01 18:00' , '2014-11-02 05:00' , freq = freq , tz = 'US/Eastern' )
824
+ idx = idx .tz_convert ('UTC' )
825
+ expected = np .repeat (np .array ([22 , 23 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]),
826
+ np .array ([n , n , n , n , n , n , n , n , n , n , n , n , 1 ]))
827
+ self .assert_numpy_array_equal (idx .hour , expected )
828
+
829
+ # daily
830
+ # Start DST
831
+ idx = date_range ('2014-03-08 00:00' , '2014-03-09 00:00' , freq = 'D' , tz = 'UTC' )
832
+ idx = idx .tz_convert ('US/Eastern' )
833
+ self .assert_numpy_array_equal (idx .hour , np .array ([19 , 19 ]))
834
+
835
+ idx = date_range ('2014-03-08 00:00' , '2014-03-09 00:00' , freq = 'D' , tz = 'US/Eastern' )
836
+ idx = idx .tz_convert ('UTC' )
837
+ self .assert_numpy_array_equal (idx .hour , np .array ([5 , 5 ]))
838
+
839
+ # End DST
840
+ idx = date_range ('2014-11-01 00:00' , '2014-11-02 00:00' , freq = 'D' , tz = 'UTC' )
841
+ idx = idx .tz_convert ('US/Eastern' )
842
+ self .assert_numpy_array_equal (idx .hour , np .array ([20 , 20 ]))
843
+
844
+ idx = date_range ('2014-11-01 00:00' , '2014-11-02 000:00' , freq = 'D' , tz = 'US/Eastern' )
845
+ idx = idx .tz_convert ('UTC' )
846
+ self .assert_numpy_array_equal (idx .hour , np .array ([4 , 4 ]))
847
+
790
848
791
849
class TestTimeZoneCacheKey (tm .TestCase ):
792
850
def test_cache_keys_are_distinct_for_pytz_vs_dateutil (self ):
0 commit comments