Skip to content

Commit be2a042

Browse files
Khor Chean Weiphofl
Khor Chean Wei
authored andcommitted
Group by aggregate functions test case (pandas-dev#45763)
1 parent 6329bc7 commit be2a042

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pandas/tests/groupby/test_categorical.py

+18
Original file line numberDiff line numberDiff line change
@@ -1794,3 +1794,21 @@ def test_groupby_categorical_observed_nunique():
17941794
name="c",
17951795
)
17961796
tm.assert_series_equal(result, expected)
1797+
1798+
1799+
def test_groupby_categorical_aggregate_functions():
1800+
# GH#37275
1801+
dtype = pd.CategoricalDtype(categories=["small", "big"], ordered=True)
1802+
df = DataFrame(
1803+
[[1, "small"], [1, "big"], [2, "small"]], columns=["grp", "description"]
1804+
).astype({"description": dtype})
1805+
1806+
result = df.groupby("grp")["description"].max()
1807+
expected = Series(
1808+
["big", "small"],
1809+
index=Index([1, 2], name="grp"),
1810+
name="description",
1811+
dtype=pd.CategoricalDtype(categories=["small", "big"], ordered=True),
1812+
)
1813+
1814+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)