Skip to content

Commit 4b52854

Browse files
ltartaroYi Wei
authored and
Yi Wei
committed
TST: groupby.nth with MultiIndex Interval (pandas-dev#52968)
1 parent 913cf0e commit 4b52854

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

pandas/tests/groupby/test_nth.py

+23
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,29 @@ def test_groupby_nth_with_column_axis():
767767
tm.assert_frame_equal(result, expected)
768768

769769

770+
def test_groupby_nth_interval():
771+
# GH#24205
772+
idx_result = MultiIndex(
773+
[
774+
pd.CategoricalIndex([pd.Interval(0, 1), pd.Interval(1, 2)]),
775+
pd.CategoricalIndex([pd.Interval(0, 10), pd.Interval(10, 20)]),
776+
],
777+
[[0, 0, 0, 1, 1], [0, 1, 1, 0, -1]],
778+
)
779+
df_result = DataFrame({"col": range(len(idx_result))}, index=idx_result)
780+
result = df_result.groupby(level=[0, 1], observed=False).nth(0)
781+
val_expected = [0, 1, 3]
782+
idx_expected = MultiIndex(
783+
[
784+
pd.CategoricalIndex([pd.Interval(0, 1), pd.Interval(1, 2)]),
785+
pd.CategoricalIndex([pd.Interval(0, 10), pd.Interval(10, 20)]),
786+
],
787+
[[0, 0, 1], [0, 1, 0]],
788+
)
789+
expected = DataFrame(val_expected, index=idx_expected, columns=["col"])
790+
tm.assert_frame_equal(result, expected)
791+
792+
770793
@pytest.mark.parametrize(
771794
"start, stop, expected_values, expected_columns",
772795
[

0 commit comments

Comments
 (0)