From 6f6c2602274ac69cd4e3d5ed48f7818054d41863 Mon Sep 17 00:00:00 2001 From: Kee Chong Tan Date: Sat, 2 Nov 2019 12:13:28 +0000 Subject: [PATCH 1/2] Add test_groupby_categorical_series_dataframe_consistent --- pandas/tests/groupby/test_categorical.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandas/tests/groupby/test_categorical.py b/pandas/tests/groupby/test_categorical.py index ad5d2315f7e33..3674187595d09 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -1193,6 +1193,13 @@ def test_seriesgroupby_observed_apply_dict(df_cat, observed, index, data): tm.assert_series_equal(result, expected) +def test_groupby_categorical_series_dataframe_consistent(df_cat): + # GH 20416 + expected = df_cat.groupby(['A', 'B'])['C'].mean() + result = df_cat.groupby(['A', 'B']).mean()['C'] + tm.assert_series_equal(result, expected) + + @pytest.mark.parametrize("code", [([1, 0, 0]), ([0, 0, 0])]) def test_groupby_categorical_axis_1(code): # GH 13420 From c0cd900f003401e36efc328079afa5e80a72822f Mon Sep 17 00:00:00 2001 From: Kee Chong Tan Date: Sat, 2 Nov 2019 12:20:16 +0000 Subject: [PATCH 2/2] Reformatting with Black --- pandas/tests/groupby/test_categorical.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/groupby/test_categorical.py b/pandas/tests/groupby/test_categorical.py index 3674187595d09..22a23407b2521 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -1195,8 +1195,8 @@ def test_seriesgroupby_observed_apply_dict(df_cat, observed, index, data): def test_groupby_categorical_series_dataframe_consistent(df_cat): # GH 20416 - expected = df_cat.groupby(['A', 'B'])['C'].mean() - result = df_cat.groupby(['A', 'B']).mean()['C'] + expected = df_cat.groupby(["A", "B"])["C"].mean() + result = df_cat.groupby(["A", "B"]).mean()["C"] tm.assert_series_equal(result, expected)