From 775d0c1b6cd624a309b20ec871aaa7ef97d2dcb2 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sat, 16 Nov 2019 12:58:20 -0800 Subject: [PATCH] REF: remove unnecessary _try_cast calls (#29642) --- pandas/core/groupby/generic.py | 2 +- pandas/core/groupby/groupby.py | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 9073a1e31dfb02..f6c4836632795b 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -397,7 +397,7 @@ def _aggregate_named(self, func, *args, **kwargs): output = func(group, *args, **kwargs) if isinstance(output, (Series, Index, np.ndarray)): raise ValueError("Must produce aggregated value") - result[name] = self._try_cast(output, group) + result[name] = output return result diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 280f1e88b0ea8f..746fb21c5776e2 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -1357,14 +1357,6 @@ def f(self, **kwargs): # apply a non-cython aggregation result = self.aggregate(lambda x: npfunc(x, axis=self.axis)) - - # coerce the resulting columns if we can - if isinstance(result, DataFrame): - for col in result.columns: - result[col] = self._try_cast(result[col], self.obj[col]) - else: - result = self._try_cast(result, self.obj) - return result set_function_name(f, name, cls)