Skip to content

Commit 0994ecd

Browse files
authored
TST: collect Period tests (#56073)
* TST: collect Period tests * Collect Period tests
1 parent d22adf6 commit 0994ecd

File tree

7 files changed

+556
-542
lines changed

7 files changed

+556
-542
lines changed

pandas/tests/arithmetic/test_period.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,42 @@ def test_parr_add_sub_object_array(self):
13101310
expected = PeriodIndex(["2000-12-30"] * 3, freq="D")._data.astype(object)
13111311
tm.assert_equal(result, expected)
13121312

1313+
def test_period_add_timestamp_raises(self, box_with_array):
1314+
# GH#17983
1315+
ts = Timestamp("2017")
1316+
per = Period("2017", freq="M")
1317+
1318+
arr = pd.Index([per], dtype="Period[M]")
1319+
arr = tm.box_expected(arr, box_with_array)
1320+
1321+
msg = "cannot add PeriodArray and Timestamp"
1322+
with pytest.raises(TypeError, match=msg):
1323+
arr + ts
1324+
with pytest.raises(TypeError, match=msg):
1325+
ts + arr
1326+
msg = "cannot add PeriodArray and DatetimeArray"
1327+
with pytest.raises(TypeError, match=msg):
1328+
arr + Series([ts])
1329+
with pytest.raises(TypeError, match=msg):
1330+
Series([ts]) + arr
1331+
with pytest.raises(TypeError, match=msg):
1332+
arr + pd.Index([ts])
1333+
with pytest.raises(TypeError, match=msg):
1334+
pd.Index([ts]) + arr
1335+
1336+
if box_with_array is pd.DataFrame:
1337+
msg = "cannot add PeriodArray and DatetimeArray"
1338+
else:
1339+
msg = r"unsupported operand type\(s\) for \+: 'Period' and 'DatetimeArray"
1340+
with pytest.raises(TypeError, match=msg):
1341+
arr + pd.DataFrame([ts])
1342+
if box_with_array is pd.DataFrame:
1343+
msg = "cannot add PeriodArray and DatetimeArray"
1344+
else:
1345+
msg = r"unsupported operand type\(s\) for \+: 'DatetimeArray' and 'Period'"
1346+
with pytest.raises(TypeError, match=msg):
1347+
pd.DataFrame([ts]) + arr
1348+
13131349

13141350
class TestPeriodSeriesArithmetic:
13151351
def test_parr_add_timedeltalike_scalar(self, three_days, box_with_array):

0 commit comments

Comments
 (0)