diff --git a/pandas/tests/test_groupby.py b/pandas/tests/test_groupby.py index 7b98a453957528..65e98b17a228e6 100644 --- a/pandas/tests/test_groupby.py +++ b/pandas/tests/test_groupby.py @@ -6778,9 +6778,19 @@ def test_groupby_multi_categorical_as_index(self): 'B': [101.0, nan, nan, 205.0, nan, nan]}, columns=['cat', 'A', 'B']) + group_columns = ['cat', 'A'] + for name in [None, 'X', 'B', 'cat']: df.index = Index(list("abc"), name=name) - result = df.groupby(['cat', 'A'], as_index=False).sum() + + if name in group_columns and name in df.index.names: + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + result = df.groupby(group_columns, as_index=False).sum() + + else: + result = df.groupby(group_columns, as_index=False).sum() + tm.assert_frame_equal(result, expected, check_index_type=True) def test_groupby_preserve_categorical_dtype(self):