Skip to content

TST: fix xfailed arithmetic tests #33855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pandas/core/ops/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ def should_series_dispatch(left, right, op):
ldtype = left.dtypes.iloc[0]
rdtype = right.dtypes.iloc[0]

if (is_timedelta64_dtype(ldtype) and is_integer_dtype(rdtype)) or (
is_timedelta64_dtype(rdtype) and is_integer_dtype(ldtype)
if (
is_timedelta64_dtype(ldtype)
and (is_integer_dtype(rdtype) or is_object_dtype(rdtype))
) or (
is_timedelta64_dtype(rdtype)
and (is_integer_dtype(ldtype) or is_object_dtype(ldtype))
):
# numpy integer dtypes as timedelta64 dtypes in this scenario
return True
Expand Down
28 changes: 18 additions & 10 deletions pandas/tests/arithmetic/test_timedelta64.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,10 @@ def test_tda_add_sub_index(self):
expected = tdi - tdi
tm.assert_index_equal(result, expected)

def test_tda_add_dt64_object_array(self, box_df_fail, tz_naive_fixture):
def test_tda_add_dt64_object_array(self, box_with_array, tz_naive_fixture):
# Result should be cast back to DatetimeArray
box = box_df_fail
box = box_with_array

dti = pd.date_range("2016-01-01", periods=3, tz=tz_naive_fixture)
dti = dti._with_freq(None)
tdi = dti - dti
Expand Down Expand Up @@ -1396,33 +1397,40 @@ def test_td64arr_sub_offset_array(self, box_with_array):
res = tdi - other
tm.assert_equal(res, expected)

def test_td64arr_with_offset_series(self, names, box_df_fail):
def test_td64arr_with_offset_series(self, names, box_with_array):
# GH#18849
box = box_df_fail
box = box_with_array
box2 = Series if box in [pd.Index, tm.to_array] else box
exname = names[2] if box is not tm.to_array else names[1]

if box is pd.DataFrame:
# Since we are operating with a DataFrame and a non-DataFrame,
# the non-DataFrame is cast to Series and its name ignored.
exname = names[0]
elif box is tm.to_array:
exname = names[1]
else:
exname = names[2]

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

expected_add = Series([tdi[n] + other[n] for n in range(len(tdi))], name=exname)
tdi = tm.box_expected(tdi, box)
obj = tm.box_expected(tdi, box)
expected_add = tm.box_expected(expected_add, box2)

with tm.assert_produces_warning(PerformanceWarning):
res = tdi + other
res = obj + other
tm.assert_equal(res, expected_add)

with tm.assert_produces_warning(PerformanceWarning):
res2 = other + tdi
res2 = other + obj
tm.assert_equal(res2, expected_add)

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

with tm.assert_produces_warning(PerformanceWarning):
res3 = tdi - other
res3 = obj - other
tm.assert_equal(res3, expected_sub)

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