Skip to content

Commit 4273ad0

Browse files
majiayu000claude
andcommitted
BUG: Make Series flex methods (truediv, floordiv, etc.) raise NotImplementedError for bool dtypes
Apply _bool_arith_check in Series._binop() to ensure flex methods like truediv(), floordiv(), pow() raise NotImplementedError for bool dtypes, consistent with their dunder counterparts (__truediv__, __floordiv__, etc.). The fix applies the check directly rather than routing through arithmetic_op() to avoid affecting comparison operations (gt, lt, etc.) that also use _binop. Closes #63250 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 944c527 commit 4273ad0

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

pandas/core/ops/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from __future__ import annotations
88

99
from pandas.core.ops.array_ops import (
10+
_bool_arith_check,
1011
arithmetic_op,
1112
comp_method_OBJECT_ARRAY,
1213
comparison_op,

pandas/core/series.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6718,6 +6718,9 @@ def _binop(self, other: Series, func, level=None, fill_value=None) -> Series:
67186718
this_vals, other_vals = ops.fill_binop(this._values, other._values, fill_value)
67196719

67206720
with np.errstate(all="ignore"):
6721+
# GH#63250: Apply _bool_arith_check for arithmetic operations on bool dtype
6722+
# to ensure consistent behavior between flex methods and dunder methods
6723+
ops._bool_arith_check(func, this_vals, other_vals)
67216724
result = func(this_vals, other_vals)
67226725

67236726
name = ops.get_op_result_name(self, other)

0 commit comments

Comments
 (0)