Skip to content

TEST: cut() with nullable Int64 dtype #51384

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

Merged
merged 6 commits into from
Feb 16, 2023
Merged
Changes from all 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
15 changes: 15 additions & 0 deletions pandas/tests/reshape/test_cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,3 +744,18 @@ def test_cut_bins_datetime_intervalindex():
result = cut(Series([Timestamp("2022-02-26")]), bins=bins)
expected = Categorical.from_codes([0], bins, ordered=True)
tm.assert_categorical_equal(result.array, expected)


def test_cut_with_nullable_int64():
# GH 30787
series = Series([0, 1, 2, 3, 4, pd.NA, 6, 7], dtype="Int64")
bins = [0, 2, 4, 6, 8]
intervals = IntervalIndex.from_breaks(bins)

expected = Series(
Categorical.from_codes([-1, 0, 0, 1, 1, -1, 2, 3], intervals, ordered=True)
)

result = cut(series, bins=bins)

tm.assert_series_equal(result, expected)