@@ -1327,14 +1327,11 @@ def test_td64arr_add_offset_index(self, names, box):
1327
1327
tdi = tm .box_expected (tdi , box )
1328
1328
expected = tm .box_expected (expected , box )
1329
1329
1330
- # The DataFrame operation is transposed and so operates as separate
1331
- # scalar operations, which do not issue a PerformanceWarning
1332
- warn = PerformanceWarning if box is not pd .DataFrame else None
1333
- with tm .assert_produces_warning (warn ):
1330
+ with tm .assert_produces_warning (PerformanceWarning ):
1334
1331
res = tdi + other
1335
1332
tm .assert_equal (res , expected )
1336
1333
1337
- with tm .assert_produces_warning (warn ):
1334
+ with tm .assert_produces_warning (PerformanceWarning ):
1338
1335
res2 = other + tdi
1339
1336
tm .assert_equal (res2 , expected )
1340
1337
@@ -1353,14 +1350,11 @@ def test_td64arr_add_offset_array(self, box_with_array):
1353
1350
tdi = tm .box_expected (tdi , box )
1354
1351
expected = tm .box_expected (expected , box )
1355
1352
1356
- # The DataFrame operation is transposed and so operates as separate
1357
- # scalar operations, which do not issue a PerformanceWarning
1358
- warn = PerformanceWarning if box is not pd .DataFrame else None
1359
- with tm .assert_produces_warning (warn ):
1353
+ with tm .assert_produces_warning (PerformanceWarning ):
1360
1354
res = tdi + other
1361
1355
tm .assert_equal (res , expected )
1362
1356
1363
- with tm .assert_produces_warning (warn ):
1357
+ with tm .assert_produces_warning (PerformanceWarning ):
1364
1358
res2 = other + tdi
1365
1359
tm .assert_equal (res2 , expected )
1366
1360
@@ -1389,10 +1383,7 @@ def test_td64arr_sub_offset_index(self, names, box_with_array):
1389
1383
tdi = tm .box_expected (tdi , box )
1390
1384
expected = tm .box_expected (expected , xbox )
1391
1385
1392
- # The DataFrame operation is transposed and so operates as separate
1393
- # scalar operations, which do not issue a PerformanceWarning
1394
- warn = PerformanceWarning if box is not pd .DataFrame else None
1395
- with tm .assert_produces_warning (warn ):
1386
+ with tm .assert_produces_warning (PerformanceWarning ):
1396
1387
res = tdi - other
1397
1388
tm .assert_equal (res , expected )
1398
1389
@@ -1408,10 +1399,7 @@ def test_td64arr_sub_offset_array(self, box_with_array):
1408
1399
tdi = tm .box_expected (tdi , box_with_array )
1409
1400
expected = tm .box_expected (expected , box_with_array )
1410
1401
1411
- # The DataFrame operation is transposed and so operates as separate
1412
- # scalar operations, which do not issue a PerformanceWarning
1413
- warn = None if box_with_array is pd .DataFrame else PerformanceWarning
1414
- with tm .assert_produces_warning (warn ):
1402
+ with tm .assert_produces_warning (PerformanceWarning ):
1415
1403
res = tdi - other
1416
1404
tm .assert_equal (res , expected )
1417
1405
@@ -1482,28 +1470,31 @@ def test_td64arr_add_sub_object_array(self, box_with_array):
1482
1470
[pd .Timedelta (days = 1 ), pd .offsets .Day (2 ), pd .Timestamp ("2000-01-04" )]
1483
1471
)
1484
1472
1485
- warn = PerformanceWarning if box_with_array is not pd .DataFrame else None
1486
- with tm .assert_produces_warning (warn ):
1473
+ with tm .assert_produces_warning (PerformanceWarning ):
1487
1474
result = tdarr + other
1488
1475
1489
1476
expected = pd .Index (
1490
1477
[pd .Timedelta (days = 2 ), pd .Timedelta (days = 4 ), pd .Timestamp ("2000-01-07" )]
1491
1478
)
1492
1479
expected = tm .box_expected (expected , box_with_array )
1480
+ if box_with_array is pd .DataFrame :
1481
+ expected = expected .astype (object )
1493
1482
tm .assert_equal (result , expected )
1494
1483
1495
1484
msg = "unsupported operand type|cannot subtract a datelike"
1496
1485
with pytest .raises (TypeError , match = msg ):
1497
- with tm .assert_produces_warning (warn ):
1486
+ with tm .assert_produces_warning (PerformanceWarning ):
1498
1487
tdarr - other
1499
1488
1500
- with tm .assert_produces_warning (warn ):
1489
+ with tm .assert_produces_warning (PerformanceWarning ):
1501
1490
result = other - tdarr
1502
1491
1503
1492
expected = pd .Index (
1504
1493
[pd .Timedelta (0 ), pd .Timedelta (0 ), pd .Timestamp ("2000-01-01" )]
1505
1494
)
1506
1495
expected = tm .box_expected (expected , box_with_array )
1496
+ if box_with_array is pd .DataFrame :
1497
+ expected = expected .astype (object )
1507
1498
tm .assert_equal (result , expected )
1508
1499
1509
1500
@@ -2043,6 +2034,7 @@ def test_td64arr_div_numeric_array(self, box_with_array, vector, any_real_dtype)
2043
2034
expected = [tdser .iloc [0 , n ] / vector [n ] for n in range (len (vector ))]
2044
2035
else :
2045
2036
expected = [tdser [n ] / vector [n ] for n in range (len (tdser ))]
2037
+ expected = pd .Index (expected ) # do dtype inference
2046
2038
expected = tm .box_expected (expected , xbox )
2047
2039
tm .assert_equal (result , expected )
2048
2040
0 commit comments