Skip to content

Commit b9ff59c

Browse files
committed
Merge pull request #3913 from jreback/groupby_apply
BUG: (GH3911) groupby appying with custom function not converting dtypes of result
2 parents 4e02cae + fd6be3d commit b9ff59c

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

RELEASE.rst

+5-1
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,11 @@ pandas 0.11.1
234234
- ``read_html`` now correctly skips tests (GH3741_)
235235
- PandasObjects raise TypeError when trying to hash (GH3882_)
236236
- Fix incorrect arguments passed to concat that are not list-like (e.g. concat(df1,df2)) (GH3481_)
237-
- Correctly parse when passed the ``dtype=str`` (or other variable-len string dtypes) in ``read_csv`` (GH3795_)
237+
- Correctly parse when passed the ``dtype=str`` (or other variable-len string dtypes)
238+
in ``read_csv`` (GH3795_)
238239
- Fix index name not propogating when using ``loc/ix`` (GH3880_)
240+
- Fix groupby when applying a custom function resulting in a returned DataFrame was
241+
not converting dtypes (GH3911_)
239242

240243
.. _GH3164: https://github.com/pydata/pandas/issues/3164
241244
.. _GH2786: https://github.com/pydata/pandas/issues/2786
@@ -331,6 +334,7 @@ pandas 0.11.1
331334
.. _GH3873: https://github.com/pydata/pandas/issues/3873
332335
.. _GH3877: https://github.com/pydata/pandas/issues/3877
333336
.. _GH3880: https://github.com/pydata/pandas/issues/3880
337+
.. _GH3911: https://github.com/pydata/pandas/issues/3911
334338

335339

336340
pandas 0.11.0

pandas/core/groupby.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,7 @@ def _wrap_applied_output(self, keys, values, not_indexed_same=False):
19281928
return Series(values, index=key_index)
19291929

19301930
return DataFrame(stacked_values, index=index,
1931-
columns=columns)
1931+
columns=columns).convert_objects()
19321932

19331933
else:
19341934
return Series(values, index=key_index)

pandas/tests/test_groupby.py

+14
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,20 @@ def test_groupby_nonobject_dtype(self):
261261
expected = self.mframe.groupby(key.astype('O')).sum()
262262
assert_frame_equal(result, expected)
263263

264+
# GH 3911, mixed frame non-conversion
265+
df = self.df_mixed_floats.copy()
266+
df['value'] = range(len(df))
267+
268+
def max_value(group):
269+
return group.ix[group['value'].idxmax()]
270+
271+
applied = df.groupby('A').apply(max_value)
272+
result = applied.get_dtype_counts()
273+
result.sort()
274+
expected = Series({ 'object' : 2, 'float64' : 2, 'int64' : 1 })
275+
expected.sort()
276+
assert_series_equal(result,expected)
277+
264278
def test_groupby_return_type(self):
265279

266280
# GH2893, return a reduced type

0 commit comments

Comments
 (0)