Skip to content

Commit fa74517

Browse files
authored
BUG: Series.round raising for nullable bool dtype (#56767)
* BUG: Series.round raising for nullable bool dtype * Fix typing
1 parent d8e9529 commit fa74517

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
@@ -404,6 +404,8 @@ def round(self, decimals: int = 0, *args, **kwargs):
404404
DataFrame.round : Round values of a DataFrame.
405405
Series.round : Round values of a Series.
406406
"""
407+
if self.dtype.kind == "b":
408+
return self
407409
nv.validate_round(args, kwargs)
408410
values = np.round(self._data, decimals=decimals, **kwargs)
409411

pandas/core/series.py

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

2797-
return result
2798-
27992797
@overload
28002798
def quantile(
28012799
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)