| 474 | virtual Status AddResultMetadata(PyObject* result) { return Status::OK(); } |
| 475 | |
| 476 | Status MakeBlock1D() { |
| 477 | // For Series or for certain DataFrame block types, we need to shape to a |
| 478 | // 1D array when there is only one column |
| 479 | PyAcquireGIL lock; |
| 480 | |
| 481 | ARROW_DCHECK_EQ(1, num_columns_); |
| 482 | |
| 483 | npy_intp new_dims[1] = {static_cast<npy_intp>(num_rows_)}; |
| 484 | PyArray_Dims dims; |
| 485 | dims.ptr = new_dims; |
| 486 | dims.len = 1; |
| 487 | |
| 488 | PyObject* reshaped = PyArray_Newshape( |
| 489 | reinterpret_cast<PyArrayObject*>(block_arr_.obj()), &dims, NPY_ANYORDER); |
| 490 | RETURN_IF_PYERROR(); |
| 491 | |
| 492 | // ARROW-8801: Here a PyArrayObject is created that is not being managed by |
| 493 | // any OwnedRef object. This object is then put in the resulting object |
| 494 | // with PyDict_SetItemString, which increments the reference count, so a |
| 495 | // memory leak ensues. There are several ways to fix the memory leak but a |
| 496 | // simple one is to put the reshaped 1D block array in this OwnedRefNoGIL |
| 497 | // so it will be correctly decref'd when this class is destructed. |
| 498 | block_arr_.reset(reshaped); |
| 499 | return Status::OK(); |
| 500 | } |
| 501 | |
| 502 | virtual Status GetResultBlock(PyObject** out) { |
| 503 | *out = block_arr_.obj(); |
no test coverage detected