Skip to content

BUG: nth on series groupby with dropna=True gives TypeError #7628

Closed
@jorisvandenbossche

Description

@jorisvandenbossche

From the docs: http://pandas-docs.github.io/pandas-docs-travis/groupby.html#taking-the-nth-row-of-each-group

In [1]: df = DataFrame([[1, np.nan], [1, 4], [5, 6]], columns=['A', 'B'])

In [2]: g = df.groupby('A')

In [3]: g.B.nth(0, dropna=True)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-bcb9dcbefdf5> in <module>()
----> 1 g.B.nth(0, dropna=True)

C:\Users\vdbosscj\Scipy\pandas-joris\pandas\core\groupby.py in nth(self, n, drop
na)
    831         # get a new grouper for our dropped obj
    832         grouper, exclusions, obj = _get_grouper(dropped, key=self.keys,
axis=self.axis,
--> 833                                                 level=self.level, sort=s
elf.sort)
    834
    835         sizes = obj.groupby(grouper).size()

C:\Users\vdbosscj\Scipy\pandas-joris\pandas\core\groupby.py in _get_grouper(obj,
 key, axis, level, sort)
   2035             raise AssertionError(errmsg)
   2036
-> 2037         ping = Grouping(group_axis, gpr, obj=obj, name=name, level=level
, sort=sort)
   2038         groupings.append(ping)
   2039

C:\Users\vdbosscj\Scipy\pandas-joris\pandas\core\groupby.py in __init__(self, in
dex, grouper, obj, name, level, sort)
   1874             # no level passed
   1875             if not isinstance(self.grouper, (Series, np.ndarray)):
-> 1876                 self.grouper = self.index.map(self.grouper)
   1877                 if not (hasattr(self.grouper, "__len__") and
   1878                         len(self.grouper) == len(self.index)):

C:\Users\vdbosscj\Scipy\pandas-joris\pandas\core\index.py in map(self, mapper)
   1332
   1333     def map(self, mapper):
-> 1334         return self._arrmap(self.values, mapper)
   1335
   1336     def isin(self, values):

C:\Users\vdbosscj\Scipy\pandas-joris\pandas\algos.pyd in pandas.algos.arrmap_int
64 (pandas\algos.c:72351)()

TypeError: 'NoneType' object is not callable

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions