Skip to content

CLN: dont catch Exception in groupby var #28883

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 10, 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
18 changes: 8 additions & 10 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class providing the base-class of operations.
)
from pandas.core.dtypes.missing import isna, notna

from pandas.core import nanops
import pandas.core.algorithms as algorithms
from pandas.core.arrays import Categorical
from pandas.core.base import (
Expand Down Expand Up @@ -721,6 +722,10 @@ def f(g):
with np.errstate(all="ignore"):
return func(g, *args, **kwargs)

elif hasattr(nanops, "nan" + func):
# TODO: should we wrap this in to e.g. _is_builtin_func?
Copy link
Member

Choose a reason for hiding this comment

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

That would seem logical; follow ups to figure out what is actually needed here are certainly welcome

f = getattr(nanops, "nan" + func)

else:
raise ValueError(
"func must be a callable if args or kwargs are supplied"
Expand Down Expand Up @@ -1297,16 +1302,9 @@ def var(self, ddof=1, *args, **kwargs):
"""
nv.validate_groupby_func("var", args, kwargs)
if ddof == 1:
try:
return self._cython_agg_general(
"var",
alt=lambda x, axis: Series(x).var(ddof=ddof, **kwargs),
**kwargs
)
except Exception:
f = lambda x: x.var(ddof=ddof, **kwargs)
with _group_selection_context(self):
return self._python_agg_general(f)
return self._cython_agg_general(
"var", alt=lambda x, axis: Series(x).var(ddof=ddof, **kwargs), **kwargs
)
else:
f = lambda x: x.var(ddof=ddof, **kwargs)
with _group_selection_context(self):
Expand Down