NVIDIA / NVIDIA/cudf

[BUG] `Column._scatter_by_slice` doesn't handle negative-stride slices correctly.

Open
#13,532 0 comments 0 reactions 0 assignees View on GitHub
0 - Backlog bug Python
Dominant language
C++
Stars
9.8k
Forks
1.1k
Avg merge
3d 6m
Merged PRs (30d)
278

Description

**Describe the bug**

```python
In [49]: col = cudf.core.column.as_column([1, 2, 3, 4])

In [50]: col
Out[50]:

[
1,
2,
3,
4
]
dtype: int64

In [51]: col[::-1] = cudf.Scalar(7)

In [52]: col
Out[52]:

[
1,
2,
3,
4
]
dtype: int64
```

This eventually calls `_scatter_by_slice`, which does this:

```python
def _scatter_by_slice(
self,
key: builtins.slice,
value: Union[cudf.core.scalar.Scalar, ColumnBase],
) -> Optional[Self]:
"""If this function returns None, it's either a no-op (slice is empty),
or the inplace replacement is already performed (fill-in-place).
"""
start, stop, step = key.indices(len(self))
if start >= stop:
return None
num_keys = len(range(start, stop, step))

```

But that first check is not right to determine if the slice is empty.

```python
# x[::-1]
slice(None, None, -1).indices(3)
# => (2, -1, -1)
```

**Expected behavior**

This should work.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.