Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions python/pyarrow/array.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ cdef _sequence_to_array(object sequence, object mask, object size,
options.from_pandas = from_pandas
options.ignore_timezone = os.environ.get('PYARROW_IGNORE_TIMEZONE', False)

with nogil:
chunked = GetResultValue(
ConvertPySequence(sequence, mask, options, pool)
)
chunked = GetResultValue(
ConvertPySequence(sequence, mask, options, pool)
)

if chunked.get().num_chunks() == 1:
return pyarrow_wrap_array(chunked.get().chunk(0))
Expand Down Expand Up @@ -93,9 +92,8 @@ cdef _ndarray_to_array(object values, object mask, DataType type,
shared_ptr[CDataType] c_type = _ndarray_to_type(values, type)
CCastOptions cast_options = CCastOptions(safe)

with nogil:
check_status(NdarrayToArrow(pool, values, mask, from_pandas,
c_type, cast_options, &chunked_out))
check_status(NdarrayToArrow(pool, values, mask, from_pandas,
c_type, cast_options, &chunked_out))

if chunked_out.get().num_chunks() > 1:
return pyarrow_wrap_chunked_array(chunked_out)
Expand Down
79 changes: 41 additions & 38 deletions python/pyarrow/includes/libarrow_python.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ cdef extern from "arrow/python/arrow_to_pandas.h" namespace "arrow::py::MapConve
cdef extern from "arrow/python/api.h" namespace "arrow::py" nogil:
shared_ptr[CDataType] GetPrimitiveType(Type type)

object PyFloat_FromHalf(uint16_t value)

cdef cppclass PyConversionOptions:
PyConversionOptions()

Expand All @@ -77,13 +75,26 @@ cdef extern from "arrow/python/api.h" namespace "arrow::py" nogil:
c_bool ignore_timezone
c_bool strict

# TODO Some functions below are not actually "nogil"
CStatus TensorToSparseCOOTensor(shared_ptr[CTensor],
shared_ptr[CSparseCOOTensor]* out)

CResult[shared_ptr[CChunkedArray]] ConvertPySequence(
object obj, object mask, const PyConversionOptions& options,
CMemoryPool* pool)
CStatus TensorToSparseCSRMatrix(shared_ptr[CTensor],
shared_ptr[CSparseCSRMatrix]* out)

CResult[shared_ptr[CDataType]] NumPyDtypeToArrow(object dtype)
CStatus TensorToSparseCSCMatrix(shared_ptr[CTensor],
shared_ptr[CSparseCSCMatrix]* out)

CStatus TensorToSparseCSFTensor(shared_ptr[CTensor],
shared_ptr[CSparseCSFTensor]* out)

void c_set_default_memory_pool \
" arrow::py::set_default_memory_pool"(CMemoryPool* pool)\

CMemoryPool* c_get_memory_pool \
" arrow::py::get_memory_pool"()

cdef extern from "arrow/python/api.h" namespace "arrow::py":
object PyFloat_FromHalf(uint16_t value)

CStatus NdarrayToArrow(CMemoryPool* pool, object ao, object mo,
c_bool from_pandas,
Expand All @@ -96,6 +107,12 @@ cdef extern from "arrow/python/api.h" namespace "arrow::py" nogil:
const CCastOptions& cast_options,
shared_ptr[CChunkedArray]* out)

CResult[shared_ptr[CChunkedArray]] ConvertPySequence(
object obj, object mask, const PyConversionOptions& options,
CMemoryPool* pool)

CResult[shared_ptr[CDataType]] NumPyDtypeToArrow(object dtype)

CStatus NdarrayToTensor(CMemoryPool* pool, object ao,
const vector[c_string]& dim_names,
shared_ptr[CTensor]* out)
Expand Down Expand Up @@ -144,36 +161,6 @@ cdef extern from "arrow/python/api.h" namespace "arrow::py" nogil:
const vector[c_string]& dim_names,
shared_ptr[CSparseCSFTensor]* out)

CStatus TensorToSparseCOOTensor(shared_ptr[CTensor],
shared_ptr[CSparseCOOTensor]* out)

CStatus TensorToSparseCSRMatrix(shared_ptr[CTensor],
shared_ptr[CSparseCSRMatrix]* out)

CStatus TensorToSparseCSCMatrix(shared_ptr[CTensor],
shared_ptr[CSparseCSCMatrix]* out)

CStatus TensorToSparseCSFTensor(shared_ptr[CTensor],
shared_ptr[CSparseCSFTensor]* out)

CStatus ConvertArrayToPandas(const PandasOptions& options,
shared_ptr[CArray] arr,
object py_ref, PyObject** out)

CStatus ConvertChunkedArrayToPandas(const PandasOptions& options,
shared_ptr[CChunkedArray] arr,
object py_ref, PyObject** out)

CStatus ConvertTableToPandas(const PandasOptions& options,
shared_ptr[CTable] table,
PyObject** out)

void c_set_default_memory_pool \
" arrow::py::set_default_memory_pool"(CMemoryPool* pool)\

CMemoryPool* c_get_memory_pool \
" arrow::py::get_memory_pool"()

cdef cppclass PyBuffer(CBuffer):
@staticmethod
CResult[shared_ptr[CBuffer]] FromPyObject(object obj)
Expand Down Expand Up @@ -210,15 +197,31 @@ cdef extern from "arrow/python/api.h" namespace "arrow::py" nogil:
c_bool to_numpy


cdef extern from "arrow/python/api.h" namespace "arrow::py" nogil:
CStatus ConvertArrayToPandas(const PandasOptions& options,
shared_ptr[CArray] arr,
object py_ref, PyObject** out)

CStatus ConvertChunkedArrayToPandas(const PandasOptions& options,
shared_ptr[CChunkedArray] arr,
object py_ref, PyObject** out)

CStatus ConvertTableToPandas(const PandasOptions& options,
shared_ptr[CTable] table,
PyObject** out)


cdef extern from "arrow/python/api.h" namespace "arrow::py::internal" nogil:
cdef cppclass CTimePoint "arrow::py::internal::TimePoint":
pass

CTimePoint PyDateTime_to_TimePoint(PyDateTime_DateTime* pydatetime)
int64_t TimePoint_to_ns(CTimePoint val)
CTimePoint TimePoint_from_s(double val)
CTimePoint TimePoint_from_ns(int64_t val)


cdef extern from "arrow/python/api.h" namespace "arrow::py::internal":
CTimePoint PyDateTime_to_TimePoint(PyDateTime_DateTime* pydatetime)
CResult[c_string] TzinfoToString(PyObject* pytzinfo)
CResult[PyObject*] StringToTzinfo(c_string, c_bool)

Expand Down
3 changes: 1 addition & 2 deletions python/pyarrow/scalar.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -1842,8 +1842,7 @@ def scalar(value, type=None, *, from_pandas=None, MemoryPool memory_pool=None):
options.from_pandas = from_pandas

value = [value]
with nogil:
chunked = GetResultValue(ConvertPySequence(value, None, options, pool))
chunked = GetResultValue(ConvertPySequence(value, None, options, pool))

# get the first chunk
assert chunked.get().num_chunks() == 1
Expand Down