Skip to content

Commit 58d34d9

Browse files
jbrockmendeljreback
authored andcommitted
CLN: catch less in groupby (pandas-dev#29077)
1 parent 45dc6d3 commit 58d34d9

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

pandas/core/groupby/generic.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -889,9 +889,23 @@ def aggregate(self, func=None, *args, **kwargs):
889889
result = self._aggregate_multiple_funcs(
890890
[func], _level=_level, _axis=self.axis
891891
)
892-
except AssertionError:
893-
raise
894-
except Exception:
892+
except ValueError as err:
893+
if "no results" not in str(err):
894+
# raised directly by _aggregate_multiple_funcs
895+
raise
896+
result = self._aggregate_frame(func)
897+
except NotImplementedError as err:
898+
if "axis other than 0 is not supported" in str(err):
899+
# raised directly by _aggregate_multiple_funcs
900+
pass
901+
elif "decimal does not support skipna=True" in str(err):
902+
# FIXME: kludge for DecimalArray tests
903+
pass
904+
else:
905+
raise
906+
# FIXME: this is raised in a bunch of
907+
# test_whitelist.test_regression_whitelist_methods tests,
908+
# can be avoided
895909
result = self._aggregate_frame(func)
896910
else:
897911
result.columns = Index(

pandas/core/resample.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries
1818

1919
import pandas.core.algorithms as algos
20+
from pandas.core.base import DataError
2021
from pandas.core.generic import _shared_docs
2122
from pandas.core.groupby.base import GroupByMixin
2223
from pandas.core.groupby.generic import SeriesGroupBy
@@ -362,7 +363,23 @@ def _groupby_and_aggregate(self, how, grouper=None, *args, **kwargs):
362363
result = grouped.aggregate(how, *args, **kwargs)
363364
except AssertionError:
364365
raise
365-
except Exception:
366+
except DataError:
367+
# we have a non-reducing function; try to evaluate
368+
result = grouped.apply(how, *args, **kwargs)
369+
except ValueError as err:
370+
if "Must produce aggregated value" in str(err):
371+
# raised in _aggregate_named
372+
pass
373+
elif "len(index) != len(labels)" in str(err):
374+
# raised in libgroupby validation
375+
pass
376+
elif "No objects to concatenate" in str(err):
377+
# raised in concat call
378+
# In tests this is reached via either
379+
# _apply_to_column_groupbys (ohlc) or DataFrameGroupBy.nunique
380+
pass
381+
else:
382+
raise
366383

367384
# we have a non-reducing function
368385
# try to evaluate

0 commit comments

Comments
 (0)