Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6a2da7a

Browse files
BUG: round on object columns no longer raises a TypeError (#61399)
* raise TypeError when Series dtype is object on calling Series.round()* add test* precommit* add github issue reference to test* add bugfix to 2.3 whatsnew* change self._mgr.dtype to self.dtypeCo-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>---------Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
1 parentfe60f43 commit6a2da7a

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

‎doc/source/whatsnew/v2.3.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ Timezones
120120
Numeric
121121
^^^^^^^
122122
- 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`)
123+
- Bug in:meth:`Series.round` on object columns no longer raises ``TypeError``
123124
-
124125

125126
Conversion

‎pandas/core/series.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,6 +2514,8 @@ def round(self, decimals: int = 0, *args, **kwargs) -> Series:
25142514
dtype: float64
25152515
"""
25162516
nv.validate_round(args,kwargs)
2517+
ifself.dtype=="object":
2518+
raiseTypeError("Expected numeric dtype, got object instead.")
25172519
new_mgr=self._mgr.round(decimals=decimals)
25182520
returnself._constructor_from_mgr(new_mgr,axes=new_mgr.axes).__finalize__(
25192521
self,method="round"

‎pandas/tests/series/methods/test_round.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,10 @@ def test_round_ea_boolean(self):
7272
tm.assert_series_equal(result,expected)
7373
result.iloc[0]=False
7474
tm.assert_series_equal(ser,expected)
75+
76+
deftest_round_dtype_object(self):
77+
# GH#61206
78+
ser=Series([0.2],dtype="object")
79+
msg="Expected numeric dtype, got object instead."
80+
withpytest.raises(TypeError,match=msg):
81+
ser.round()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp