diff --git a/doc/source/whatsnew/v2.3.0.rst b/doc/source/whatsnew/v2.3.0.rst index fc60789801ce7..f7bd8a8f191ae 100644 --- a/doc/source/whatsnew/v2.3.0.rst +++ b/doc/source/whatsnew/v2.3.0.rst @@ -107,6 +107,7 @@ Timezones Numeric ^^^^^^^ - Enabled :class:`Series.mode` and :class:`DataFrame.mode` with ``dropna=False`` to sort the result for all dtypes in the presence of NA values; previously only certain dtypes would sort (:issue:`60702`) +- Bug in :meth:`Series.round` on object columns no longer raises ``TypeError`` - Conversion diff --git a/pandas/core/series.py b/pandas/core/series.py index 4e2e363885594..cc16c29c6c861 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2814,6 +2814,8 @@ def round(self, decimals: int = 0, *args, **kwargs) -> Series: dtype: float64 """ nv.validate_round(args, kwargs) + if self.dtype == "object": + raise TypeError("Expected numeric dtype, got object instead.") 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" diff --git a/pandas/tests/series/methods/test_round.py b/pandas/tests/series/methods/test_round.py index c330b7a7dfbbb..a78f77e990ae1 100644 --- a/pandas/tests/series/methods/test_round.py +++ b/pandas/tests/series/methods/test_round.py @@ -72,3 +72,10 @@ def test_round_ea_boolean(self): tm.assert_series_equal(result, expected) result.iloc[0] = False tm.assert_series_equal(ser, expected) + + def test_round_dtype_object(self): + # GH#61206 + ser = Series([0.2], dtype="object") + msg = "Expected numeric dtype, got object instead." + with pytest.raises(TypeError, match=msg): + ser.round()