Skip to content

Commit d61e523

Browse files
committed
#GH24205: test_groupby_nth_interval created
1 parent 57c4940 commit d61e523

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pandas/tests/groupby/test_nth.py

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

769769

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

0 commit comments

Comments
 (0)