@@ -1310,6 +1310,42 @@ def test_parr_add_sub_object_array(self):
1310
1310
expected = PeriodIndex (["2000-12-30" ] * 3 , freq = "D" )._data .astype (object )
1311
1311
tm .assert_equal (result , expected )
1312
1312
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
+
1313
1349
1314
1350
class TestPeriodSeriesArithmetic :
1315
1351
def test_parr_add_timedeltalike_scalar (self , three_days , box_with_array ):
0 commit comments