Skip to content

Commit

Permalink
TST: groupby.nth with MultiIndex Interval (#52968)
Browse files Browse the repository at this point in the history
  • Loading branch information
ltartaro authored Apr 29, 2023
1 parent 9f5b44c commit a3c9a5c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pandas/tests/groupby/test_nth.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,29 @@ def test_groupby_nth_with_column_axis():
tm.assert_frame_equal(result, expected)


def test_groupby_nth_interval():
# GH#24205
idx_result = MultiIndex(
[
pd.CategoricalIndex([pd.Interval(0, 1), pd.Interval(1, 2)]),
pd.CategoricalIndex([pd.Interval(0, 10), pd.Interval(10, 20)]),
],
[[0, 0, 0, 1, 1], [0, 1, 1, 0, -1]],
)
df_result = DataFrame({"col": range(len(idx_result))}, index=idx_result)
result = df_result.groupby(level=[0, 1], observed=False).nth(0)
val_expected = [0, 1, 3]
idx_expected = MultiIndex(
[
pd.CategoricalIndex([pd.Interval(0, 1), pd.Interval(1, 2)]),
pd.CategoricalIndex([pd.Interval(0, 10), pd.Interval(10, 20)]),
],
[[0, 0, 1], [0, 1, 0]],
)
expected = DataFrame(val_expected, index=idx_expected, columns=["col"])
tm.assert_frame_equal(result, expected)


@pytest.mark.parametrize(
"start, stop, expected_values, expected_columns",
[
Expand Down

0 comments on commit a3c9a5c

Please sign in to comment.