Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ Missing
^^^^^^^
- Bug in :meth:`DataFrame.fillna` and :meth:`Series.fillna` that would ignore the ``limit`` argument on :class:`.ExtensionArray` dtypes (:issue:`58001`)
- Bug in :meth:`NA.__and__`, :meth:`NA.__or__` and :meth:`NA.__xor__` when operating with ``np.bool_`` objects (:issue:`58427`)
- Bug in ``divmod`` between :class:`NA` and ``Int64`` dtype objects (:issue:`62196`)
-

MultiIndex
Expand Down
4 changes: 4 additions & 0 deletions pandas/core/arrays/masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,10 @@ def _arith_method(self, other, op):
# will be all-True, but since this is division, we want
# to end up with floating dtype.
result = result.astype(np.float64)
elif op_name in {"divmod", "rdivmod"}:
# GH#62196
res = self._maybe_mask_result(result, mask)
return res, res.copy()
else:
# Make sure we do this before the "pow" mask checks
# to get an expected exception message on shape mismatch.
Expand Down
23 changes: 23 additions & 0 deletions pandas/tests/arrays/masked/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,26 @@ def test_unary_op_does_not_propagate_mask(data, op):
expected = result.copy(deep=True)
ser[0] = None
tm.assert_series_equal(result, expected)


@pytest.mark.parametrize("dtype", ["Int64", "Int32", "Float32", "Float64"])
def test_divmod_pdna(dtype):
# GH#62196
ser = pd.Series([1, 2, 3], dtype=dtype)
res = divmod(pd.NA, ser)
assert isinstance(res, tuple) and len(res) == 2

exp = pd.Series([pd.NA, pd.NA, pd.NA], dtype=dtype)
tm.assert_series_equal(res[0], exp)
tm.assert_series_equal(res[1], exp)

tm.assert_series_equal(res[0], pd.NA // ser)
tm.assert_series_equal(res[1], pd.NA % ser)

res = divmod(ser, pd.NA)
assert isinstance(res, tuple) and len(res) == 2
tm.assert_series_equal(res[0], exp)
tm.assert_series_equal(res[1], exp)

tm.assert_series_equal(res[0], ser // pd.NA)
tm.assert_series_equal(res[1], ser % pd.NA)
Loading