@@ -541,9 +541,10 @@ def test_tda_add_sub_index(self):
541
541
expected = tdi - tdi
542
542
tm .assert_index_equal (result , expected )
543
543
544
- def test_tda_add_dt64_object_array (self , box_df_fail , tz_naive_fixture ):
544
+ def test_tda_add_dt64_object_array (self , box_with_array , tz_naive_fixture ):
545
545
# Result should be cast back to DatetimeArray
546
- box = box_df_fail
546
+ box = box_with_array
547
+
547
548
dti = pd .date_range ("2016-01-01" , periods = 3 , tz = tz_naive_fixture )
548
549
dti = dti ._with_freq (None )
549
550
tdi = dti - dti
@@ -1396,33 +1397,40 @@ def test_td64arr_sub_offset_array(self, box_with_array):
1396
1397
res = tdi - other
1397
1398
tm .assert_equal (res , expected )
1398
1399
1399
- def test_td64arr_with_offset_series (self , names , box_df_fail ):
1400
+ def test_td64arr_with_offset_series (self , names , box_with_array ):
1400
1401
# GH#18849
1401
- box = box_df_fail
1402
+ box = box_with_array
1402
1403
box2 = Series if box in [pd .Index , tm .to_array ] else box
1403
- exname = names [2 ] if box is not tm .to_array else names [1 ]
1404
+
1405
+ if box is pd .DataFrame :
1406
+ # Since we are operating with a DataFrame and a non-DataFrame,
1407
+ # the non-DataFrame is cast to Series and its name ignored.
1408
+ exname = names [0 ]
1409
+ elif box is tm .to_array :
1410
+ exname = names [1 ]
1411
+ else :
1412
+ exname = names [2 ]
1404
1413
1405
1414
tdi = TimedeltaIndex (["1 days 00:00:00" , "3 days 04:00:00" ], name = names [0 ])
1406
1415
other = Series ([pd .offsets .Hour (n = 1 ), pd .offsets .Minute (n = - 2 )], name = names [1 ])
1407
1416
1408
1417
expected_add = Series ([tdi [n ] + other [n ] for n in range (len (tdi ))], name = exname )
1409
- tdi = tm .box_expected (tdi , box )
1418
+ obj = tm .box_expected (tdi , box )
1410
1419
expected_add = tm .box_expected (expected_add , box2 )
1411
1420
1412
1421
with tm .assert_produces_warning (PerformanceWarning ):
1413
- res = tdi + other
1422
+ res = obj + other
1414
1423
tm .assert_equal (res , expected_add )
1415
1424
1416
1425
with tm .assert_produces_warning (PerformanceWarning ):
1417
- res2 = other + tdi
1426
+ res2 = other + obj
1418
1427
tm .assert_equal (res2 , expected_add )
1419
1428
1420
- # TODO: separate/parametrize add/sub test?
1421
1429
expected_sub = Series ([tdi [n ] - other [n ] for n in range (len (tdi ))], name = exname )
1422
1430
expected_sub = tm .box_expected (expected_sub , box2 )
1423
1431
1424
1432
with tm .assert_produces_warning (PerformanceWarning ):
1425
- res3 = tdi - other
1433
+ res3 = obj - other
1426
1434
tm .assert_equal (res3 , expected_sub )
1427
1435
1428
1436
@pytest .mark .parametrize ("obox" , [np .array , pd .Index , pd .Series ])
0 commit comments