Skip to content

Commit

Permalink
TST: Add tests for groupby categorical values with axis=1 (#27788)
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesdong1991 authored and WillAyd committed Aug 7, 2019
1 parent 3bf35c6 commit 3bdac3e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pandas/tests/groupby/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1163,3 +1163,13 @@ def test_seriesgroupby_observed_apply_dict(df_cat, observed, index, data):
lambda x: OrderedDict([("min", x.min()), ("max", x.max())])
)
assert_series_equal(result, expected)


@pytest.mark.parametrize("code", [([1, 0, 0]), ([0, 0, 0])])
def test_groupby_categorical_axis_1(code):
# GH 13420
df = DataFrame({"a": [1, 2, 3, 4], "b": [-1, -2, -3, -4], "c": [5, 6, 7, 8]})
cat = pd.Categorical.from_codes(code, categories=list("abc"))
result = df.groupby(cat, axis=1).mean()
expected = df.T.groupby(cat, axis=0).mean().T
assert_frame_equal(result, expected)

0 comments on commit 3bdac3e

Please sign in to comment.