Skip to content

Commit 76c9ba7

Browse files
committed
typerror for non numerics
1 parent 2e9cddf commit 76c9ba7

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

pandas/core/arrays/arrow/array.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,8 @@ def round(self, decimals: int = 0, *args, **kwargs) -> Self:
10941094
DataFrame.round : Round values of a DataFrame.
10951095
Series.round : Round values of a Series.
10961096
"""
1097+
if not self.dtype._is_numeric or self.dtype._is_boolean:
1098+
raise TypeError("Cannot round non-numeric type.")
10971099
return type(self)(pc.round(self._pa_array, ndigits=decimals))
10981100

10991101
@doc(ExtensionArray.searchsorted)

pandas/tests/extension/base/methods.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -719,10 +719,12 @@ def test_equals_same_data_different_object(self, data):
719719

720720
def test_round(self, data):
721721
if not data.dtype._is_numeric or data.dtype._is_boolean:
722-
pytest.skip("Round is only valid for numeric non-boolean dtypes")
723-
result = pd.Series(data).round()
724-
expected = pd.Series(
725-
[round(element) if pd.notna(element) else element for element in data],
726-
dtype=data.dtype,
727-
)
728-
tm.assert_series_equal(result, expected)
722+
with pytest.raises(TypeError):
723+
pd.Series(data).round()
724+
else:
725+
result = pd.Series(data).round()
726+
expected = pd.Series(
727+
[round(element) if pd.notna(element) else element for element in data],
728+
dtype=data.dtype,
729+
)
730+
tm.assert_series_equal(result, expected)

pandas/tests/extension/test_datetime.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ def check_reduce(self, ser: pd.Series, op_name: str, skipna: bool):
138138

139139
else:
140140
return super().check_reduce(ser, op_name, skipna)
141+
142+
@pytest.mark.skip("DatetimeArray uses a different function signature for round")
143+
def test_round(self):
144+
pass
145+
141146

142147

143148
class Test2DCompat(base.NDArrayBacked2DTests):

0 commit comments

Comments
 (0)