Skip to content

Commit 1f5f7a5

Browse files
committed
Code Review jreback
1 parent 82f263a commit 1f5f7a5

File tree

1 file changed

+58
-16
lines changed

1 file changed

+58
-16
lines changed

pandas/tseries/tests/test_timezones.py

+58-16
Original file line numberDiff line numberDiff line change
@@ -902,46 +902,88 @@ def test_utc_with_system_utc(self):
902902
# check that the time hasn't changed.
903903
self.assertEqual(ts, ts.tz_convert(dateutil.tz.tzutc()))
904904

905-
def test_tslib_tz_convert_hour_overflow_dst_bug(self):
905+
def test_tz_convert_hour_overflow_dst(self):
906906
# Regression test for:
907907
# https://github.com/pydata/pandas/issues/13306
908908

909909
# 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']
910+
ts = ['2008-05-12 09:50:00',
911+
'2008-12-12 09:50:35',
912+
'2009-05-12 09:50:32']
913913
tt = to_datetime(ts).tz_localize('US/Eastern')
914914
ut = tt.tz_convert('UTC')
915-
expected = np.array([17, 19, 17], dtype=np.int32)
915+
expected = np.array([13, 14, 13], dtype=np.int32)
916916
self.assert_numpy_array_equal(ut.hour, expected)
917917

918918
# 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']
919+
ts = ['2008-05-12 13:50:00',
920+
'2008-12-12 14:50:35',
921+
'2009-05-12 13:50:32']
922922
tt = to_datetime(ts).tz_localize('UTC')
923923
ut = tt.tz_convert('US/Eastern')
924-
expected = np.array([13, 14, 13], dtype=np.int32)
924+
expected = np.array([9, 9, 9], dtype=np.int32)
925925
self.assert_numpy_array_equal(ut.hour, expected)
926926

927927
# 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']
928+
ts = ['2008-05-12 09:50:00',
929+
'2008-12-12 09:50:35',
930+
'2008-05-12 09:50:32']
931931
tt = to_datetime(ts).tz_localize('US/Eastern')
932932
ut = tt.tz_convert('UTC')
933-
expected = np.array([17, 19, 17], dtype=np.int32)
933+
expected = np.array([13, 14, 13], dtype=np.int32)
934934
self.assert_numpy_array_equal(ut.hour, expected)
935935

936936
# 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']
937+
ts = ['2008-05-12 13:50:00',
938+
'2008-12-12 14:50:35',
939+
'2008-05-12 13:50:32']
940940
tt = to_datetime(ts).tz_localize('UTC')
941941
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')
942975
expected = np.array([13, 14, 13], dtype=np.int32)
943976
self.assert_numpy_array_equal(ut.hour, expected)
944977

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+
945987
def test_tslib_tz_convert_trans_pos_plus_1__bug(self):
946988
# Regression test for tslib.tz_convert(vals, tz1, tz2).
947989
# See https://github.com/pydata/pandas/issues/4496 for details.

0 commit comments

Comments
 (0)