Skip to content
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

BUG: Grouper(key='A') gives AttributeError when applying function #8795

Closed
jorisvandenbossche opened this issue Nov 12, 2014 · 2 comments · Fixed by #9008
Closed

BUG: Grouper(key='A') gives AttributeError when applying function #8795

jorisvandenbossche opened this issue Nov 12, 2014 · 2 comments · Fixed by #9008
Milestone

Comments

@jorisvandenbossche
Copy link
Member

I was playing a bit with pd.Grouper. Shouldn't the following work:

In [109]: df = pd.DataFrame({'A':[0,0,1,1,2,2], 'B':[1,2,3,4,5,6]})

In [110]: df
Out[110]:
   A  B
0  0  1
1  0  2
2  1  3
3  1  4
4  2  5
5  2  6

In [111]: df.groupby(pd.Grouper(key='A')).sum()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-111-b9e051aabea3> in <module>()
----> 1 df.groupby(pd.Grouper(key='A')).sum()

C:\Anaconda\lib\site-packages\pandas\core\groupby.pyc in f(self)
    108             raise SpecificationError(str(e))
    109         except Exception:
--> 110             result = self.aggregate(lambda x: npfunc(x, axis=self.axis))

    111             if _convert:
    112                 result = result.convert_objects()

C:\Anaconda\lib\site-packages\pandas\core\groupby.pyc in aggregate(self, arg, *a
rgs, **kwargs)
   2634                 return getattr(self, cyfunc)()
   2635
-> 2636             if self.grouper.nkeys > 1:
   2637                 return self._python_agg_general(arg, *args, **kwargs)
   2638             else:

AttributeError: 'Int64Index' object has no attribute 'nkeys'
@jreback
Copy link
Contributor

jreback commented Nov 12, 2014

yep, seems like a bug, that should work

of course df.groupby('A').sum() is the test against this

@jreback jreback added this to the 0.15.2 milestone Nov 12, 2014
@jorisvandenbossche
Copy link
Member Author

It seems this already was broken in 0.14.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants