Skip to content

CLN: Exception*2 in groupby wrapper #28771

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 8 commits into from
Oct 8, 2019
Merged
Changes from 1 commit
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
Next Next commit
CLN: Specific exceptions instead of Exception x 2
  • Loading branch information
jbrockmendel committed Oct 3, 2019
commit f7f0f65a3084b2109a2d53ca69dc0bbed3a5270c
17 changes: 14 additions & 3 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class providing the base-class of operations.
from contextlib import contextmanager
import datetime
from functools import partial, wraps
import re
import types
from typing import FrozenSet, List, Optional, Tuple, Type, Union

Expand Down Expand Up @@ -638,10 +639,17 @@ def curried(x):

try:
return self.apply(curried_with_axis)
except Exception:
try:
except TypeError as err:
if "got an unexpected keyword argument 'axis'" in str(err):
# We need to use the `curried` instead of `curried_with_axis`
# Any exception other than needing to use `curried`
# rather than `curried_with_axis` gets re-raised.
return self.apply(curried)
except Exception:
elif re.search(
"reduction operation '.*' not allowed for this dtype", str(err)
):
# We don't have a cython implementation
# TODO: is the above comment accurate?

# related to : GH3688
# try item-by-item
Expand All @@ -653,7 +661,10 @@ def curried(x):
return self._aggregate_item_by_item(name, *args, **kwargs)
except AttributeError:
# e.g. SparseArray has no flags attr
# FIXME: 'SeriesGroupBy' object has no attribute '_aggregate_item_by_item'
# occurs in idxmax() case in tests.groupby.test_function.test_non_cython_api
raise ValueError
raise

return wrapper

Expand Down