Skip to content

BUG: DataFrame.agg({'col': 'size'}) not working #16405

Closed
@chmp

Description

@chmp

size aggregation does not seem to work properly when used with ungrouped dataframes. When replacing size with count the examples run through. However, this change null semantics, counting nulls (size) in contrast to skipping nulls (count). The examples below are for Pandas version 0.20.1.

When used with .groupby(...), size aggregation works as expected:

>>> pd.DataFrame({'g': [0, 0, 1], 'v': [1, 2, None]}).groupby('g').agg({'v': 'size'})
   v
g   
0  2
1  1

Without .groupby, it raises an recursion error:

>>> pd.DataFrame({'g': [0, 0, 1], 'v': [1, 2, None]}).agg({'v': 'size'})
---------------------------------------------------------------------------
RecursionError                            Traceback (most recent call last)
<ipython-input-15-5fc5c38cdb5f> in <module>()
----> 1 pd.DataFrame({'g': [0, 0, 1], 'v': [1, 2, 3]}).agg({'v': 'size'})

/Volumes/Home/venvs/py3-data-science/lib/python3.5/site-packages/pandas/core/frame.py in aggregate(self, func, axis, *args, **kwargs)
   4250                 pass
   4251         if result is None:
-> 4252             return self.apply(func, axis=axis, args=args, **kwargs)
   4253         return result
   4254 

/Volumes/Home/venvs/py3-data-science/lib/python3.5/site-packages/pandas/core/frame.py in apply(self, func, axis, broadcast, raw, reduce, args, **kwds)
   4322         # dispatch to agg
   4323         if axis == 0 and isinstance(func, (list, dict)):
-> 4324             return self.aggregate(func, axis=axis, *args, **kwds)
   4325 
   4326         if len(self.columns) == 0 and len(self.index) == 0:

... last 2 frames repeated, from the frame below ...

/Volumes/Home/venvs/py3-data-science/lib/python3.5/site-packages/pandas/core/frame.py in aggregate(self, func, axis, *args, **kwargs)
   4250                 pass
   4251         if result is None:
-> 4252             return self.apply(func, axis=axis, args=args, **kwargs)
   4253         return result
   4254 

RecursionError: maximum recursion depth exceeded

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions