-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
BUG/TST: Series round with dtype object #62174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 8 commits
5f0bd7d
a919646
c44e2af
fd1f6b6
0ab7faa
83acc9e
2c3d0e2
084569f
bb50529
8226901
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from __future__ import annotations | ||
|
||
import functools | ||
import inspect | ||
import re | ||
from typing import ( | ||
|
@@ -261,7 +262,7 @@ def make_block_same_class( | |
|
||
@final | ||
def __repr__(self) -> str: | ||
# don't want to print out all of the items here | ||
# don't want to out all of the items here | ||
name = type(self).__name__ | ||
if self.ndim == 1: | ||
result = f"{name}: {len(self)} dtype: {self.dtype}" | ||
|
@@ -345,7 +346,6 @@ def apply(self, func, **kwargs) -> list[Block]: | |
one | ||
""" | ||
result = func(self.values, **kwargs) | ||
|
||
result = maybe_coerce_values(result) | ||
return self._split_op_result(result) | ||
|
||
|
@@ -1503,16 +1503,32 @@ def quantile( | |
def round(self, decimals: int) -> Self: | ||
""" | ||
Rounds the values. | ||
If the block is not of an integer or float dtype, nothing happens. | ||
This is consistent with DataFrame.round behavior. | ||
(Note: Series.round would raise) | ||
If the block is of object dtype, it will operate pointwise and possibly raise. | ||
Otherwise, if the block is not of an integer or float dtype, nothing happens. | ||
|
||
Parameters | ||
---------- | ||
decimals: int, | ||
Number of decimal places to round to. | ||
Caller is responsible for validating this | ||
""" | ||
if self.dtype == _dtype_obj: | ||
round_func = functools.partial(round, ndigits=decimals) | ||
mapper = functools.partial(algos.map_array, mapper=round_func) | ||
try: | ||
if self.values.ndim == 1: | ||
values = algos.map_array(self.values, round_func) | ||
else: | ||
values = np.apply_along_axis(mapper, 0, self.values) | ||
|
||
except TypeError as err: | ||
raise TypeError("Expected numeric entries for dtype object.") from err | ||
|
||
refs = None | ||
if values is self.values: | ||
refs = self.refs | ||
|
||
return self.make_block_same_class(values, refs=refs) | ||
|
||
if not self.is_numeric or self.is_bool: | ||
return self.copy(deep=False) | ||
# TODO: round only defined on BaseMaskedArray | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, thanks for catching that