Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions pandas/tests/arithmetic/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,42 @@ def test_parr_add_sub_object_array(self):
expected = PeriodIndex(["2000-12-30"] * 3, freq="D")._data.astype(object)
tm.assert_equal(result, expected)

def test_period_add_timestamp_raises(self, box_with_array):
# GH#17983
ts = Timestamp("2017")
per = Period("2017", freq="M")

arr = pd.Index([per], dtype="Period[M]")
arr = tm.box_expected(arr, box_with_array)

msg = "cannot add PeriodArray and Timestamp"
with pytest.raises(TypeError, match=msg):
arr + ts
with pytest.raises(TypeError, match=msg):
ts + arr
msg = "cannot add PeriodArray and DatetimeArray"
with pytest.raises(TypeError, match=msg):
arr + Series([ts])
with pytest.raises(TypeError, match=msg):
Series([ts]) + arr
with pytest.raises(TypeError, match=msg):
arr + pd.Index([ts])
with pytest.raises(TypeError, match=msg):
pd.Index([ts]) + arr

if box_with_array is pd.DataFrame:
msg = "cannot add PeriodArray and DatetimeArray"
else:
msg = r"unsupported operand type\(s\) for \+: 'Period' and 'DatetimeArray"
with pytest.raises(TypeError, match=msg):
arr + pd.DataFrame([ts])
if box_with_array is pd.DataFrame:
msg = "cannot add PeriodArray and DatetimeArray"
else:
msg = r"unsupported operand type\(s\) for \+: 'DatetimeArray' and 'Period'"
with pytest.raises(TypeError, match=msg):
pd.DataFrame([ts]) + arr


class TestPeriodSeriesArithmetic:
def test_parr_add_timedeltalike_scalar(self, three_days, box_with_array):
Expand Down
Loading