Skip to content

Commit 713eaa6

Browse files
sinhrksjreback
authored andcommitted
BUG: DatetimeIndex - Period shows ununderstandable error
closes #13078 Author: sinhrks <[email protected]> Closes #13581 from sinhrks/dti_period_error and squashes the following commits: c957541 [sinhrks] BUG: DatetimeIndex - Period shows ununderstandable error
1 parent 5701c69 commit 713eaa6

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']:
@@ -1159,6 +1173,20 @@ def test_dti_tdi_numeric_ops(self):
11591173
expected = DatetimeIndex(['20121231', pd.NaT, '20130101'])
11601174
tm.assert_index_equal(result, expected)
11611175

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

11641192
# with datetimes/timedelta and tdi/dti

0 commit comments

Comments
 (0)