Skip to content

Commit d2e8c5f

Browse files
Fix error checking
Signed-off-by: Devin Petersohn <[email protected]>
1 parent 95f5510 commit d2e8c5f

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

modin/pandas/dataframe.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,16 @@ def groupby(
423423
# strings is passed in, the data used for the groupby is dropped before the
424424
# groupby takes place.
425425
drop = False
426-
426+
# Check that there is no ambiguity in the parameter we were given.
427+
_by_check = by if is_list_like(by) else [by]
428+
for k in _by_check:
429+
if k in self.index.names and k in self.axes[axis]:
430+
level_name, index_name = "an index", "a column"
431+
if axis == 1:
432+
level_name, index_name = index_name, level_name
433+
raise ValueError(
434+
f"{k} is both {level_name} level and {index_name} label, which is ambiguous."
435+
)
427436
if (
428437
not isinstance(by, (pandas.Series, Series))
429438
and is_list_like(by)
@@ -447,14 +456,6 @@ def groupby(
447456
idx_name = by.name
448457
by = by._query_compiler
449458
elif is_list_like(by):
450-
for k in by:
451-
if k in self.index.names and k in self.axes[axis]:
452-
level_name, index_name = "an index", "a column"
453-
if axis == 1:
454-
level_name, index_name = index_name, level_name
455-
raise ValueError(
456-
f"{k} is both {level_name} level and {index_name} label, which is ambiguous."
457-
)
458459
# fastpath for multi column groupby
459460
if axis == 0 and all(
460461
(

0 commit comments

Comments
 (0)