Skip to content

Commit a919646

Browse files
committed
updated tests
1 parent 5f0bd7d commit a919646

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +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`)
195+
- :meth:`Series.round` now operates pointwise on columns of object dtype (:issue:`62173`)
196196
- :meth:`Series.str.get_dummies` now accepts a ``dtype`` parameter to specify the dtype of the resulting DataFrame (:issue:`47872`)
197197
- :meth:`pandas.concat` will raise a ``ValueError`` when ``ignore_index=True`` and ``keys`` is not ``None`` (:issue:`59274`)
198198
- :py:class:`frozenset` elements in pandas objects are now natively printed (:issue:`60690`)

pandas/core/series.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,11 +2517,14 @@ def round(self, decimals: int = 0, *args, **kwargs) -> Series:
25172517
"""
25182518
nv.validate_round(args, kwargs)
25192519
if self.dtype == "object":
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")
2520+
try:
2521+
round_func = functools.partial(round, ndigits=decimals)
2522+
new_values = self._map_values(round_func)
2523+
return self._constructor(
2524+
new_values, index=self.index, copy=False
2525+
).__finalize__(self, method="map")
2526+
except TypeError as e:
2527+
raise TypeError("Expected numeric entries for dtype object.") from e
25252528
new_mgr = self._mgr.round(decimals=decimals)
25262529
return self._constructor_from_mgr(new_mgr, axes=new_mgr.axes).__finalize__(
25272530
self, method="round"

pandas/tests/series/methods/test_round.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,11 @@ def test_round_ea_boolean(self):
7474
tm.assert_series_equal(ser, expected)
7575

7676
def test_round_dtype_object(self):
77-
# GH#61206
78-
ser = Series([0.2], dtype="object")
79-
msg = "Expected numeric dtype, got object instead."
77+
# GH#61206, GH#62173
78+
ser = Series([0.232], dtype="object")
79+
expected = Series([0.2])
80+
tm.assert_series_equal(ser.round(1), expected)
81+
ser2 = Series(["bar"], dtype="object")
82+
msg = "Expected numeric entries for dtype object."
8083
with pytest.raises(TypeError, match=msg):
81-
ser.round()
84+
ser2.round()

0 commit comments

Comments
 (0)