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/06/26 20:43:43 UTC
arrow git commit: ARROW-1152: [Cython] read_tensor should work with a
readable file
Repository: arrow
Updated Branches:
refs/heads/master ec6e183ee -> bfe15dbf9
ARROW-1152: [Cython] read_tensor should work with a readable file
Author: Philipp Moritz <pc...@gmail.com>
Closes #783 from pcmoritz/fix-read-tensor and squashes the following commits:
a03b59fc [Philipp Moritz] add unit test
e6fb7104 [Philipp Moritz] fix read_tensor
Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/bfe15dbf
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/bfe15dbf
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/bfe15dbf
Branch: refs/heads/master
Commit: bfe15dbf91dce9a1dd810951db522de50e376c9f
Parents: ec6e183
Author: Philipp Moritz <pc...@gmail.com>
Authored: Mon Jun 26 16:43:38 2017 -0400
Committer: Wes McKinney <we...@twosigma.com>
Committed: Mon Jun 26 16:43:38 2017 -0400
----------------------------------------------------------------------
python/pyarrow/io.pxi | 2 +-
python/pyarrow/tests/test_tensor.py | 13 +++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/arrow/blob/bfe15dbf/python/pyarrow/io.pxi
----------------------------------------------------------------------
diff --git a/python/pyarrow/io.pxi b/python/pyarrow/io.pxi
index 23eb6ef..9f0ad7e 100644
--- a/python/pyarrow/io.pxi
+++ b/python/pyarrow/io.pxi
@@ -1254,7 +1254,7 @@ def read_tensor(NativeFile source):
cdef:
shared_ptr[CTensor] sp_tensor
- source._assert_writeable()
+ source._assert_readable()
cdef int64_t offset = source.tell()
with nogil:
http://git-wip-us.apache.org/repos/asf/arrow/blob/bfe15dbf/python/pyarrow/tests/test_tensor.py
----------------------------------------------------------------------
diff --git a/python/pyarrow/tests/test_tensor.py b/python/pyarrow/tests/test_tensor.py
index b0924e3..a83f6f2 100644
--- a/python/pyarrow/tests/test_tensor.py
+++ b/python/pyarrow/tests/test_tensor.py
@@ -114,3 +114,16 @@ def test_tensor_size():
data = np.random.randn(10, 4)
tensor = pa.Tensor.from_numpy(data)
assert pa.get_tensor_size(tensor) > (data.size * 8)
+
+def test_read_tensor(tmpdir):
+ # Create and write tensor tensor
+ data = np.random.randn(10, 4)
+ tensor = pa.Tensor.from_numpy(data)
+ data_size = pa.get_tensor_size(tensor)
+ path = os.path.join(str(tmpdir), 'pyarrow-tensor-ipc-read-tensor')
+ write_mmap = pa.create_memory_map(path, data_size)
+ pa.write_tensor(tensor, write_mmap)
+ # Try to read tensor
+ read_mmap = pa.memory_map(path, mode='r')
+ array = pa.read_tensor(read_mmap).to_numpy()
+ np.testing.assert_equal(data, array)