Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST #24205: test_groupby_nth_interval created for Groupby Nth with Multindex Inverval #52968

Merged
merged 5 commits into from
Apr 29, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pandas/tests/groupby/test_nth.py
100644 → 100755
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():
# 24205
ltartaro marked this conversation as resolved.
Show resolved Hide resolved
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