From 06210a1a4544a5b87854e9e346ad8dd82106c835 Mon Sep 17 00:00:00 2001 From: Minh Vu Date: Sat, 8 Aug 2026 21:05:10 +0200 Subject: [PATCH 1/3] Fix duplicate bin detection for large cut inputs --- python/cudf/cudf/core/cut.py | 2 +- python/cudf/cudf/tests/general_functions/test_cut.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/python/cudf/cudf/core/cut.py b/python/cudf/cudf/core/cut.py index 046aaa9bf698..ff1041ac5596 100644 --- a/python/cudf/cudf/core/cut.py +++ b/python/cudf/cudf/core/cut.py @@ -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" diff --git a/python/cudf/cudf/tests/general_functions/test_cut.py b/python/cudf/cudf/tests/general_functions/test_cut.py index ffcc0da2c0c4..1faca0ac2368 100644 --- a/python/cudf/cudf/tests/general_functions/test_cut.py +++ b/python/cudf/cudf/tests/general_functions/test_cut.py @@ -230,6 +230,16 @@ 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) + + @pytest.mark.parametrize( "x", [ From 79764d7f2d504dd90615eef1c1ceb0b251b6dac0 Mon Sep 17 00:00:00 2001 From: Minh Vu Date: Sat, 8 Aug 2026 21:12:44 +0200 Subject: [PATCH 2/3] Add duplicate edge regression coverage --- python/cudf/cudf/tests/general_functions/test_cut.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/python/cudf/cudf/tests/general_functions/test_cut.py b/python/cudf/cudf/tests/general_functions/test_cut.py index 1faca0ac2368..8640e5401006 100644 --- a/python/cudf/cudf/tests/general_functions/test_cut.py +++ b/python/cudf/cudf/tests/general_functions/test_cut.py @@ -240,6 +240,18 @@ def test_cut_unique_bins_larger_than_integer_cache(): assert_eq(expected, actual) +def test_cut_duplicate_bins_with_distinct_large_integers(): + x = [1, 2] + duplicate_edge = int("257") + bins = [0, duplicate_edge, int("257"), 258] + + 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", [ From e471df227f6615ebb69cbe94683231e034e0c370 Mon Sep 17 00:00:00 2001 From: Minh Vu Date: Mon, 10 Aug 2026 18:20:30 +0200 Subject: [PATCH 3/3] Explain distinct duplicate bin construction --- python/cudf/cudf/tests/general_functions/test_cut.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/cudf/cudf/tests/general_functions/test_cut.py b/python/cudf/cudf/tests/general_functions/test_cut.py index 8640e5401006..d53466e6c246 100644 --- a/python/cudf/cudf/tests/general_functions/test_cut.py +++ b/python/cudf/cudf/tests/general_functions/test_cut.py @@ -242,6 +242,7 @@ def test_cut_unique_bins_larger_than_integer_cache(): 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]