From cbd2df4861408f3055559ae1413a754c2b4f2d2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20Gonz=C3=A1lez?= Date: Sat, 13 Aug 2022 00:35:20 +0000 Subject: [PATCH] TST: Check MultiIndex when grouping by all columns of an empty DF (#32464) Co-authored-by: Richard Shadrach <45562402+rhshadrach@users.noreply.github.com> --- pandas/tests/groupby/test_function.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pandas/tests/groupby/test_function.py b/pandas/tests/groupby/test_function.py index 93e9b5bb776ab..45ac77bac9e02 100644 --- a/pandas/tests/groupby/test_function.py +++ b/pandas/tests/groupby/test_function.py @@ -1574,3 +1574,15 @@ def test_corrwith_with_1_axis(): ) expected = Series([np.nan] * 6, index=index) tm.assert_series_equal(result, expected) + + +def test_multiindex_group_all_columns_when_empty(groupby_func): + # GH 32464 + df = DataFrame({"a": [], "b": [], "c": []}).set_index(["a", "b", "c"]) + gb = df.groupby(["a", "b", "c"]) + method = getattr(gb, groupby_func) + args = get_groupby_method_args(groupby_func, df) + + result = method(*args).index + expected = df.index + tm.assert_index_equal(result, expected)