Skip to content

Commit 2b694bf

Browse files
committed
move round to base calss
1 parent aa79869 commit 2b694bf

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

pandas/core/arrays/base.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,6 +2141,19 @@ def _mode(self, dropna: bool = True) -> Self:
21412141
# error: Incompatible return value type (got "Union[ExtensionArray,
21422142
# ndarray[Any, Any]]", expected "Self")
21432143
return mode(self, dropna=dropna) # type: ignore[return-value]
2144+
2145+
def round(self, decimals: int = 0, *args, **kwargs) -> Self:
2146+
# Implementer note: This is a non-optimized default implementation.
2147+
# Implementers are encouraged to override this method to avoid
2148+
# elementwise rounding.
2149+
if not self.dtype._is_numeric or self.dtype._is_boolean:
2150+
raise TypeError(
2151+
f"Cannot round {self.dtype} dtype as it is non-numeric or boolean"
2152+
)
2153+
return self._from_sequence(
2154+
[round(element) if not isna(element) else element for element in self.data],
2155+
dtype=self.dtype,
2156+
)
21442157

21452158
def __array_ufunc__(self, ufunc: np.ufunc, method: str, *inputs, **kwargs):
21462159
if any(
@@ -2337,19 +2350,6 @@ def _add_logical_ops(cls) -> None:
23372350
setattr(cls, "__xor__", cls._create_logical_method(operator.xor))
23382351
setattr(cls, "__rxor__", cls._create_logical_method(roperator.rxor))
23392352

2340-
def round(self, decimals: int = 0, *args, **kwargs) -> Self:
2341-
# Implementer note: This is a non-optimized default implementation.
2342-
# Implementers are encouraged to override this method to avoid
2343-
# elementwise rounding.
2344-
if not self.dtype._is_numeric or self.dtype._is_boolean:
2345-
raise TypeError(
2346-
f"Cannot round {self.dtype} dtype as it is non-numeric or boolean"
2347-
)
2348-
return self._from_sequence(
2349-
[round(element) if not isna(element) else element for element in self.data],
2350-
dtype=self.dtype,
2351-
)
2352-
23532353

23542354
class ExtensionScalarOpsMixin(ExtensionOpsMixin):
23552355
"""

0 commit comments

Comments
 (0)