Skip to content

Commit c957541

Browse files
committed
BUG: DatetimeIndex - Period shows ununderstandable error
1 parent ba82b51 commit c957541

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

doc/source/whatsnew/v0.19.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ Bug Fixes
473473
- Bug in ``Series.str.extractall()`` with ``str`` index raises ``ValueError`` (:issue:`13156`)
474474
- Bug in ``Series.str.extractall()`` with single group and quantifier (:issue:`13382`)
475475

476-
476+
- Bug in ``DatetimeIndex`` and ``Period`` subtraction raises ``ValueError`` or ``AttributeError`` rather than ``TypeError`` (:issue:`13078`)
477477
- Bug in ``PeriodIndex`` and ``Period`` subtraction raises ``AttributeError`` (:issue:`13071`)
478478
- Bug in ``PeriodIndex`` construction returning a ``float64`` index in some circumstances (:issue:`13067`)
479479
- Bug in ``.resample(..)`` with a ``PeriodIndex`` not changing its ``freq`` appropriately when empty (:issue:`13067`)

pandas/tseries/tests/test_base.py

+28
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,20 @@ def test_sub_isub(self):
443443
rng -= 1
444444
tm.assert_index_equal(rng, expected)
445445

446+
def test_sub_period(self):
447+
# GH 13078
448+
# not supported, check TypeError
449+
p = pd.Period('2011-01-01', freq='D')
450+
451+
for freq in [None, 'D']:
452+
idx = pd.DatetimeIndex(['2011-01-01', '2011-01-02'], freq=freq)
453+
454+
with tm.assertRaises(TypeError):
455+
idx - p
456+
457+
with tm.assertRaises(TypeError):
458+
p - idx
459+
446460
def test_value_counts_unique(self):
447461
# GH 7735
448462
for tz in [None, 'UTC', 'Asia/Tokyo', 'US/Eastern']:
@@ -1157,6 +1171,20 @@ def test_dti_tdi_numeric_ops(self):
11571171
expected = DatetimeIndex(['20121231', pd.NaT, '20130101'])
11581172
tm.assert_index_equal(result, expected)
11591173

1174+
def test_sub_period(self):
1175+
# GH 13078
1176+
# not supported, check TypeError
1177+
p = pd.Period('2011-01-01', freq='D')
1178+
1179+
for freq in [None, 'H']:
1180+
idx = pd.TimedeltaIndex(['1 hours', '2 hours'], freq=freq)
1181+
1182+
with tm.assertRaises(TypeError):
1183+
idx - p
1184+
1185+
with tm.assertRaises(TypeError):
1186+
p - idx
1187+
11601188
def test_addition_ops(self):
11611189

11621190
# with datetimes/timedelta and tdi/dti

0 commit comments

Comments
 (0)