Skip to content

Commit 69b6d60

Browse files
author
y-p
committed
BUG: add length check on categorical grouper, GH3011
1 parent 9754f4d commit 69b6d60

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

doc/source/v0.11.0.txt

+4
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ Bug Fixes
316316
reporting (GH2807_)
317317
- Fix pretty-printing of infinite data structures (closes GH2978_)
318318
- str.contains ignored na argument (GH2806_)
319+
- Substitute warning for segfault when grouping with categorical grouper
320+
of mismatched length (GH3011_)
321+
319322

320323
See the `full release notes
321324
<https://github.com/pydata/pandas/blob/master/RELEASE.rst>`__ or issue tracker
@@ -331,3 +334,4 @@ on GitHub for a complete list.
331334
.. _GH2806: https://github.com/pydata/pandas/issues/2806
332335
.. _GH2807: https://github.com/pydata/pandas/issues/2807
333336
.. _GH2918: https://github.com/pydata/pandas/issues/2918
337+
.. _GH3011: https://github.com/pydata/pandas/issues/3011

pandas/core/groupby.py

+5
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,11 @@ def _get_grouper(obj, key=None, axis=0, level=None, sort=True):
13101310
exclusions.append(gpr)
13111311
name = gpr
13121312
gpr = obj[gpr]
1313+
1314+
if (isinstance(gpr,Categorical) and len(gpr) != len(obj)):
1315+
errmsg = "Categorical grouper must have len(grouper) == len(data)"
1316+
raise AssertionError(errmsg)
1317+
13131318
ping = Grouping(group_axis, gpr, name=name, level=level, sort=sort)
13141319
groupings.append(ping)
13151320

0 commit comments

Comments
 (0)