Skip to content

Commit fcea0dc

Browse files
jbrockmendelWillAyd
authored andcommitted
No catching needed for median (#28873)
1 parent 5cbd82b commit fcea0dc

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

pandas/core/groupby/groupby.py

+5-17
Original file line numberDiff line numberDiff line change
@@ -1234,23 +1234,11 @@ def median(self, **kwargs):
12341234
Series or DataFrame
12351235
Median of values within each group.
12361236
"""
1237-
try:
1238-
return self._cython_agg_general(
1239-
"median",
1240-
alt=lambda x, axis: Series(x).median(axis=axis, **kwargs),
1241-
**kwargs
1242-
)
1243-
except GroupByError:
1244-
raise
1245-
except Exception:
1246-
1247-
def f(x):
1248-
if isinstance(x, np.ndarray):
1249-
x = Series(x)
1250-
return x.median(axis=self.axis, **kwargs)
1251-
1252-
with _group_selection_context(self):
1253-
return self._python_agg_general(f)
1237+
return self._cython_agg_general(
1238+
"median",
1239+
alt=lambda x, axis: Series(x).median(axis=axis, **kwargs),
1240+
**kwargs
1241+
)
12541242

12551243
@Substitution(name="groupby")
12561244
@Appender(_common_see_also)

0 commit comments

Comments
 (0)