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

Function MakeNumPyView

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

Source from the content-addressed store, hash-verified

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