Skip to content

Commit d52ef15

Browse files
majiayu000claude
andcommitted
BUG: Make Series flex methods (truediv, floordiv, etc.) raise NotImplementedError for bool dtypes
Use arithmetic_op for arithmetic operations in Series._binop() to ensure flex methods like truediv(), floordiv(), pow() raise NotImplementedError for bool dtypes, consistent with their dunder counterparts. Comparison operations (gt, lt, etc.) continue to use direct function calls to preserve their existing behavior. Closes #63250 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 944c527 commit d52ef15

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pandas/core/series.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6718,7 +6718,20 @@ 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-
result = func(this_vals, other_vals)
6721+
# GH#63250: Use arithmetic_op for arithmetic operations to ensure
6722+
# consistent behavior with dunder methods (includes _bool_arith_check)
6723+
# But use direct func call for comparison operations (gt, lt, etc.)
6724+
if func in (
6725+
operator.gt,
6726+
operator.ge,
6727+
operator.lt,
6728+
operator.le,
6729+
operator.eq,
6730+
operator.ne,
6731+
):
6732+
result = func(this_vals, other_vals)
6733+
else:
6734+
result = ops.arithmetic_op(this_vals, other_vals, func)
67226735

67236736
name = ops.get_op_result_name(self, other)
67246737

0 commit comments

Comments
 (0)