BUG: Fix segfault in GroupBy.count and DataFrame.count
- [x] closes #32841 
- [x] closes #21824
- [x] tests added / passed
- [x] passes `black pandas`
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

Hello @tv3141! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:







There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers: 

##### Comment last updated at 2020-03-29 16:22:27 UTC So far, this PR does not fix the related https://github.com/pandas-dev/pandas/issues/21824.

One option would be to mask rows `-1` as well in the calling code as well. But I think it would be good to prevent SegFaults in `count_level_2d` itself, especially if bound checking should be disabled for performance.  > Thanks for taking a look; on first pass I think this code is essentially the same thing though?
> 
> Do you know which array access / index is actually causing the OOB error?

`labels` contains `-1`s when the groupby column contains `NaN`s. 

The calling function `count()` creates `mask` for `-1`s, and `count_level_2d` would ignore masked values. This changed with https://github.com/pandas-dev/pandas/commit/d968aab3da13f68fabbb05f8eba12927d8bc5836#diff-8fa7422077eecd07a4006c11c78fc93aL1265-L1268, since then out-of-bounds access on `counts` can happen. ping @jreback  @tv3141 can you fix merge conflict in whatsnew? Otherwise lgtm as well @jbrockmendel any comments outstanding on this? this looks good. i think ok to merge. no objections here Great thanks @tv3141 