Skip to content

Commit e246c3b

Browse files
jbrockmendelTomAugspurger
authored andcommitted
TST: fix DecimalArray._reduce kludges (#29630)
* TST: fix DecimalArray._reduce kludges
1 parent 545d175 commit e246c3b

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

pandas/core/groupby/generic.py

-7
Original file line numberDiff line numberDiff line change
@@ -885,13 +885,6 @@ def aggregate(self, func=None, *args, **kwargs):
885885
# raised directly by _aggregate_multiple_funcs
886886
raise
887887
result = self._aggregate_frame(func)
888-
except NotImplementedError as err:
889-
if "decimal does not support skipna=True" in str(err):
890-
# FIXME: kludge for DecimalArray tests
891-
pass
892-
else:
893-
raise
894-
result = self._aggregate_frame(func)
895888
else:
896889
result.columns = Index(
897890
result.columns.levels[0], name=self._selected_obj.columns.name

pandas/core/groupby/groupby.py

-3
Original file line numberDiff line numberDiff line change
@@ -1342,9 +1342,6 @@ def f(self, **kwargs):
13421342
# raised in _get_cython_function, in some cases can
13431343
# be trimmed by implementing cython funcs for more dtypes
13441344
pass
1345-
elif "decimal does not support skipna=True" in str(err):
1346-
# FIXME: kludge for test_decimal:test_in_numeric_groupby
1347-
pass
13481345
else:
13491346
raise
13501347

pandas/tests/extension/decimal/array.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,14 @@ def _concat_same_type(cls, to_concat):
166166
def _reduce(self, name, skipna=True, **kwargs):
167167

168168
if skipna:
169-
raise NotImplementedError("decimal does not support skipna=True")
169+
# If we don't have any NAs, we can ignore skipna
170+
if self.isna().any():
171+
other = self[~self.isna()]
172+
return other._reduce(name, **kwargs)
173+
174+
if name == "sum" and len(self) == 0:
175+
# GH#29630 avoid returning int 0 or np.bool_(False) on old numpy
176+
return decimal.Decimal(0)
170177

171178
try:
172179
op = getattr(self.data, name)

pandas/tests/extension/decimal/test_decimal.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class TestMissing(BaseDecimal, base.BaseMissingTests):
145145
class Reduce:
146146
def check_reduce(self, s, op_name, skipna):
147147

148-
if skipna or op_name in ["median", "skew", "kurt"]:
148+
if op_name in ["median", "skew", "kurt"]:
149149
with pytest.raises(NotImplementedError):
150150
getattr(s, op_name)(skipna=skipna)
151151

0 commit comments

Comments
 (0)