Skip to content

Commit

Permalink
Use zero-copy slice when step=1
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasG0 committed Mar 25, 2024
1 parent 5385bc8 commit b9df1e6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions python/pyarrow/array.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,13 @@ def _normalize_slice(object arrow_obj, slice key):
Py_ssize_t n = len(arrow_obj)

start, stop, step = key.indices(n)
indices = np.arange(start, stop, step)
return arrow_obj.take(indices)

if step != 1:
indices = np.arange(start, stop, step)
return arrow_obj.take(indices)
else:
length = max(stop - start, 0)
return arrow_obj.slice(start, length)


cdef Py_ssize_t _normalize_index(Py_ssize_t index,
Expand Down

0 comments on commit b9df1e6

Please sign in to comment.