-
Notifications
You must be signed in to change notification settings - Fork 4.1k
[Python] Slicing an array backwards beyond the start doesn't include first item #38768
Copy link
Copy link
Closed
Description
When slicing an array "backwards" (with negative step, -1 in the example), and when the stop is "beyond" the start (larger negative number than number of elements), the first item is not included:
In [9]: arr = pa.array([0, 1, 2, 3, 4])
In [10]: arr[4:-6:-1]
Out[10]:
<pyarrow.lib.Int64Array object at 0x7faab0eaf8e0>
[
4,
3,
2,
1
]
While if we omit the stop (meaning, slice until the end, in this case of backwards slicing until the start), it works correctly:
In [11]: arr[4::-1]
Out[11]:
<pyarrow.lib.Int64Array object at 0x7faab0eac340>
[
4,
3,
2,
1,
0
]
I haven't yet checked if this is an issue in the underlying C++ slicing, or in the Python layer, eg in our "normalize_slice" logic:
arrow/python/pyarrow/array.pxi
Line 544 in 26cf0e0
| def _normalize_slice(object arrow_obj, slice key): |
Reactions are currently unavailable