Skip to content

Commit d331b99

Browse files
committed
test for non-ordered Categorical rank
1 parent 31bef27 commit d331b99

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pandas/tests/groupby/test_rank.py

+17
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@
1313
import pandas._testing as tm
1414

1515

16+
def test_rank_unordered_categorical_typeerror():
17+
# GH#51034 should be TypeError, not NotImplementedError
18+
cat = pd.Categorical([], ordered=False)
19+
ser = Series(cat)
20+
df = ser.to_frame()
21+
22+
msg = "Cannot perform rank with non-ordered Categorical"
23+
24+
gb = ser.groupby(cat)
25+
with pytest.raises(TypeError, match=msg):
26+
gb.rank()
27+
28+
gb2 = df.groupby(cat)
29+
with pytest.raises(TypeError, match=msg):
30+
gb2.rank()
31+
32+
1633
def test_rank_apply():
1734
lev1 = tm.rands_array(10, 100)
1835
lev2 = tm.rands_array(10, 130)

0 commit comments

Comments
 (0)