Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def cut(

# bins can either be an int, sequence of scalars or an intervalIndex
if isinstance(bins, Sequence):
if len(set(bins)) is not len(bins):
if len(set(bins)) != len(bins):
if duplicates == "raise":
raise ValueError(
f"Bin edges must be unique: {bins!r}.\n"
Expand Down
23 changes: 23 additions & 0 deletions python/cudf/cudf/tests/general_functions/test_cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,29 @@ def test_cut_drop_duplicates_raises(
)


def test_cut_unique_bins_larger_than_integer_cache():
x = [1, 2]
bins = list(range(257))

expected = pd.cut(x=x, bins=bins, labels=False)
actual = cut(x=x, bins=bins, labels=False)

assert_eq(expected, actual)
Comment thread
coderabbitai[bot] marked this conversation as resolved.


def test_cut_duplicate_bins_with_distinct_large_integers():
x = [1, 2]
# Construct equal bin edges independently so they are distinct objects.
duplicate_edge = int("257")
bins = [0, duplicate_edge, int("257"), 258]
Comment thread
mroeschke marked this conversation as resolved.

assert bins[1] == bins[2]
assert bins[1] is not bins[2]

with pytest.raises(ValueError, match="Bin edges must be unique"):
cut(x=x, bins=bins, labels=False)


@pytest.mark.parametrize(
"x",
[
Expand Down
Loading