Skip to content

Conversation

@majiayu000
Copy link

Summary

This PR fixes the inconsistency between Series flex methods (.truediv(), .floordiv(), etc.) and their dunder counterparts (__truediv__, __floordiv__, etc.) when operating on boolean dtypes.

Previously:

  • pd.Series([True]) / [True] raised NotImplementedError
  • pd.Series([True]).truediv([True]) returned a float result ✗

After this fix, both methods consistently raise NotImplementedError: operator 'truediv' not implemented for bool dtypes.

Changes

Modified Series._binop() to route through ops.arithmetic_op() instead of directly calling the operator function. This ensures the _bool_arith_check is applied consistently for all arithmetic operations.

The fix applies to all disallowed operations for bool dtypes:

  • truediv / rtruediv
  • floordiv / rfloordiv
  • pow / rpow
  • divmod / rdivmod

Test Plan

  • Verified pd.Series([True]).truediv([True]) now raises NotImplementedError
  • Verified pd.Series([True]).rtruediv([True]) now raises NotImplementedError
  • Verified pd.Series([True]).floordiv([True]) now raises NotImplementedError
  • Verified pd.Series([True]).pow([True]) now raises NotImplementedError
  • Verified normal float operations still work: pd.Series([1.0]).truediv([2.0]) returns [0.5]

Closes #63250

…ementedError for bool dtypes

This change ensures that flex methods like .truediv(), .rtruediv(), .floordiv(),
.rfloordiv(), .pow(), .rpow() raise NotImplementedError for boolean dtypes,
consistent with their dunder method counterparts (__truediv__, etc.).

Previously, pd.Series([True]).truediv([True]) would return a float result,
while pd.Series([True]) / [True] would raise NotImplementedError. This fixes
the inconsistency by routing _binop through ops.arithmetic_op which includes
the bool dtype check.

Closes pandas-dev#63250
@jbrockmendel
Copy link
Member

Can you add tests (applies to all your PRs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Inconsistency between Series[bool].__truediv__(list[bool]) and Series[bool].truediv(list[bool])

2 participants