From d52ef15415a013d8f7ce386c45e3db988fc4ff8e Mon Sep 17 00:00:00 2001 From: lif <1835304752@qq.com> Date: Fri, 12 Dec 2025 11:13:28 +0800 Subject: [PATCH] BUG: Make Series flex methods (truediv, floordiv, etc.) raise NotImplementedError for bool dtypes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- pandas/core/series.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 1ea8bbbaa0cfb..22eb33e0a95ed 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -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)