Skip to content

Commit 7bb0c87

Browse files
authored
Resolve issue pandas-dev#36158
As described in issue pandas-dev#36158 multi-dimensional groups prepared with lambda raise error on indices as isnan() is not defined for MultiIndex. Grouping already has the check for MultiIndex on line 440, but it's not triggered on __init__ when grouper is represented by lambda function and gets casted to MultiIndex later where MT stays as is.
1 parent 27aae22 commit 7bb0c87

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

pandas/core/groupby/grouper.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,10 @@ def __init__(
516516
t = self.name or str(type(self.grouper))
517517
raise ValueError(f"Grouper for '{t}' not 1-dimensional")
518518
self.grouper = self.index.map(self.grouper)
519+
520+
if isinstance(grouper, MultiIndex):
521+
self.grouper = grouper._values
522+
519523
if not (
520524
hasattr(self.grouper, "__len__")
521525
and len(self.grouper) == len(self.index)

0 commit comments

Comments
 (0)