Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: Add tests for groupby categorical values with axis=1 #27788

Merged
merged 8 commits into from
Aug 7, 2019
10 changes: 10 additions & 0 deletions pandas/tests/groupby/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,3 +1165,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]})
grp = pd.Categorical.from_codes(code, categories=list("abc"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you call this cat instead of grp? The latter is typically the result of an actual groupby

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, changed! @WillAyd and thanks for taking a look!

result = df.groupby(grp, axis=1).mean()
expected = df.T.groupby(grp, axis=0).mean().T
assert_frame_equal(result, expected)