From edf2dae6db373729d8303a19851ae03e5e84364b Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 28 Aug 2019 15:04:33 -0700 Subject: [PATCH 1/3] avoid catching Exception in _choose_path --- pandas/core/groupby/generic.py | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 7d6690a0dfa5a..df2b42d618d01 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -644,22 +644,19 @@ def _choose_path(self, fast_path, slow_path, group): res = 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 + 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 not isinstance(res_fast, DataFrame): + return path, res + + if not res_fast.columns.equals(group.columns): + return path, res + + if res_fast.equals(res): + path = fast_path + return path, res def _transform_item_by_item(self, obj, wrapper): From 13c790c856c431788a905fe960247d26f6aca1f8 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 28 Aug 2019 16:16:54 -0700 Subject: [PATCH 2/3] catch ValueError in fast_path --- pandas/core/groupby/generic.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index df2b42d618d01..18a4f3821773c 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -644,7 +644,10 @@ def _choose_path(self, fast_path, slow_path, group): res = slow_path(group) # if we make it here, test if we can use the fast path - res_fast = fast_path(group) + try: + res_fast = fast_path(group) + except ValueError: + return path, res # verify fast path does not change columns (and names), otherwise # its results cannot be joined with those of the slow path From 65a93a218eea07f224a2478fdf9a1972b7b15a91 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 28 Aug 2019 16:54:08 -0700 Subject: [PATCH 3/3] catch more, begrudgingly --- pandas/core/groupby/generic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 18a4f3821773c..cb05d56216aec 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -646,7 +646,8 @@ 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) - except ValueError: + except Exception: + # Hard to know ex-ante what exceptions `fast_path` might raise return path, res # verify fast path does not change columns (and names), otherwise