8000 BUG: Groupby selection context not being properly reset by christopherzimmerman · Pull Request #28541 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG: Groupby selection context not being properly reset #28541

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

Closed
wants to merge 9 commits into from
Prev Previous commit
Another context needed to be set
  • Loading branch information
christopherzimmerman committed Oct 21, 2019
commit 30509636e34bfaa79eddd9cfad785d716fc9a8bb
13 changes: 7 additions & 6 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,9 @@ def curried(x):
# in tests.groupby.test_function.test_non_cython_api
raise ValueError

wrapper.__name__ = name
return wrapper
wrapper.__name__ = name

return wrapper

def get_group(self, name, obj=None):
"""
Expand Down Expand Up @@ -720,7 +721,9 @@ def f(g):
f = func

# ignore SettingWithCopy here in case the user mutates
with option_context("mode.chained_assignment", None):
with option_context(
"mode.chained_assignment", None
) as _, _group_selection_context(self) as _:
try:
result = self._python_apply_general(f)
except TypeError:
Expand All @@ -731,9 +734,7 @@ def f(g):
# except if the udf is trying an operation that
# fails on *some* columns, e.g. a numeric operation
# on a string grouper column

with _group_selection_context(self):
return self._python_apply_general(f)
return self._python_apply_general(f)

return result

Expand Down
0