You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2017/04/07 14:16:56 UTC
arrow git commit: ARROW-781 [C++/Python] Increase reference count of
the numpy base array?
Repository: arrow
Updated Branches:
refs/heads/master 1c6609746 -> 027c6b808
ARROW-781 [C++/Python] Increase reference count of the numpy base array?
see https://issues.apache.org/jira/browse/ARROW-781
Author: Philipp Moritz <pc...@gmail.com>
Closes #503 from pcmoritz/numpy-base-object and squashes the following commits:
207e439 [Philipp Moritz] add test for numpy base object
e96c89a [Philipp Moritz] increase reference count of the numpy base array
Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/027c6b80
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/027c6b80
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/027c6b80
Branch: refs/heads/master
Commit: 027c6b8084961cf10d80927c8380cce7a23acc1f
Parents: 1c66097
Author: Philipp Moritz <pc...@gmail.com>
Authored: Fri Apr 7 10:16:47 2017 -0400
Committer: Wes McKinney <we...@twosigma.com>
Committed: Fri Apr 7 10:16:47 2017 -0400
----------------------------------------------------------------------
cpp/src/arrow/python/numpy_convert.cc | 1 +
python/pyarrow/tests/test_tensor.py | 7 +++++++
2 files changed, 8 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/arrow/blob/027c6b80/cpp/src/arrow/python/numpy_convert.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/python/numpy_convert.cc b/cpp/src/arrow/python/numpy_convert.cc
index 3697819..23470fb 100644
--- a/cpp/src/arrow/python/numpy_convert.cc
+++ b/cpp/src/arrow/python/numpy_convert.cc
@@ -258,6 +258,7 @@ Status TensorToNdarray(const Tensor& tensor, PyObject* base, PyObject** out) {
if (base != Py_None) {
PyArray_SetBaseObject(reinterpret_cast<PyArrayObject*>(result), base);
+ Py_XINCREF(base);
}
*out = result;
return Status::OK();
http://git-wip-us.apache.org/repos/asf/arrow/blob/027c6b80/python/pyarrow/tests/test_tensor.py
----------------------------------------------------------------------
diff --git a/python/pyarrow/tests/test_tensor.py b/python/pyarrow/tests/test_tensor.py
index 5327f1a..a39064b 100644
--- a/python/pyarrow/tests/test_tensor.py
+++ b/python/pyarrow/tests/test_tensor.py
@@ -16,6 +16,7 @@
# under the License.
import os
+import sys
import pytest
import numpy as np
@@ -41,6 +42,12 @@ def test_tensor_attrs():
tensor = pa.Tensor.from_numpy(data2)
assert not tensor.is_mutable
+def test_tensor_base_object():
+ tensor = pa.Tensor.from_numpy(np.random.randn(10, 4))
+ n = sys.getrefcount(tensor)
+ array = tensor.to_numpy()
+ assert sys.getrefcount(tensor) == n + 1
+
@pytest.mark.parametrize('dtype_str,arrow_type', [
('i1', pa.int8()),