Skip to content

BUG: Fix incorrect dtype on groupby with as_index=False (GH3610_) #3613

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
May 15, 2013
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
6 changes: 3 additions & 3 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down