Skip to content
Open
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
15 changes: 14 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -6718,7 +6718,20 @@ def _binop(self, other: Series, func, level=None, fill_value=None) -> Series:
this_vals, other_vals = ops.fill_binop(this._values, other._values, fill_value)

with np.errstate(all="ignore"):
result = func(this_vals, other_vals)
# GH#63250: Use arithmetic_op for arithmetic operations to ensure
# consistent behavior with dunder methods (includes _bool_arith_check)
# But use direct func call for comparison operations (gt, lt, etc.)
if func in (
operator.gt,
operator.ge,
operator.lt,
operator.le,
operator.eq,
operator.ne,
):
result = func(this_vals, other_vals)
else:
result = ops.arithmetic_op(this_vals, other_vals, func)

name = ops.get_op_result_name(self, other)

Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/series/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,20 @@ def test_flex_disallows_dataframe(self):
with pytest.raises(TypeError, match=msg):
ser.add(df, axis=0)

@pytest.mark.parametrize(
"opname", ["truediv", "rtruediv", "floordiv", "rfloordiv", "pow", "rpow"]
)
def test_flex_method_bool_dtype_raises(self, opname):
# GH#63250 - flex methods should raise NotImplementedError for bool dtypes
# consistent with their dunder counterparts
ser = Series([True, False, True])
other = Series([False, True, True])

op = getattr(Series, opname)
msg = f"operator '{opname.removeprefix('r')}' not implemented for bool dtypes"
with pytest.raises(NotImplementedError, match=msg):
op(ser, other)


class TestSeriesArithmetic:
# Some of these may end up in tests/arithmetic, but are not yet sorted
Expand Down
Loading