Skip to content

CLN: catch less in groupby #29077

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 1 commit into from
Oct 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
20 changes: 17 additions & 3 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,9 +889,23 @@ def aggregate(self, func=None, *args, **kwargs):
result = self._aggregate_multiple_funcs(
[func], _level=_level, _axis=self.axis
)
except AssertionError:
raise
except Exception:
except ValueError as err:
if "no results" not in str(err):
# raised directly by _aggregate_multiple_funcs
raise
result = self._aggregate_frame(func)
except NotImplementedError as err:
if "axis other than 0 is not supported" in str(err):
# raised directly by _aggregate_multiple_funcs
pass
elif "decimal does not support skipna=True" in str(err):
# FIXME: kludge for DecimalArray tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the end goal of this change?
I don't think we should have special cases in the code for our tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The upcoming fix here is to have DecimalArray._reduce implement support skipna=True.

A lot of spaghetti code here is driven by the numeric_only behavior that suppresses exceptions.

pass
else:
raise
# FIXME: this is raised in a bunch of
# test_whitelist.test_regression_whitelist_methods tests,
# can be avoided
result = self._aggregate_frame(func)
else:
result.columns = Index(
Expand Down
19 changes: 18 additions & 1 deletion pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries

import pandas.core.algorithms as algos
from pandas.core.base import DataError
from pandas.core.generic import _shared_docs
from pandas.core.groupby.base import GroupByMixin
from pandas.core.groupby.generic import SeriesGroupBy
Expand Down Expand Up @@ -362,7 +363,23 @@ def _groupby_and_aggregate(self, how, grouper=None, *args, **kwargs):
result = grouped.aggregate(how, *args, **kwargs)
except AssertionError:
raise
except Exception:
except DataError:
# we have a non-reducing function; try to evaluate
result = grouped.apply(how, *args, **kwargs)
except ValueError as err:
if "Must produce aggregated value" in str(err):
# raised in _aggregate_named
pass
elif "len(index) != len(labels)" in str(err):
# raised in libgroupby validation
pass
elif "No objects to concatenate" in str(err):
# raised in concat call
# In tests this is reached via either
# _apply_to_column_groupbys (ohlc) or DataFrameGroupBy.nunique
pass
else:
raise

# we have a non-reducing function
# try to evaluate
Expand Down