Skip to content

CLN: avoid catching Exception in _choose_path #28205

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
Sep 2, 2019
Merged
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
27 changes: 14 additions & 13 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,20 +646,21 @@ def _choose_path(self, fast_path, slow_path, group):
# if we make it here, test if we can use the fast path
try:
res_fast = fast_path(group)

# verify fast path does not change columns (and names), otherwise
# its results cannot be joined with those of the slow path
if res_fast.columns != group.columns:
return path, res
# verify numerical equality with the slow path
if res.shape == res_fast.shape:
res_r = res.values.ravel()
res_fast_r = res_fast.values.ravel()
mask = notna(res_r)
if (res_r[mask] == res_fast_r[mask]).all():
path = fast_path
except Exception:
pass
# Hard to know ex-ante what exceptions `fast_path` might raise
return path, res

# verify fast path does not change columns (and names), otherwise
# its results cannot be joined with those of the slow path
if not isinstance(res_fast, DataFrame):
return path, res

if not res_fast.columns.equals(group.columns):
Copy link
Member

Choose a reason for hiding this comment

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

Can you add this condition to the check above?

Copy link
Member Author

Choose a reason for hiding this comment

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

for coverage purposes Id rather leave them separate. i.e. i want to be able to see that both cases are reached

return path, res

if res_fast.equals(res):
path = fast_path

return path, res

def _transform_item_by_item(self, obj, wrapper):
Expand Down