MCPcopy Create free account
hub / github.com/apache/arrow / MakeNumPyView

Function MakeNumPyView

python/pyarrow/src/arrow/python/arrow_to_pandas.cc:322–352  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

320}
321
322Status MakeNumPyView(std::shared_ptr<Array> arr, PyObject* py_ref, int npy_type, int ndim,
323 npy_intp* dims, PyObject** out) {
324 PyAcquireGIL lock;
325
326 PyArray_Descr* descr = internal::GetSafeNumPyDtype(npy_type);
327 set_numpy_metadata(npy_type, arr->type().get(), descr);
328 PyObject* result = PyArray_NewFromDescr(
329 &PyArray_Type, descr, ndim, dims, /*strides=*/nullptr,
330 const_cast<void*>(GetPrimitiveValues(*arr)), /*flags=*/0, nullptr);
331 PyArrayObject* np_arr = reinterpret_cast<PyArrayObject*>(result);
332 if (np_arr == nullptr) {
333 // Error occurred, trust that error set
334 return Status::OK();
335 }
336
337 PyObject* base;
338 if (py_ref == nullptr) {
339 // Capsule will be owned by the ndarray, no incref necessary. See
340 // ARROW-1973
341 RETURN_NOT_OK(CapsulizeArray(arr, &base));
342 } else {
343 Py_INCREF(py_ref);
344 base = py_ref;
345 }
346 RETURN_NOT_OK(SetNdarrayBase(np_arr, base));
347
348 // Do not allow Arrow data to be mutated
349 PyArray_CLEARFLAGS(np_arr, NPY_ARRAY_WRITEABLE);
350 *out = result;
351 return Status::OK();
352}
353
354class PandasWriter {
355 public:

Callers 2

TransferSingleMethod · 0.85
WriteIndicesMethod · 0.85

Calls 8

GetSafeNumPyDtypeFunction · 0.85
set_numpy_metadataFunction · 0.85
GetPrimitiveValuesFunction · 0.85
CapsulizeArrayFunction · 0.85
SetNdarrayBaseFunction · 0.85
OKFunction · 0.50
getMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected