Skip to content

Commit bffed36

Browse files
authored
BUG: GH27721 - test groupby rank with multiindex (#41084)
1 parent ad407f7 commit bffed36

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pandas/tests/groupby/test_rank.py

+22
Original file line numberDiff line numberDiff line change
@@ -578,3 +578,25 @@ def test_rank_pct_equal_values_on_group_transition(use_nan):
578578
expected = Series([1 / 3, 2 / 3, 1, 1], name="val")
579579

580580
tm.assert_series_equal(result, expected)
581+
582+
583+
def test_rank_multiindex():
584+
# GH27721
585+
df = concat(
586+
{
587+
"a": DataFrame({"col1": [1, 2], "col2": [3, 4]}),
588+
"b": DataFrame({"col3": [5, 6], "col4": [7, 8]}),
589+
},
590+
axis=1,
591+
)
592+
593+
result = df.groupby(level=0, axis=1).rank(axis=1, ascending=False, method="first")
594+
expected = concat(
595+
{
596+
"a": DataFrame({"col1": [2.0, 2.0], "col2": [1.0, 1.0]}),
597+
"b": DataFrame({"col3": [2.0, 2.0], "col4": [1.0, 1.0]}),
598+
},
599+
axis=1,
600+
)
601+
602+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)