From a3ae461eb7763d2d43d16954c56921fee3714e70 Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Fri, 4 Nov 2022 17:48:48 +0000 Subject: [PATCH] Fix off-by-one in copy-range Only when copying a zero-length range can we afford to return the target column. Closes #12073. --- python/cudf/cudf/_lib/copying.pyx | 2 +- python/cudf/cudf/tests/test_setitem.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/python/cudf/cudf/_lib/copying.pyx b/python/cudf/cudf/_lib/copying.pyx index d9a7a5b8754..f5c910ca77d 100644 --- a/python/cudf/cudf/_lib/copying.pyx +++ b/python/cudf/cudf/_lib/copying.pyx @@ -144,7 +144,7 @@ def copy_range(Column input_column, target_column from target_begin to target_end """ - if abs(target_end - target_begin) <= 1: + if abs(target_end - target_begin) < 1: return target_column if target_begin < 0: diff --git a/python/cudf/cudf/tests/test_setitem.py b/python/cudf/cudf/tests/test_setitem.py index 13b342e6c3b..bbf6f14d99f 100644 --- a/python/cudf/cudf/tests/test_setitem.py +++ b/python/cudf/cudf/tests/test_setitem.py @@ -108,6 +108,12 @@ def test_series_set_item(psr, arg): assert_eq(psr, gsr) +def test_series_setitem_singleton_range(): + sr = cudf.Series([1, 2, 3], dtype=np.int64) + sr.iloc[:1] = np.asarray([7], dtype=np.int64) + assert_eq(sr, cudf.Series([7, 2, 3], dtype=np.int64)) + + @pytest.mark.parametrize( "df", [