Skip to content

An apply on a DataFrame along axis=1 breaks aggregations on groupby's of that DataFrame #3480

Closed
@gkoller

Description

@gkoller

This seems to be a regression from 0.10.1 to 0.11.0

This works:

from pandas import DataFrame
df = DataFrame({'foo1' : ['one', 'two', 'two', 'three', 'one', 'two'],
                'foo2' : np.random.randn(6)})
grouped = df.groupby('foo1')
grouped.agg(['mean'])

This does not (notice the apply):

from pandas import DataFrame
df = DataFrame({'foo1' : ['one', 'two', 'two', 'three', 'one', 'two'],
                'foo2' : np.random.randn(6)})
df = df.apply(lambda x: x, axis=1)
grouped = df.groupby('foo1')
grouped.agg(['mean'])

The error raised is:

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-47-4df234603be2> in <module>()
----> 1 grouped.agg(['mean'])

/Users/gkoller/.virtualenvs/abo/lib/python2.6/site-packages/pandas/core/groupby.pyc in agg(self, func, *args, **kwargs)
    336     @Appender(_agg_doc)
    337     def agg(self, func, *args, **kwargs):
--> 338         return self.aggregate(func, *args, **kwargs)
    339 
    340     def _iterate_slices(self):

/Users/gkoller/.virtualenvs/abo/lib/python2.6/site-packages/pandas/core/groupby.pyc in aggregate(self, arg, *args, **kwargs)
   1688                 result = DataFrame(result)
   1689         elif isinstance(arg, list):
-> 1690             return self._aggregate_multiple_funcs(arg)
   1691         else:
   1692             cyfunc = _intercept_cython(arg)

/Users/gkoller/.virtualenvs/abo/lib/python2.6/site-packages/pandas/core/groupby.pyc in _aggregate_multiple_funcs(self, arg)
   1736             except SpecificationError:
   1737                 raise
-> 1738         result = concat(results, keys=keys, axis=1)
   1739 
   1740         return result

/Users/gkoller/.virtualenvs/abo/lib/python2.6/site-packages/pandas/tools/merge.pyc in concat(objs, axis, join, join_axes, ignore_index, keys, levels, names, verify_integrity)
    870                        ignore_index=ignore_index, join=join,
    871                        keys=keys, levels=levels, names=names,
--> 872                        verify_integrity=verify_integrity)
    873     return op.get_result()
    874 

/Users/gkoller/.virtualenvs/abo/lib/python2.6/site-packages/pandas/tools/merge.pyc in __init__(self, objs, axis, join, join_axes, keys, levels, names, ignore_index, verify_integrity)
    911 
    912         if len(objs) == 0:
--> 913             raise Exception('All objects passed were None')
    914 
    915         # consolidate data

Exception: All objects passed were None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions