Skip to content
/ cudf Public
forked from rapidsai/cudf

Commit

Permalink
Fix off-by-one in copy-range
Browse files Browse the repository at this point in the history
Only when copying a zero-length range can we afford to return the
target column. Closes rapidsai#12073.
  • Loading branch information
wence- committed Nov 4, 2022
1 parent 2a58ff6 commit a3ae461
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/cudf/cudf/_lib/copying.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions python/cudf/cudf/tests/test_setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down

0 comments on commit a3ae461

Please sign in to comment.