Skip to content

Commit 6dbeeb4

Browse files
Backport PR #56767 on branch 2.2.x (BUG: Series.round raising for nullable bool dtype) (#56782)
Backport PR #56767: BUG: Series.round raising for nullable bool dtype Co-authored-by: Patrick Hoefler <[email protected]>
1 parent 41f22b3 commit 6dbeeb4

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

doc/source/whatsnew/v2.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ Numeric
790790
- Bug in :meth:`Series.__floordiv__` for :class:`ArrowDtype` with integral dtypes raising for large values (:issue:`56645`)
791791
- Bug in :meth:`Series.pow` not filling missing values correctly (:issue:`55512`)
792792
- Bug in :meth:`Series.replace` and :meth:`DataFrame.replace` matching float ``0.0`` with ``False`` and vice versa (:issue:`55398`)
793+
- Bug in :meth:`Series.round` raising for nullable boolean dtype (:issue:`55936`)
793794

794795
Conversion
795796
^^^^^^^^^^

pandas/core/arrays/masked.py

+2
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@ def round(self, decimals: int = 0, *args, **kwargs):
403403
DataFrame.round : Round values of a DataFrame.
404404
Series.round : Round values of a Series.
405405
"""
406+
if self.dtype.kind == "b":
407+
return self
406408
nv.validate_round(args, kwargs)
407409
values = np.round(self._data, decimals=decimals, **kwargs)
408410

pandas/core/series.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -2788,13 +2788,11 @@ def round(self, decimals: int = 0, *args, **kwargs) -> Series:
27882788
dtype: float64
27892789
"""
27902790
nv.validate_round(args, kwargs)
2791-
result = self._values.round(decimals)
2792-
result = self._constructor(result, index=self.index, copy=False).__finalize__(
2791+
new_mgr = self._mgr.round(decimals=decimals, using_cow=using_copy_on_write())
2792+
return self._constructor_from_mgr(new_mgr, axes=new_mgr.axes).__finalize__(
27932793
self, method="round"
27942794
)
27952795

2796-
return result
2797-
27982796
@overload
27992797
def quantile(
28002798
self, q: float = ..., interpolation: QuantileInterpolation = ...

pandas/tests/series/methods/test_round.py

+9
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,12 @@ def test_round_nat(self, method, freq, unit):
6363
round_method = getattr(ser.dt, method)
6464
result = round_method(freq)
6565
tm.assert_series_equal(result, expected)
66+
67+
def test_round_ea_boolean(self):
68+
# GH#55936
69+
ser = Series([True, False], dtype="boolean")
70+
expected = ser.copy()
71+
result = ser.round(2)
72+
tm.assert_series_equal(result, expected)
73+
result.iloc[0] = False
74+
tm.assert_series_equal(ser, expected)

0 commit comments

Comments
 (0)