Skip to content

Commit f34de9e

Browse files
committed
Merge pull request #3613 from jreback/groupby_dtype
BUG: Fix incorrect dtype on groupby with ``as_index=False`` (GH3610_)
2 parents f61d7e3 + a6d3127 commit f34de9e

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

RELEASE.rst

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ pandas 0.11.1
114114
in a frame (GH3594_)
115115
- Fix modulo and integer division on Series,DataFrames to act similary to ``float`` dtypes to return
116116
``np.nan`` or ``np.inf`` as appropriate (GH3590_)
117+
- Fix incorrect dtype on groupby with ``as_index=False`` (GH3610_)
117118

118119
.. _GH3164: https://github.com/pydata/pandas/issues/3164
119120
.. _GH2786: https://github.com/pydata/pandas/issues/2786
@@ -159,6 +160,7 @@ pandas 0.11.1
159160
.. _GH3556: https://github.com/pydata/pandas/issues/3556
160161
.. _GH3594: https://github.com/pydata/pandas/issues/3594
161162
.. _GH3590: https://github.com/pydata/pandas/issues/3590
163+
.. _GH3610: https://github.com/pydata/pandas/issues/3610
162164
.. _GH3435: https://github.com/pydata/pandas/issues/3435
163165

164166

pandas/core/groupby.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,7 @@ def aggregate(self, arg, *args, **kwargs):
17131713
result.insert(0, name, values)
17141714
result.index = np.arange(len(result))
17151715

1716-
return result
1716+
return result.convert_objects()
17171717

17181718
def _aggregate_multiple_funcs(self, arg):
17191719
from pandas.tools.merge import concat
@@ -2054,7 +2054,7 @@ def _wrap_aggregated_output(self, output, names=None):
20542054
if self.axis == 1:
20552055
result = result.T
20562056

2057-
return result
2057+
return result.convert_objects()
20582058

20592059
def _wrap_agged_blocks(self, blocks):
20602060
obj = self._obj_with_exclusions
@@ -2094,7 +2094,7 @@ def _wrap_agged_blocks(self, blocks):
20942094
if self.axis == 1:
20952095
result = result.T
20962096

2097-
return result
2097+
return result.convert_objects()
20982098

20992099

21002100
from pandas.tools.plotting import boxplot_frame_groupby

pandas/tests/test_groupby.py

+8
Original file line numberDiff line numberDiff line change
@@ -1842,6 +1842,14 @@ def test_apply_with_mixed_dtype(self):
18421842
result = df.apply(lambda x: x, axis=1)
18431843
assert_series_equal(df.get_dtype_counts(), result.get_dtype_counts())
18441844

1845+
1846+
# GH 3610 incorrect dtype conversion with as_index=False
1847+
df = DataFrame({"c1" : [1,2,6,6,8]})
1848+
df["c2"] = df.c1/2.0
1849+
result1 = df.groupby("c2").mean().reset_index().c2
1850+
result2 = df.groupby("c2", as_index=False).mean().c2
1851+
assert_series_equal(result1,result2)
1852+
18451853
def test_groupby_list_infer_array_like(self):
18461854
result = self.df.groupby(list(self.df['A'])).mean()
18471855
expected = self.df.groupby(self.df['A']).mean()

0 commit comments

Comments
 (0)