Skip to content

Commit 3bdac3e

Browse files
charlesdong1991WillAyd
authored andcommitted
TST: Add tests for groupby categorical values with axis=1 (pandas-dev#27788)
1 parent 3bf35c6 commit 3bdac3e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pandas/tests/groupby/test_categorical.py

+10
Original file line numberDiff line numberDiff line change
@@ -1163,3 +1163,13 @@ def test_seriesgroupby_observed_apply_dict(df_cat, observed, index, data):
11631163
lambda x: OrderedDict([("min", x.min()), ("max", x.max())])
11641164
)
11651165
assert_series_equal(result, expected)
1166+
1167+
1168+
@pytest.mark.parametrize("code", [([1, 0, 0]), ([0, 0, 0])])
1169+
def test_groupby_categorical_axis_1(code):
1170+
# GH 13420
1171+
df = DataFrame({"a": [1, 2, 3, 4], "b": [-1, -2, -3, -4], "c": [5, 6, 7, 8]})
1172+
cat = pd.Categorical.from_codes(code, categories=list("abc"))
1173+
result = df.groupby(cat, axis=1).mean()
1174+
expected = df.T.groupby(cat, axis=0).mean().T
1175+
assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)