Skip to content

Commit 9d2c689

Browse files
author
Jon M. Mease
committed
Implemented GH 5677
1 parent f260463 commit 9d2c689

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pandas/core/groupby.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -2449,8 +2449,13 @@ def is_in_obj(gpr):
24492449
exclusions.append(name)
24502450

24512451
elif is_in_axis(gpr): # df.groupby('name')
2452-
in_axis, name, gpr = True, gpr, obj[gpr]
2453-
exclusions.append(name)
2452+
if gpr in obj:
2453+
in_axis, name, gpr = True, gpr, obj[gpr]
2454+
exclusions.append(name)
2455+
elif gpr in obj.index.names:
2456+
in_axis, name, level, gpr = False, None, gpr, None
2457+
else:
2458+
raise KeyError(gpr)
24542459
elif isinstance(gpr, Grouper) and gpr.key is not None:
24552460
# Add key to exclusions
24562461
exclusions.append(gpr.key)

0 commit comments

Comments
 (0)