Skip to content

Commit 25c2f08

Browse files
jbrockmendelharisbal
authored and
harisbal
committed
separate DatetimeIndex timezone tests (pandas-dev#19545)
1 parent 325df9f commit 25c2f08

File tree

3 files changed

+1047
-1004
lines changed

3 files changed

+1047
-1004
lines changed

pandas/tests/indexes/datetimes/test_arithmetic.py

+26
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,14 @@ def test_dti_shift_no_freq(self):
412412
with pytest.raises(NullFrequencyError):
413413
dti.shift(2)
414414

415+
@pytest.mark.parametrize('tzstr', ['US/Eastern', 'dateutil/US/Eastern'])
416+
def test_dti_shift_localized(self, tzstr):
417+
dr = date_range('2011/1/1', '2012/1/1', freq='W-FRI')
418+
dr_tz = dr.tz_localize(tzstr)
419+
420+
result = dr_tz.shift(1, '10T')
421+
assert result.tz == dr_tz.tz
422+
415423
# -------------------------------------------------------------
416424
# Binary operations DatetimeIndex and timedelta-like
417425

@@ -767,6 +775,24 @@ def test_dti_with_offset_series(self, tz, names):
767775
res3 = dti - other
768776
tm.assert_series_equal(res3, expected_sub)
769777

778+
def test_dti_add_offset_tzaware(self):
779+
dates = date_range('2012-11-01', periods=3, tz='US/Pacific')
780+
offset = dates + pd.offsets.Hour(5)
781+
assert dates[0] + pd.offsets.Hour(5) == offset[0]
782+
783+
# GH#6818
784+
for tz in ['UTC', 'US/Pacific', 'Asia/Tokyo']:
785+
dates = date_range('2010-11-01 00:00', periods=3, tz=tz, freq='H')
786+
expected = DatetimeIndex(['2010-11-01 05:00', '2010-11-01 06:00',
787+
'2010-11-01 07:00'], freq='H', tz=tz)
788+
789+
offset = dates + pd.offsets.Hour(5)
790+
tm.assert_index_equal(offset, expected)
791+
offset = dates + np.timedelta64(5, 'h')
792+
tm.assert_index_equal(offset, expected)
793+
offset = dates + timedelta(hours=5)
794+
tm.assert_index_equal(offset, expected)
795+
770796

771797
@pytest.mark.parametrize('klass,assert_func', [
772798
(Series, tm.assert_series_equal),

0 commit comments

Comments
 (0)