Skip to content

TST: fix DecimalArray._reduce kludges #29630

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

Merged
merged 4 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,13 +897,6 @@ def aggregate(self, func=None, *args, **kwargs):
# raised directly by _aggregate_multiple_funcs
raise
result = self._aggregate_frame(func)
except NotImplementedError as err:
if "decimal does not support skipna=True" in str(err):
# FIXME: kludge for DecimalArray tests
pass
else:
raise
result = self._aggregate_frame(func)
else:
result.columns = Index(
result.columns.levels[0], name=self._selected_obj.columns.name
Expand Down
3 changes: 0 additions & 3 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,9 +1349,6 @@ def f(self, **kwargs):
# raised in _get_cython_function, in some cases can
# be trimmed by implementing cython funcs for more dtypes
pass
elif "decimal does not support skipna=True" in str(err):
# FIXME: kludge for test_decimal:test_in_numeric_groupby
pass
else:
raise

Expand Down
9 changes: 8 additions & 1 deletion pandas/tests/extension/decimal/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,14 @@ def _concat_same_type(cls, to_concat):
def _reduce(self, name, skipna=True, **kwargs):

if skipna:
raise NotImplementedError("decimal does not support skipna=True")
# If we don't have any NAs, we can ignore skipna
if self.isna().any():
other = self[~self.isna()]
return other._reduce(name, **kwargs)

if name == "sum" and len(self) == 0:
# GH#29630 avoid returning int 0 or np.bool_(False) on old numpy
return decimal.Decimal(0)

try:
op = getattr(self.data, name)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/extension/decimal/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class TestMissing(BaseDecimal, base.BaseMissingTests):
class Reduce:
def check_reduce(self, s, op_name, skipna):

if skipna or op_name in ["median", "skew", "kurt"]:
if op_name in ["median", "skew", "kurt"]:
with pytest.raises(NotImplementedError):
getattr(s, op_name)(skipna=skipna)

Expand Down