Skip to content

Commit 5f0bd7d

Browse files
committed
changed series.round() object dtype behavior to pointwise
1 parent 2547ff3 commit 5f0bd7d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ Other enhancements
192192
- :meth:`Series.map` can now accept kwargs to pass on to func (:issue:`59814`)
193193
- :meth:`Series.map` now accepts an ``engine`` parameter to allow execution with a third-party execution engine (:issue:`61125`)
194194
- :meth:`Series.rank` and :meth:`DataFrame.rank` with numpy-nullable dtypes preserve ``NA`` values and return ``UInt64`` dtype where appropriate instead of casting ``NA`` to ``NaN`` with ``float64`` dtype (:issue:`62043`)
195+
- :meth:`Series.round` now operates pointwise on columns of object dtype (:issue:`61682`)
195196
- :meth:`Series.str.get_dummies` now accepts a ``dtype`` parameter to specify the dtype of the resulting DataFrame (:issue:`47872`)
196197
- :meth:`pandas.concat` will raise a ``ValueError`` when ``ignore_index=True`` and ``keys`` is not ``None`` (:issue:`59274`)
197198
- :py:class:`frozenset` elements in pandas objects are now natively printed (:issue:`60690`)

pandas/core/series.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2517,7 +2517,11 @@ def round(self, decimals: int = 0, *args, **kwargs) -> Series:
25172517
"""
25182518
nv.validate_round(args, kwargs)
25192519
if self.dtype == "object":
2520-
raise TypeError("Expected numeric dtype, got object instead.")
2520+
round_func = functools.partial(round, ndigits=decimals)
2521+
new_values = self._map_values(round_func)
2522+
return self._constructor(
2523+
new_values, index=self.index, copy=False
2524+
).__finalize__(self, method="map")
25212525
new_mgr = self._mgr.round(decimals=decimals)
25222526
return self._constructor_from_mgr(new_mgr, axes=new_mgr.axes).__finalize__(
25232527
self, method="round"

0 commit comments

Comments
 (0)