diff --git a/RELEASE.rst b/RELEASE.rst index d81a0e405ddd9..006da5f8e76af 100644 --- a/RELEASE.rst +++ b/RELEASE.rst @@ -114,6 +114,7 @@ pandas 0.11.1 in a frame (GH3594_) - Fix modulo and integer division on Series,DataFrames to act similary to ``float`` dtypes to return ``np.nan`` or ``np.inf`` as appropriate (GH3590_) + - Fix incorrect dtype on groupby with ``as_index=False`` (GH3610_) .. _GH3164: https://github.com/pydata/pandas/issues/3164 .. _GH2786: https://github.com/pydata/pandas/issues/2786 @@ -159,6 +160,7 @@ pandas 0.11.1 .. _GH3556: https://github.com/pydata/pandas/issues/3556 .. _GH3594: https://github.com/pydata/pandas/issues/3594 .. _GH3590: https://github.com/pydata/pandas/issues/3590 +.. _GH3610: https://github.com/pydata/pandas/issues/3610 .. _GH3435: https://github.com/pydata/pandas/issues/3435 diff --git a/pandas/core/groupby.py b/pandas/core/groupby.py index 7762803b029e9..093c61ba5af5c 100644 --- a/pandas/core/groupby.py +++ b/pandas/core/groupby.py @@ -1713,7 +1713,7 @@ def aggregate(self, arg, *args, **kwargs): result.insert(0, name, values) result.index = np.arange(len(result)) - return result + return result.convert_objects() def _aggregate_multiple_funcs(self, arg): from pandas.tools.merge import concat @@ -2054,7 +2054,7 @@ def _wrap_aggregated_output(self, output, names=None): if self.axis == 1: result = result.T - return result + return result.convert_objects() def _wrap_agged_blocks(self, blocks): obj = self._obj_with_exclusions @@ -2094,7 +2094,7 @@ def _wrap_agged_blocks(self, blocks): if self.axis == 1: result = result.T - return result + return result.convert_objects() from pandas.tools.plotting import boxplot_frame_groupby diff --git a/pandas/tests/test_groupby.py b/pandas/tests/test_groupby.py index 23077655d5144..c1c4217cb6f62 100644 --- a/pandas/tests/test_groupby.py +++ b/pandas/tests/test_groupby.py @@ -1842,6 +1842,14 @@ def test_apply_with_mixed_dtype(self): result = df.apply(lambda x: x, axis=1) assert_series_equal(df.get_dtype_counts(), result.get_dtype_counts()) + + # GH 3610 incorrect dtype conversion with as_index=False + df = DataFrame({"c1" : [1,2,6,6,8]}) + df["c2"] = df.c1/2.0 + result1 = df.groupby("c2").mean().reset_index().c2 + result2 = df.groupby("c2", as_index=False).mean().c2 + assert_series_equal(result1,result2) + def test_groupby_list_infer_array_like(self): result = self.df.groupby(list(self.df['A'])).mean() expected = self.df.groupby(self.df['A']).mean()