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

Function TestNumPyBufferNumpyArray

python/pyarrow/src/arrow/python/python_test.cc:330–358  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

328}
329
330Status TestNumPyBufferNumpyArray() {
331 npy_intp dims[1] = {10};
332
333 OwnedRef arr_ref(PyArray_SimpleNew(1, dims, NPY_FLOAT));
334 PyObject* arr = arr_ref.obj();
335 ASSERT_NE(arr, nullptr);
336 auto old_refcnt = Py_REFCNT(arr);
337
338 auto buf = std::make_shared<NumPyBuffer>(arr);
339 ASSERT_TRUE(buf->is_cpu());
340 ASSERT_EQ(buf->data(), PyArray_DATA(reinterpret_cast<PyArrayObject*>(arr)));
341 ASSERT_TRUE(buf->is_mutable());
342 ASSERT_EQ(buf->mutable_data(), buf->data());
343 ASSERT_EQ(old_refcnt + 1, Py_REFCNT(arr));
344 buf.reset();
345 ASSERT_EQ(old_refcnt, Py_REFCNT(arr));
346
347 // Read-only
348 PyArray_CLEARFLAGS(reinterpret_cast<PyArrayObject*>(arr), NPY_ARRAY_WRITEABLE);
349 buf = std::make_shared<NumPyBuffer>(arr);
350 ASSERT_TRUE(buf->is_cpu());
351 ASSERT_EQ(buf->data(), PyArray_DATA(reinterpret_cast<PyArrayObject*>(arr)));
352 ASSERT_FALSE(buf->is_mutable());
353 ASSERT_EQ(old_refcnt + 1, Py_REFCNT(arr));
354 buf.reset();
355 ASSERT_EQ(old_refcnt, Py_REFCNT(arr));
356
357 return Status::OK();
358}
359#endif
360
361Status TestPythonDecimalToString() {

Callers

nothing calls this directly

Calls 4

OKFunction · 0.50
dataMethod · 0.45
mutable_dataMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected