Skip to content

Commit b6434fa

Browse files
authored
TST: fix xfailed arithmetic tests (pandas-dev#33855)
1 parent 9d2eca8 commit b6434fa

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

pandas/core/ops/dispatch.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ def should_series_dispatch(left, right, op):
6565
ldtype = left.dtypes.iloc[0]
6666
rdtype = right.dtypes.iloc[0]
6767

68-
if (is_timedelta64_dtype(ldtype) and is_integer_dtype(rdtype)) or (
69-
is_timedelta64_dtype(rdtype) and is_integer_dtype(ldtype)
68+
if (
69+
is_timedelta64_dtype(ldtype)
70+
and (is_integer_dtype(rdtype) or is_object_dtype(rdtype))
71+
) or (
72+
is_timedelta64_dtype(rdtype)
73+
and (is_integer_dtype(ldtype) or is_object_dtype(ldtype))
7074
):
7175
# numpy integer dtypes as timedelta64 dtypes in this scenario
7276
return True

pandas/tests/arithmetic/test_timedelta64.py

+18-10
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,10 @@ def test_tda_add_sub_index(self):
541541
expected = tdi - tdi
542542
tm.assert_index_equal(result, expected)
543543

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):
545545
# Result should be cast back to DatetimeArray
546-
box = box_df_fail
546+
box = box_with_array
547+
547548
dti = pd.date_range("2016-01-01", periods=3, tz=tz_naive_fixture)
548549
dti = dti._with_freq(None)
549550
tdi = dti - dti
@@ -1396,33 +1397,40 @@ def test_td64arr_sub_offset_array(self, box_with_array):
13961397
res = tdi - other
13971398
tm.assert_equal(res, expected)
13981399

1399-
def test_td64arr_with_offset_series(self, names, box_df_fail):
1400+
def test_td64arr_with_offset_series(self, names, box_with_array):
14001401
# GH#18849
1401-
box = box_df_fail
1402+
box = box_with_array
14021403
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]
14041413

14051414
tdi = TimedeltaIndex(["1 days 00:00:00", "3 days 04:00:00"], name=names[0])
14061415
other = Series([pd.offsets.Hour(n=1), pd.offsets.Minute(n=-2)], name=names[1])
14071416

14081417
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)
14101419
expected_add = tm.box_expected(expected_add, box2)
14111420

14121421
with tm.assert_produces_warning(PerformanceWarning):
1413-
res = tdi + other
1422+
res = obj + other
14141423
tm.assert_equal(res, expected_add)
14151424

14161425
with tm.assert_produces_warning(PerformanceWarning):
1417-
res2 = other + tdi
1426+
res2 = other + obj
14181427
tm.assert_equal(res2, expected_add)
14191428

1420-
# TODO: separate/parametrize add/sub test?
14211429
expected_sub = Series([tdi[n] - other[n] for n in range(len(tdi))], name=exname)
14221430
expected_sub = tm.box_expected(expected_sub, box2)
14231431

14241432
with tm.assert_produces_warning(PerformanceWarning):
1425-
res3 = tdi - other
1433+
res3 = obj - other
14261434
tm.assert_equal(res3, expected_sub)
14271435

14281436
@pytest.mark.parametrize("obox", [np.array, pd.Index, pd.Series])

0 commit comments

Comments
 (0)