Skip to content

Commit 21c6cec

Browse files
further clean-up tests
1 parent aebc892 commit 21c6cec

File tree

2 files changed

+35
-37
lines changed

2 files changed

+35
-37
lines changed

pandas/tseries/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ def __sub__(self, other):
657657
elif isinstance(other, DatetimeIndex):
658658
return self._sub_datelike(other)
659659
elif isinstance(other, Index):
660-
raise TypeError("cannot add {typ1} and {typ2}"
660+
raise TypeError("cannot subtract {typ1} and {typ2}"
661661
.format(typ1=type(self).__name__,
662662
typ2=type(other).__name__))
663663
elif isinstance(other, (DateOffset, timedelta, np.timedelta64,

pandas/tseries/tests/test_base.py

+34-36
Original file line numberDiff line numberDiff line change
@@ -384,28 +384,6 @@ def test_union(self):
384384

385385
def test_add_iadd(self):
386386
for tz in self.tz:
387-
rng1 = pd.date_range('1/1/2000', freq='D', periods=5, tz=tz)
388-
other1 = pd.date_range('1/6/2000', freq='D', periods=5, tz=tz)
389-
expected1 = pd.date_range('1/1/2000', freq='D', periods=10, tz=tz)
390-
391-
rng2 = pd.date_range('1/1/2000', freq='D', periods=5, tz=tz)
392-
other2 = pd.date_range('1/4/2000', freq='D', periods=5, tz=tz)
393-
expected2 = pd.date_range('1/1/2000', freq='D', periods=8, tz=tz)
394-
395-
rng3 = pd.date_range('1/1/2000', freq='D', periods=5, tz=tz)
396-
other3 = pd.DatetimeIndex([], tz=tz)
397-
expected3 = pd.date_range('1/1/2000', freq='D', periods=5, tz=tz)
398-
399-
for rng, other, expected in [(rng1, other1, expected1),
400-
(rng2, other2, expected2),
401-
(rng3, other3, expected3)]:
402-
# previously performed setop (deprecated in 0.16.0), now
403-
# raises TypeError (GH14164)
404-
with tm.assertRaises(TypeError):
405-
rng + other
406-
407-
with tm.assertRaises(TypeError):
408-
rng += other
409387

410388
# offset
411389
offsets = [pd.offsets.Hour(2), timedelta(hours=2),
@@ -457,7 +435,7 @@ def test_add_dti_dti(self):
457435
with tm.assertRaises(TypeError):
458436
dti + dti_tz
459437

460-
def test_diff(self):
438+
def test_difference(self):
461439
for tz in self.tz:
462440
# diff
463441
rng1 = pd.date_range('1/1/2000', freq='D', periods=5, tz=tz)
@@ -529,10 +507,15 @@ def test_sub_dti_dti(self):
529507
with tm.assertRaises(TypeError):
530508
dti_tz - dti_tz2
531509

510+
# isub
511+
dti -= dti
512+
tm.assert_index_equal(dti, expected)
513+
532514
# different length raises ValueError
515+
dti1 = date_range('20130101', periods=3)
533516
dti2 = date_range('20130101', periods=4)
534517
with tm.assertRaises(ValueError):
535-
dti - dti2
518+
dti1 - dti2
536519

537520
# NaN propagation
538521
dti1 = DatetimeIndex(['2012-01-01', np.nan, '2012-01-03'])
@@ -2036,7 +2019,7 @@ def test_resolution(self):
20362019
idx = pd.period_range(start='2013-04-01', periods=30, freq=freq)
20372020
self.assertEqual(idx.resolution, expected)
20382021

2039-
def test_add_iadd(self):
2022+
def test_union(self):
20402023
# union
20412024
rng1 = pd.period_range('1/1/2000', freq='D', periods=5)
20422025
other1 = pd.period_range('1/6/2000', freq='D', periods=5)
@@ -2062,7 +2045,8 @@ def test_add_iadd(self):
20622045
rng5 = pd.PeriodIndex(['2000-01-01 09:01', '2000-01-01 09:03',
20632046
'2000-01-01 09:05'], freq='T')
20642047
other5 = pd.PeriodIndex(['2000-01-01 09:01', '2000-01-01 09:05'
2065-
'2000-01-01 09:08'], freq='T')
2048+
'2000-01-01 09:08'],
2049+
freq='T')
20662050
expected5 = pd.PeriodIndex(['2000-01-01 09:01', '2000-01-01 09:03',
20672051
'2000-01-01 09:05', '2000-01-01 09:08'],
20682052
freq='T')
@@ -2083,18 +2067,19 @@ def test_add_iadd(self):
20832067
expected6),
20842068
(rng7, other7, expected7)]:
20852069

2086-
# GH9094
2087-
with tm.assertRaises(TypeError):
2088-
rng + other
2089-
20902070
result_union = rng.union(other)
2091-
20922071
tm.assert_index_equal(result_union, expected)
20932072

2094-
# GH 6527
2095-
# GH9094
2096-
with tm.assertRaises(TypeError):
2097-
rng += other
2073+
def test_add_iadd(self):
2074+
rng = pd.period_range('1/1/2000', freq='D', periods=5)
2075+
other = pd.period_range('1/6/2000', freq='D', periods=5)
2076+
2077+
# previously performed setop union, now raises TypeError (GH14164)
2078+
with tm.assertRaises(TypeError):
2079+
rng + other
2080+
2081+
with tm.assertRaises(TypeError):
2082+
rng += other
20982083

20992084
# offset
21002085
# DateOffset
@@ -2181,7 +2166,7 @@ def test_add_iadd(self):
21812166
rng += 1
21822167
tm.assert_index_equal(rng, expected)
21832168

2184-
def test_sub_isub(self):
2169+
def test_difference(self):
21852170
# diff
21862171
rng1 = pd.period_range('1/1/2000', freq='D', periods=5)
21872172
other1 = pd.period_range('1/6/2000', freq='D', periods=5)
@@ -2223,6 +2208,19 @@ def test_sub_isub(self):
22232208
result_union = rng.difference(other)
22242209
tm.assert_index_equal(result_union, expected)
22252210

2211+
def test_sub_isub(self):
2212+
2213+
# previously performed setop, now raises TypeError (GH14164)
2214+
# TODO needs to wait on #13077 for decision on result type
2215+
rng = pd.period_range('1/1/2000', freq='D', periods=5)
2216+
other = pd.period_range('1/6/2000', freq='D', periods=5)
2217+
2218+
with tm.assertRaises(TypeError):
2219+
rng - other
2220+
2221+
with tm.assertRaises(TypeError):
2222+
rng -= other
2223+
22262224
# offset
22272225
# DateOffset
22282226
rng = pd.period_range('2014', '2024', freq='A')

0 commit comments

Comments
 (0)