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

Support boolean data in Cythonized groupby #315

Closed
wesm opened this issue Nov 1, 2011 · 3 comments

Comments

@wesm
Copy link
Member

commented Nov 1, 2011

reported by @bburan on the mailing list


In [146]: frame = DataFrame({'a': np.random.randint(0, 5, 10), 'b': np.random.ra
ndint(0, 2, 10).astype('bool')})

In [147]: print frame
  a  b
0  1  False
1  2  True
2  2  True
3  1  True
4  3  True
5  3  True
6  3  True
7  1  True
8  2  True
9  1  False

In [150]: frame.groupby('a')['b'].mean()
---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
c:\users\brad\projects\sane\src\sane\scripts\<ipython-input-150-fceb5b21892e> in
 <module>()
----> 1 frame.groupby('a')['b'].mean()

C:\Python27\lib\site-packages\pandas\core\groupby.pyc in mean(self)
   297         For multiple groupings, the result index will be a MultiIndex
   298         """
--> 299         return self._cython_agg_general('mean')
   300
   301     def size(self):

C:\Python27\lib\site-packages\pandas\core\groupby.pyc in _cython_agg_general(sel
f, how)
   347             output[name] = result[mask]
   348
--> 349         return self._wrap_aggregated_output(output, mask)
   350
   351     def _get_multi_index(self, mask):

UnboundLocalError: local variable 'mask' referenced before assignment

Note that agg() does work:

In [153]: frame.groupby('a')['b'].agg(np.mean)
Out[153]:
1    0.5
2    1.0
3    1.0
Name: None, Length: 3
@bburan

This comment has been minimized.

Copy link

commented Nov 1, 2011

I would also (when appropriate such as for non-numeric column types), catch the UnboundLocalError and raise a different error message (e.g. NotImplementedError). Some people may be perplexed by the UnboundLocalError and resulting traceback, but a NotImplementedError would hopefully be a clearer indication of what went wrong.

@wesm

This comment has been minimized.

Copy link
Member Author

commented Nov 1, 2011

Definitely-- I'll take care of both of those problems

@wesm

This comment has been minimized.

Copy link
Member Author

commented Nov 3, 2011

Took care of these two issues in the above commits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.