Skip to content

CLN: No catching needed for groupby median #28873

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
22 changes: 5 additions & 17 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,23 +1236,11 @@ def median(self, **kwargs):
Series or DataFrame
Median of values within each group.
"""
try:
return self._cython_agg_general(
"median",
alt=lambda x, axis: Series(x).median(axis=axis, **kwargs),
**kwargs
)
except GroupByError:
raise
except Exception:

def f(x):
if isinstance(x, np.ndarray):
x = Series(x)
return x.median(axis=self.axis, **kwargs)

with _group_selection_context(self):
return self._python_agg_general(f)
return self._cython_agg_general(
"median",
alt=lambda x, axis: Series(x).median(axis=axis, **kwargs),
**kwargs
)

@Substitution(name="groupby")
@Appender(_common_see_also)
Expand Down