diff --git a/python/pyarrow/array.pxi b/python/pyarrow/array.pxi index 72856bf1ecc..f195305da18 100644 --- a/python/pyarrow/array.pxi +++ b/python/pyarrow/array.pxi @@ -584,7 +584,9 @@ def _normalize_slice(object arrow_obj, slice key): start, stop, step = key.indices(n) if step != 1: - indices = np.arange(start, stop, step) + indices = list(range(start, stop, step)) + if len(indices) == 0: + return arrow_obj.slice(0, 0) return arrow_obj.take(indices) else: length = max(stop - start, 0) diff --git a/python/pyarrow/tests/test_array.py b/python/pyarrow/tests/test_array.py index 1a964cda6c0..44d796b3c91 100644 --- a/python/pyarrow/tests/test_array.py +++ b/python/pyarrow/tests/test_array.py @@ -488,15 +488,14 @@ def test_array_slice(): assert res.to_numpy().tolist() == expected -@pytest.mark.numpy def test_array_slice_negative_step(): # ARROW-2714 - np_arr = np.arange(20) - arr = pa.array(np_arr) + values = list(range(20)) + arr = pa.array(values) chunked_arr = pa.chunked_array([arr]) cases = [ - slice(None, None, -1), + slice(None, None, -1), # GH-46606 slice(None, 6, -2), slice(10, 6, -2), slice(8, None, -2), @@ -510,7 +509,7 @@ def test_array_slice_negative_step(): for case in cases: result = arr[case] - expected = pa.array(np_arr[case]) + expected = pa.array(values[case], type=arr.type) assert result.equals(expected) result = pa.record_batch([arr], names=['f0'])[case] @@ -518,7 +517,7 @@ def test_array_slice_negative_step(): assert result.equals(expected) result = chunked_arr[case] - expected = pa.chunked_array([np_arr[case]]) + expected = pa.chunked_array([values[case]], type=arr.type) assert result.equals(expected)