Skip to content

Commit 562f423

Browse files
jbrockmendelWillAyd
authored andcommitted
CLN: avoid catching Exception in _choose_path (#28205)
1 parent 30fb087 commit 562f423

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

pandas/core/groupby/generic.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -649,20 +649,21 @@ def _choose_path(self, fast_path, slow_path, group):
649649
# if we make it here, test if we can use the fast path
650650
try:
651651
res_fast = fast_path(group)
652-
653-
# verify fast path does not change columns (and names), otherwise
654-
# its results cannot be joined with those of the slow path
655-
if res_fast.columns != group.columns:
656-
return path, res
657-
# verify numerical equality with the slow path
658-
if res.shape == res_fast.shape:
659-
res_r = res.values.ravel()
660-
res_fast_r = res_fast.values.ravel()
661-
mask = notna(res_r)
662-
if (res_r[mask] == res_fast_r[mask]).all():
663-
path = fast_path
664652
except Exception:
665-
pass
653+
# Hard to know ex-ante what exceptions `fast_path` might raise
654+
return path, res
655+
656+
# verify fast path does not change columns (and names), otherwise
657+
# its results cannot be joined with those of the slow path
658+
if not isinstance(res_fast, DataFrame):
659+
return path, res
660+
661+
if not res_fast.columns.equals(group.columns):
662+
return path, res
663+
664+
if res_fast.equals(res):
665+
path = fast_path
666+
666667
return path, res
667668

668669
def _transform_item_by_item(self, obj, wrapper):

0 commit comments

Comments
 (0)