Skip to content

Commit

Permalink
Backport PR pandas-dev#56767: BUG: Series.round raising for nullable …
Browse files Browse the repository at this point in the history
…bool dtype
  • Loading branch information
phofl authored and meeseeksmachine committed Jan 8, 2024
1 parent 41f22b3 commit 55aae17
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ Numeric
- Bug in :meth:`Series.__floordiv__` for :class:`ArrowDtype` with integral dtypes raising for large values (:issue:`56645`)
- Bug in :meth:`Series.pow` not filling missing values correctly (:issue:`55512`)
- Bug in :meth:`Series.replace` and :meth:`DataFrame.replace` matching float ``0.0`` with ``False`` and vice versa (:issue:`55398`)
- Bug in :meth:`Series.round` raising for nullable boolean dtype (:issue:`55936`)

Conversion
^^^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions pandas/core/arrays/masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ def round(self, decimals: int = 0, *args, **kwargs):
DataFrame.round : Round values of a DataFrame.
Series.round : Round values of a Series.
"""
if self.dtype.kind == "b":
return self
nv.validate_round(args, kwargs)
values = np.round(self._data, decimals=decimals, **kwargs)

Expand Down
6 changes: 2 additions & 4 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2788,13 +2788,11 @@ def round(self, decimals: int = 0, *args, **kwargs) -> Series:
dtype: float64
"""
nv.validate_round(args, kwargs)
result = self._values.round(decimals)
result = self._constructor(result, index=self.index, copy=False).__finalize__(
new_mgr = self._mgr.round(decimals=decimals, using_cow=using_copy_on_write())
return self._constructor_from_mgr(new_mgr, axes=new_mgr.axes).__finalize__(
self, method="round"
)

return result

@overload
def quantile(
self, q: float = ..., interpolation: QuantileInterpolation = ...
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/series/methods/test_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,12 @@ def test_round_nat(self, method, freq, unit):
round_method = getattr(ser.dt, method)
result = round_method(freq)
tm.assert_series_equal(result, expected)

def test_round_ea_boolean(self):
# GH#55936
ser = Series([True, False], dtype="boolean")
expected = ser.copy()
result = ser.round(2)
tm.assert_series_equal(result, expected)
result.iloc[0] = False
tm.assert_series_equal(ser, expected)

0 comments on commit 55aae17

Please sign in to comment.