From 0880ccec3f85530d5ebd0e1c6ad22661f00c9e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Wed, 11 Jun 2025 13:38:23 +0200 Subject: [PATCH 1/5] [Python][C++] Implement pa.arange function to generate array sequences --- python/pyarrow/__init__.py | 1 + python/pyarrow/array.pxi | 32 +++++++++++++++++---- python/pyarrow/includes/libarrow_python.pxd | 3 ++ python/pyarrow/src/arrow/python/helpers.cc | 18 ++++++++++++ python/pyarrow/src/arrow/python/helpers.h | 13 +++++++++ python/pyarrow/tests/test_array.py | 20 +++++++++++++ 6 files changed, 82 insertions(+), 5 deletions(-) diff --git a/python/pyarrow/__init__.py b/python/pyarrow/__init__.py index c732c13764d..3555fa4f31d 100644 --- a/python/pyarrow/__init__.py +++ b/python/pyarrow/__init__.py @@ -191,6 +191,7 @@ def print_entry(label, value): SparseCOOTensor, SparseCSRMatrix, SparseCSCMatrix, SparseCSFTensor, infer_type, from_numpy_dtype, + arange, NullArray, NumericArray, IntegerArray, FloatingPointArray, BooleanArray, diff --git a/python/pyarrow/array.pxi b/python/pyarrow/array.pxi index fc412990511..b80370c706a 100644 --- a/python/pyarrow/array.pxi +++ b/python/pyarrow/array.pxi @@ -572,22 +572,44 @@ def infer_type(values, mask=None, from_pandas=False): return pyarrow_wrap_data_type(out) +def arange(int64_t start, int64_t stop, int64_t step=1): + """ + Create an array of evenly spaced values within a given interval. + This function is similar to Python's `range` function. + The resulting array will contain values starting from `start` up to but not + including `stop`, with a step size of `step`. If `step` is zero, the function + will return an empty array. + + Parameters + ---------- + start : int + The starting value for the sequence. The returned array will include this value. + stop : int + The stopping value for the sequence. The returned array will not include this value. + step : int, default 1 + The spacing between values. + + Returns + ------- + arange : Array + """ + c_array = GetResultValue(Arange(start, stop, step)) + return pyarrow_wrap_array(c_array) + + def _normalize_slice(object arrow_obj, slice key): """ Slices with step not equal to 1 (or None) will produce a copy rather than a zero-copy view """ cdef: - Py_ssize_t start, stop, step + int64_t start, stop, step Py_ssize_t n = len(arrow_obj) start, stop, step = key.indices(n) if step != 1: - indices = list(range(start, stop, step)) - if len(indices) == 0: - return arrow_obj.slice(0, 0) - return arrow_obj.take(indices) + return arrow_obj.take(arange(start, stop, step)) else: length = max(stop - start, 0) return arrow_obj.slice(start, length) diff --git a/python/pyarrow/includes/libarrow_python.pxd b/python/pyarrow/includes/libarrow_python.pxd index e544aa0165d..ccf13fa75fb 100644 --- a/python/pyarrow/includes/libarrow_python.pxd +++ b/python/pyarrow/includes/libarrow_python.pxd @@ -73,6 +73,9 @@ cdef extern from "arrow/python/api.h" namespace "arrow::py" nogil: object obj, object mask, const PyConversionOptions& options, CMemoryPool* pool) + CResult[shared_ptr[CArray]] Arange(int64_t start, int64_t stop, + int64_t step) + CResult[shared_ptr[CDataType]] NumPyDtypeToArrow(object dtype) CStatus NdarrayToArrow(CMemoryPool* pool, object ao, object mo, diff --git a/python/pyarrow/src/arrow/python/helpers.cc b/python/pyarrow/src/arrow/python/helpers.cc index 0a24b259310..e5a85b9f90d 100644 --- a/python/pyarrow/src/arrow/python/helpers.cc +++ b/python/pyarrow/src/arrow/python/helpers.cc @@ -27,6 +27,7 @@ #include #include +#include "arrow/array.h" #include "arrow/python/common.h" #include "arrow/python/decimal.h" #include "arrow/type_fwd.h" @@ -94,6 +95,23 @@ Result PyFloat_AsHalf(PyObject* obj) { } } +Result> Arange(int64_t start, int64_t stop, int64_t step) { + double delta = static_cast(stop - start); + double size = std::ceil(delta / step); + + if (ARROW_PREDICT_FALSE(step == 0 || size <= 0)) { + return MakeEmptyArray(int64()); + } + std::shared_ptr data_buffer; + ARROW_ASSIGN_OR_RAISE(data_buffer, AllocateBuffer(size * sizeof(int64_t))); + auto values = reinterpret_cast(data_buffer->mutable_data()); + for (int64_t i = 0; i < size; ++i) { + values[i] = start + i * step; + } + auto data = ArrayData::Make(int64(), size, {nullptr, data_buffer}, 0); + return MakeArray(data); +} + namespace internal { std::string PyBytes_AsStdString(PyObject* obj) { diff --git a/python/pyarrow/src/arrow/python/helpers.h b/python/pyarrow/src/arrow/python/helpers.h index b0cf1010289..66aead7ef30 100644 --- a/python/pyarrow/src/arrow/python/helpers.h +++ b/python/pyarrow/src/arrow/python/helpers.h @@ -47,6 +47,19 @@ ARROW_PYTHON_EXPORT PyObject* PyFloat_FromHalf(uint16_t value); // \brief Convert a Python object to a half-float uint16_t value. ARROW_PYTHON_EXPORT Result PyFloat_AsHalf(PyObject* obj); +/// \brief Create an array of evenly spaced values within a given interval. +/// This function is similar to Python's `range` function. +/// The resulting array will contain values starting from `start` up to but not +/// including `stop`, with a step size of `step`. If `step` is zero, the function +/// will return an empty array. +/// The resulting array will have a data type of `int64`. +/// \param[in] start initial value of the sequence. +/// \param[in] stop final value of the sequence (exclusive). +/// \param[in] step step size between consecutive values. +/// \return Result Array +ARROW_PYTHON_EXPORT +Result> Arange(int64_t start, int64_t stop, int64_t step); + namespace internal { // \brief Check that a Python module has been already imported diff --git a/python/pyarrow/tests/test_array.py b/python/pyarrow/tests/test_array.py index 7dabb8396b2..68a51b3c46d 100644 --- a/python/pyarrow/tests/test_array.py +++ b/python/pyarrow/tests/test_array.py @@ -536,6 +536,26 @@ def test_array_slice_negative_step(): assert result.equals(expected) +def test_arange(): + cases = [ + (0, 10), # Default step + (0, 10, 1), + (0, 10, 2), + (10, 0, -1), + (10, 0, -2), + (0, 0), # Empty array + (0, 10, -1), # Empty array + (10, 0, 1), # Empty array + ] + for case in cases: + result = pa.arange(*case) + assert result.equals(pa.array(list(range(*case)), type=pa.int64())) + + # Special case for invalid step (range does not accept step of 0) + result = pa.arange(0, 10, 0) + assert result.equals(pa.array([], type=pa.int64())) + + def test_array_diff(): # ARROW-6252 arr1 = pa.array(['foo'], type=pa.utf8()) From 8be210c6005eb823c08b56cc01452bd4deab841f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Wed, 11 Jun 2025 15:41:36 +0200 Subject: [PATCH 2/5] Avoid unnecessary double/int64_t conversions --- python/pyarrow/src/arrow/python/helpers.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/python/pyarrow/src/arrow/python/helpers.cc b/python/pyarrow/src/arrow/python/helpers.cc index e5a85b9f90d..9b837aeed56 100644 --- a/python/pyarrow/src/arrow/python/helpers.cc +++ b/python/pyarrow/src/arrow/python/helpers.cc @@ -96,10 +96,14 @@ Result PyFloat_AsHalf(PyObject* obj) { } Result> Arange(int64_t start, int64_t stop, int64_t step) { - double delta = static_cast(stop - start); - double size = std::ceil(delta / step); - - if (ARROW_PREDICT_FALSE(step == 0 || size <= 0)) { + int64_t size; + if (step > 0 && stop > start) { + // Ceiling division for positive step + size = (stop - start + step - 1) / step; + } else if (step < 0 && stop < start) { + // Ceiling division for negative step + size = (start - stop - step - 1) / (-step); + } else { return MakeEmptyArray(int64()); } std::shared_ptr data_buffer; From e38a78d8f64ddc5763ef2f6d9db2faa6a59aa788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Thu, 12 Jun 2025 16:11:27 +0200 Subject: [PATCH 3/5] Add option memory pool, fix step == 0, improve docstrings and add more interesting test cases --- python/pyarrow/array.pxi | 16 +++++++++--- python/pyarrow/includes/libarrow_python.pxd | 2 +- python/pyarrow/src/arrow/python/helpers.cc | 8 ++++-- python/pyarrow/src/arrow/python/helpers.h | 6 +++-- python/pyarrow/tests/test_array.py | 28 +++++++++++++-------- 5 files changed, 40 insertions(+), 20 deletions(-) diff --git a/python/pyarrow/array.pxi b/python/pyarrow/array.pxi index b80370c706a..81cdc92675b 100644 --- a/python/pyarrow/array.pxi +++ b/python/pyarrow/array.pxi @@ -572,13 +572,13 @@ def infer_type(values, mask=None, from_pandas=False): return pyarrow_wrap_data_type(out) -def arange(int64_t start, int64_t stop, int64_t step=1): +def arange(int64_t start, int64_t stop, int64_t step=1, *, memory_pool=None): """ Create an array of evenly spaced values within a given interval. + This function is similar to Python's `range` function. The resulting array will contain values starting from `start` up to but not - including `stop`, with a step size of `step`. If `step` is zero, the function - will return an empty array. + including `stop`, with a step size of `step`. Parameters ---------- @@ -588,12 +588,20 @@ def arange(int64_t start, int64_t stop, int64_t step=1): The stopping value for the sequence. The returned array will not include this value. step : int, default 1 The spacing between values. + memory_pool : MemoryPool, optional + A memory pool to use for memory allocations. + + Raises + ------ + ArrowInvalid + If `step` is zero. Returns ------- arange : Array """ - c_array = GetResultValue(Arange(start, stop, step)) + cdef CMemoryPool* pool = maybe_unbox_memory_pool(memory_pool) + c_array = GetResultValue(Arange(start, stop, step, pool)) return pyarrow_wrap_array(c_array) diff --git a/python/pyarrow/includes/libarrow_python.pxd b/python/pyarrow/includes/libarrow_python.pxd index ccf13fa75fb..bf90c13926b 100644 --- a/python/pyarrow/includes/libarrow_python.pxd +++ b/python/pyarrow/includes/libarrow_python.pxd @@ -74,7 +74,7 @@ cdef extern from "arrow/python/api.h" namespace "arrow::py" nogil: CMemoryPool* pool) CResult[shared_ptr[CArray]] Arange(int64_t start, int64_t stop, - int64_t step) + int64_t step, CMemoryPool* pool) CResult[shared_ptr[CDataType]] NumPyDtypeToArrow(object dtype) diff --git a/python/pyarrow/src/arrow/python/helpers.cc b/python/pyarrow/src/arrow/python/helpers.cc index 9b837aeed56..175c3df32ab 100644 --- a/python/pyarrow/src/arrow/python/helpers.cc +++ b/python/pyarrow/src/arrow/python/helpers.cc @@ -95,8 +95,12 @@ Result PyFloat_AsHalf(PyObject* obj) { } } -Result> Arange(int64_t start, int64_t stop, int64_t step) { +Result> Arange(int64_t start, int64_t stop, int64_t step, + MemoryPool* pool) { int64_t size; + if (step == 0) { + return Status::Invalid("Step must not be zero"); + } if (step > 0 && stop > start) { // Ceiling division for positive step size = (stop - start + step - 1) / step; @@ -107,7 +111,7 @@ Result> Arange(int64_t start, int64_t stop, int64_t step) return MakeEmptyArray(int64()); } std::shared_ptr data_buffer; - ARROW_ASSIGN_OR_RAISE(data_buffer, AllocateBuffer(size * sizeof(int64_t))); + ARROW_ASSIGN_OR_RAISE(data_buffer, AllocateBuffer(size * sizeof(int64_t), pool)); auto values = reinterpret_cast(data_buffer->mutable_data()); for (int64_t i = 0; i < size; ++i) { values[i] = start + i * step; diff --git a/python/pyarrow/src/arrow/python/helpers.h b/python/pyarrow/src/arrow/python/helpers.h index 66aead7ef30..2f797a19935 100644 --- a/python/pyarrow/src/arrow/python/helpers.h +++ b/python/pyarrow/src/arrow/python/helpers.h @@ -51,14 +51,16 @@ ARROW_PYTHON_EXPORT Result PyFloat_AsHalf(PyObject* obj); /// This function is similar to Python's `range` function. /// The resulting array will contain values starting from `start` up to but not /// including `stop`, with a step size of `step`. If `step` is zero, the function -/// will return an empty array. +/// will return an error. /// The resulting array will have a data type of `int64`. /// \param[in] start initial value of the sequence. /// \param[in] stop final value of the sequence (exclusive). /// \param[in] step step size between consecutive values. +/// \param[in] pool Memory pool for any memory allocations. /// \return Result Array ARROW_PYTHON_EXPORT -Result> Arange(int64_t start, int64_t stop, int64_t step); +Result> Arange(int64_t start, int64_t stop, int64_t step, + MemoryPool* pool); namespace internal { diff --git a/python/pyarrow/tests/test_array.py b/python/pyarrow/tests/test_array.py index 68a51b3c46d..97425df0f95 100644 --- a/python/pyarrow/tests/test_array.py +++ b/python/pyarrow/tests/test_array.py @@ -538,22 +538,28 @@ def test_array_slice_negative_step(): def test_arange(): cases = [ - (0, 10), # Default step - (0, 10, 1), - (0, 10, 2), - (10, 0, -1), - (10, 0, -2), - (0, 0), # Empty array - (0, 10, -1), # Empty array - (10, 0, 1), # Empty array + (5, 103), # Default step + (-2, 128, 3), + (4, 103, 5), + (10, -7, -1), + (100, -20, -3), + (0, 0), # Empty array + (2, 10, -1), # Empty array + (10, 3, 1), # Empty array ] for case in cases: result = pa.arange(*case) + result.validate(full=True) assert result.equals(pa.array(list(range(*case)), type=pa.int64())) - # Special case for invalid step (range does not accept step of 0) - result = pa.arange(0, 10, 0) - assert result.equals(pa.array([], type=pa.int64())) + # Validate memory_pool keyword argument + result = pa.arange(-1, 101, memory_pool=pa.default_memory_pool()) + result.validate(full=True) + assert result.equals(pa.array(list(range(-1, 101)), type=pa.int64())) + + # Special case for invalid step (arange does not accept step of 0) + with pytest.raises(pa.ArrowInvalid): + pa.arange(0, 10, 0) def test_array_diff(): From 3637fef473a2093293f9b81194b7aecfb820c730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Thu, 12 Jun 2025 17:42:16 +0200 Subject: [PATCH 4/5] Move Arange C++ function to arrow/python/util.{h,cc} --- python/CMakeLists.txt | 3 +- python/pyarrow/src/arrow/python/api.h | 1 + python/pyarrow/src/arrow/python/helpers.cc | 25 ----------- python/pyarrow/src/arrow/python/helpers.h | 15 ------- python/pyarrow/src/arrow/python/util.cc | 50 ++++++++++++++++++++++ python/pyarrow/src/arrow/python/util.h | 40 +++++++++++++++++ 6 files changed, 93 insertions(+), 41 deletions(-) create mode 100644 python/pyarrow/src/arrow/python/util.cc create mode 100644 python/pyarrow/src/arrow/python/util.h diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 048f01ab9f0..3e650aaf383 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -368,7 +368,8 @@ set(PYARROW_CPP_SRCS ${PYARROW_CPP_SOURCE_DIR}/python_test.cc ${PYARROW_CPP_SOURCE_DIR}/python_to_arrow.cc ${PYARROW_CPP_SOURCE_DIR}/pyarrow.cc - ${PYARROW_CPP_SOURCE_DIR}/udf.cc) + ${PYARROW_CPP_SOURCE_DIR}/udf.cc + ${PYARROW_CPP_SOURCE_DIR}/util.cc) set_source_files_properties(${PYARROW_CPP_SOURCE_DIR}/numpy_init.cc PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) diff --git a/python/pyarrow/src/arrow/python/api.h b/python/pyarrow/src/arrow/python/api.h index e66bf49dfec..2af0963a9c0 100644 --- a/python/pyarrow/src/arrow/python/api.h +++ b/python/pyarrow/src/arrow/python/api.h @@ -26,3 +26,4 @@ #include "arrow/python/numpy_convert.h" #include "arrow/python/numpy_to_arrow.h" #include "arrow/python/python_to_arrow.h" +#include "arrow/python/util.h" diff --git a/python/pyarrow/src/arrow/python/helpers.cc b/python/pyarrow/src/arrow/python/helpers.cc index 175c3df32ab..a9ba6e541b4 100644 --- a/python/pyarrow/src/arrow/python/helpers.cc +++ b/python/pyarrow/src/arrow/python/helpers.cc @@ -95,31 +95,6 @@ Result PyFloat_AsHalf(PyObject* obj) { } } -Result> Arange(int64_t start, int64_t stop, int64_t step, - MemoryPool* pool) { - int64_t size; - if (step == 0) { - return Status::Invalid("Step must not be zero"); - } - if (step > 0 && stop > start) { - // Ceiling division for positive step - size = (stop - start + step - 1) / step; - } else if (step < 0 && stop < start) { - // Ceiling division for negative step - size = (start - stop - step - 1) / (-step); - } else { - return MakeEmptyArray(int64()); - } - std::shared_ptr data_buffer; - ARROW_ASSIGN_OR_RAISE(data_buffer, AllocateBuffer(size * sizeof(int64_t), pool)); - auto values = reinterpret_cast(data_buffer->mutable_data()); - for (int64_t i = 0; i < size; ++i) { - values[i] = start + i * step; - } - auto data = ArrayData::Make(int64(), size, {nullptr, data_buffer}, 0); - return MakeArray(data); -} - namespace internal { std::string PyBytes_AsStdString(PyObject* obj) { diff --git a/python/pyarrow/src/arrow/python/helpers.h b/python/pyarrow/src/arrow/python/helpers.h index 2f797a19935..b0cf1010289 100644 --- a/python/pyarrow/src/arrow/python/helpers.h +++ b/python/pyarrow/src/arrow/python/helpers.h @@ -47,21 +47,6 @@ ARROW_PYTHON_EXPORT PyObject* PyFloat_FromHalf(uint16_t value); // \brief Convert a Python object to a half-float uint16_t value. ARROW_PYTHON_EXPORT Result PyFloat_AsHalf(PyObject* obj); -/// \brief Create an array of evenly spaced values within a given interval. -/// This function is similar to Python's `range` function. -/// The resulting array will contain values starting from `start` up to but not -/// including `stop`, with a step size of `step`. If `step` is zero, the function -/// will return an error. -/// The resulting array will have a data type of `int64`. -/// \param[in] start initial value of the sequence. -/// \param[in] stop final value of the sequence (exclusive). -/// \param[in] step step size between consecutive values. -/// \param[in] pool Memory pool for any memory allocations. -/// \return Result Array -ARROW_PYTHON_EXPORT -Result> Arange(int64_t start, int64_t stop, int64_t step, - MemoryPool* pool); - namespace internal { // \brief Check that a Python module has been already imported diff --git a/python/pyarrow/src/arrow/python/util.cc b/python/pyarrow/src/arrow/python/util.cc new file mode 100644 index 00000000000..cffe1eb956b --- /dev/null +++ b/python/pyarrow/src/arrow/python/util.cc @@ -0,0 +1,50 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "arrow/python/util.h" + +#include "arrow/array.h" +#include "arrow/python/common.h" + +namespace arrow ::py { + +Result> Arange(int64_t start, int64_t stop, int64_t step, + MemoryPool* pool) { + int64_t size; + if (step == 0) { + return Status::Invalid("Step must not be zero"); + } + if (step > 0 && stop > start) { + // Ceiling division for positive step + size = (stop - start + step - 1) / step; + } else if (step < 0 && stop < start) { + // Ceiling division for negative step + size = (start - stop - step - 1) / (-step); + } else { + return MakeEmptyArray(int64()); + } + std::shared_ptr data_buffer; + ARROW_ASSIGN_OR_RAISE(data_buffer, AllocateBuffer(size * sizeof(int64_t), pool)); + auto values = reinterpret_cast(data_buffer->mutable_data()); + for (int64_t i = 0; i < size; ++i) { + values[i] = start + i * step; + } + auto data = ArrayData::Make(int64(), size, {nullptr, data_buffer}, 0); + return MakeArray(data); +} + +} // namespace arrow::py diff --git a/python/pyarrow/src/arrow/python/util.h b/python/pyarrow/src/arrow/python/util.h new file mode 100644 index 00000000000..ff2ffcaea9c --- /dev/null +++ b/python/pyarrow/src/arrow/python/util.h @@ -0,0 +1,40 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include "arrow/python/common.h" +#include "arrow/python/visibility.h" + +namespace arrow::py { + +/// \brief Create an array of evenly spaced values within a given interval. +/// This function is similar to Python's `range` function. +/// The resulting array will contain values starting from `start` up to but not +/// including `stop`, with a step size of `step`. If `step` is zero, the function +/// will return an error. +/// The resulting array will have a data type of `int64`. +/// \param[in] start initial value of the sequence. +/// \param[in] stop final value of the sequence (exclusive). +/// \param[in] step step size between consecutive values. +/// \param[in] pool Memory pool for any memory allocations. +/// \return Result Array +ARROW_PYTHON_EXPORT +Result> Arange(int64_t start, int64_t stop, int64_t step, + MemoryPool* pool); + +} // namespace arrow::py From 69c6fdf11a3c624e430c1e078d97645111ac1153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Thu, 19 Jun 2025 10:09:48 +0200 Subject: [PATCH 5/5] Review comments. Release the gil when calling Arange and remove stray include --- python/pyarrow/array.pxi | 3 ++- python/pyarrow/src/arrow/python/helpers.cc | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/pyarrow/array.pxi b/python/pyarrow/array.pxi index 81cdc92675b..4e1f69aa3e2 100644 --- a/python/pyarrow/array.pxi +++ b/python/pyarrow/array.pxi @@ -601,7 +601,8 @@ def arange(int64_t start, int64_t stop, int64_t step=1, *, memory_pool=None): arange : Array """ cdef CMemoryPool* pool = maybe_unbox_memory_pool(memory_pool) - c_array = GetResultValue(Arange(start, stop, step, pool)) + with nogil: + c_array = GetResultValue(Arange(start, stop, step, pool)) return pyarrow_wrap_array(c_array) diff --git a/python/pyarrow/src/arrow/python/helpers.cc b/python/pyarrow/src/arrow/python/helpers.cc index a9ba6e541b4..0a24b259310 100644 --- a/python/pyarrow/src/arrow/python/helpers.cc +++ b/python/pyarrow/src/arrow/python/helpers.cc @@ -27,7 +27,6 @@ #include #include -#include "arrow/array.h" #include "arrow/python/common.h" #include "arrow/python/decimal.h" #include "arrow/type_fwd.h"