Skip to content

BUG: (GH3911) groupby appying with custom function not converting dtypes of result #3913

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
Jun 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
6 changes: 5 additions & 1 deletion RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,11 @@ pandas 0.11.1
- ``read_html`` now correctly skips tests (GH3741_)
- PandasObjects raise TypeError when trying to hash (GH3882_)
- Fix incorrect arguments passed to concat that are not list-like (e.g. concat(df1,df2)) (GH3481_)
- Correctly parse when passed the ``dtype=str`` (or other variable-len string dtypes) in ``read_csv`` (GH3795_)
- Correctly parse when passed the ``dtype=str`` (or other variable-len string dtypes)
in ``read_csv`` (GH3795_)
- Fix index name not propogating when using ``loc/ix`` (GH3880_)
- Fix groupby when applying a custom function resulting in a returned DataFrame was
not converting dtypes (GH3911_)

.. _GH3164: https://github.com/pydata/pandas/issues/3164
.. _GH2786: https://github.com/pydata/pandas/issues/2786
Expand Down Expand Up @@ -331,6 +334,7 @@ pandas 0.11.1
.. _GH3873: https://github.com/pydata/pandas/issues/3873
.. _GH3877: https://github.com/pydata/pandas/issues/3877
.. _GH3880: https://github.com/pydata/pandas/issues/3880
.. _GH3911: https://github.com/pydata/pandas/issues/3911


pandas 0.11.0
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,7 @@ def _wrap_applied_output(self, keys, values, not_indexed_same=False):
return Series(values, index=key_index)

return DataFrame(stacked_values, index=index,
columns=columns)
columns=columns).convert_objects()

else:
return Series(values, index=key_index)
Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,20 @@ def test_groupby_nonobject_dtype(self):
expected = self.mframe.groupby(key.astype('O')).sum()
assert_frame_equal(result, expected)

# GH 3911, mixed frame non-conversion
df = self.df_mixed_floats.copy()
df['value'] = range(len(df))

def max_value(group):
return group.ix[group['value'].idxmax()]

applied = df.groupby('A').apply(max_value)
result = applied.get_dtype_counts()
result.sort()
expected = Series({ 'object' : 2, 'float64' : 2, 'int64' : 1 })
expected.sort()
assert_series_equal(result,expected)

def test_groupby_return_type(self):

# GH2893, return a reduced type
Expand Down