Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4e474f4

Browse files
BUG: divmod with bool dtype failing to raise (#62247)
1 parent 0ee266c commit 4e474f4

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

‎doc/source/whatsnew/v3.0.0.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,7 @@ Other
11201120
- Bug in ``Series.list`` methods not preserving the original :class:`Index`. (:issue:`58425`)
11211121
- Bug in ``Series.list`` methods not preserving the original name. (:issue:`60522`)
11221122
- Bug in ``Series.replace`` when the Series was created from an :class:`Index` and Copy-On-Write is enabled (:issue:`61622`)
1123+
- Bug in ``divmod`` and ``rdivmod`` with :class:`DataFrame`, :class:`Series`, and :class:`Index` with ``bool`` dtypes failing to raise, which was inconsistent with ``__floordiv__`` behavior (:issue:`46043`)
11231124
- Bug in printing a :class:`DataFrame` with a :class:`DataFrame` stored in :attr:`DataFrame.attrs` raised a ``ValueError`` (:issue:`60455`)
11241125
- Bug in printing a :class:`Series` with a :class:`DataFrame` stored in :attr:`Series.attrs` raised a ``ValueError`` (:issue:`60568`)
11251126
- Fixed bug where the :class:`DataFrame` constructor misclassified array-like objects with a ``.name`` attribute as :class:`Series` or :class:`Index` (:issue:`61443`)

‎pandas/core/ops/array_ops.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,8 @@ def maybe_prepare_scalar_for_op(obj, shape: Shape):
585585
roperator.rfloordiv,
586586
operator.pow,
587587
roperator.rpow,
588+
divmod,
589+
roperator.rdivmod,
588590
}
589591

590592

‎pandas/tests/arithmetic/test_bool.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pytest
2+
3+
from pandas import (
4+
DataFrame,
5+
Series,
6+
)
7+
import pandas._testing as tm
8+
9+
10+
def test_divmod_bool_raises(box_with_array):
11+
# GH#46043 // raises, so divmod should too
12+
ser = Series([True, False])
13+
obj = tm.box_expected(ser, box_with_array)
14+
15+
msg = "operator 'floordiv' not implemented for bool dtypes"
16+
with pytest.raises(NotImplementedError, match=msg):
17+
obj // obj
18+
19+
if box_with_array is DataFrame:
20+
msg = "operator 'floordiv' not implemented for bool dtypes"
21+
else:
22+
msg = "operator 'divmod' not implemented for bool dtypes"
23+
with pytest.raises(NotImplementedError, match=msg):
24+
divmod(obj, obj)
25+
26+
# go through __rdivmod__
27+
with pytest.raises(NotImplementedError, match=msg):
28+
divmod(True, obj)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /