Skip to content

Commit 007128c

Browse files
authored
TST: avoid skipping in frame arith test (#38310)
1 parent 99c6116 commit 007128c

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

pandas/tests/frame/test_arithmetic.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -835,16 +835,9 @@ def test_frame_with_frame_reindex(self):
835835
)
836836
def test_binop_other(self, op, value, dtype):
837837
skip = {
838-
(operator.add, "bool"),
839-
(operator.sub, "bool"),
840-
(operator.mul, "bool"),
841838
(operator.truediv, "bool"),
842-
(operator.mod, "i8"),
843-
(operator.mod, "complex128"),
844839
(operator.pow, "bool"),
845840
}
846-
if (op, dtype) in skip:
847-
pytest.skip(f"Invalid combination {op},{dtype}")
848841

849842
e = DummyElement(value, dtype)
850843
s = DataFrame({"A": [e.value, e.value]}, dtype=e.dtype)
@@ -857,26 +850,46 @@ def test_binop_other(self, op, value, dtype):
857850
(operator.add, "<M8[ns]"),
858851
(operator.pow, "<m8[ns]"),
859852
(operator.mul, "<m8[ns]"),
853+
(operator.sub, "bool"),
854+
(operator.mod, "complex128"),
860855
}
861856

862857
if (op, dtype) in invalid:
863-
msg = (
864-
None
865-
if (dtype == "<M8[ns]" and op == operator.add)
866-
or (dtype == "<m8[ns]" and op == operator.mul)
867-
else (
858+
warn = None
859+
if (dtype == "<M8[ns]" and op == operator.add) or (
860+
dtype == "<m8[ns]" and op == operator.mul
861+
):
862+
msg = None
863+
elif dtype == "complex128":
864+
msg = "ufunc 'remainder' not supported for the input types"
865+
warn = UserWarning # "evaluating in Python space because ..."
866+
elif op is operator.sub:
867+
msg = "numpy boolean subtract, the `-` operator, is "
868+
warn = UserWarning # "evaluating in Python space because ..."
869+
else:
870+
msg = (
868871
f"cannot perform __{op.__name__}__ with this "
869872
"index type: (DatetimeArray|TimedeltaArray)"
870873
)
871-
)
872874

873875
with pytest.raises(TypeError, match=msg):
874-
op(s, e.value)
876+
with tm.assert_produces_warning(warn):
877+
op(s, e.value)
878+
879+
elif (op, dtype) in skip:
880+
881+
msg = "operator '.*' not implemented for .* dtypes"
882+
with pytest.raises(NotImplementedError, match=msg):
883+
with tm.assert_produces_warning(UserWarning):
884+
# "evaluating in Python space because ..."
885+
op(s, e.value)
886+
875887
else:
876888
# FIXME: Since dispatching to Series, this test no longer
877889
# asserts anything meaningful
878-
result = op(s, e.value).dtypes
879-
expected = op(s, value).dtypes
890+
with tm.assert_produces_warning(None):
891+
result = op(s, e.value).dtypes
892+
expected = op(s, value).dtypes
880893
tm.assert_series_equal(result, expected)
881894

882895

0 commit comments

Comments
 (0)