You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by uw...@apache.org on 2018/05/08 17:15:47 UTC
[arrow] branch master updated: ARROW-2491: [Python] raise
NotImplementedError on from_buffers with nested types
This is an automated email from the ASF dual-hosted git repository.
uwe pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new bb67939 ARROW-2491: [Python] raise NotImplementedError on from_buffers with nested types
bb67939 is described below
commit bb67939eedf97403d575937037e0471c75763546
Author: Korn, Uwe <Uw...@blue-yonder.com>
AuthorDate: Tue May 8 19:15:40 2018 +0200
ARROW-2491: [Python] raise NotImplementedError on from_buffers with nested types
Author: Korn, Uwe <Uw...@blue-yonder.com>
Closes #1927 from xhochy/ARROW-2491 and squashes the following commits:
f2300dbf <Korn, Uwe> Test for NotImplementedError
0dbcc34f <Korn, Uwe> ARROW-2491: raise NotImplementedError on from_buffers with nested types
---
python/pyarrow/array.pxi | 4 ++++
python/pyarrow/includes/libarrow.pxd | 2 ++
python/pyarrow/tests/test_array.py | 3 +++
python/pyarrow/tests/test_types.py | 5 +++++
python/pyarrow/types.pxi | 5 +++++
python/pyarrow/types.py | 7 +++++++
6 files changed, 26 insertions(+)
diff --git a/python/pyarrow/array.pxi b/python/pyarrow/array.pxi
index e9b579a..94c37b3 100644
--- a/python/pyarrow/array.pxi
+++ b/python/pyarrow/array.pxi
@@ -491,6 +491,10 @@ cdef class Array:
vector[shared_ptr[CBuffer]] c_buffers
shared_ptr[CArrayData] ad
+ if not is_primitive(type.id):
+ raise NotImplementedError("from_buffers is only supported for "
+ "primitive arrays yet.")
+
for buf in buffers:
# None will produce a null buffer pointer
c_buffers.push_back(pyarrow_unwrap_buffer(buf))
diff --git a/python/pyarrow/includes/libarrow.pxd b/python/pyarrow/includes/libarrow.pxd
index 12bbefb..215b102 100644
--- a/python/pyarrow/includes/libarrow.pxd
+++ b/python/pyarrow/includes/libarrow.pxd
@@ -90,6 +90,8 @@ cdef extern from "arrow/api.h" namespace "arrow" nogil:
c_string ToString()
+ c_bool is_primitive(Type type)
+
cdef cppclass CArrayData" arrow::ArrayData":
shared_ptr[CDataType] type
int64_t length
diff --git a/python/pyarrow/tests/test_array.py b/python/pyarrow/tests/test_array.py
index 217dfc6..6bac0cf 100644
--- a/python/pyarrow/tests/test_array.py
+++ b/python/pyarrow/tests/test_array.py
@@ -218,6 +218,9 @@ def test_array_from_buffers():
with pytest.raises(TypeError):
pa.Array.from_buffers(pa.int16(), 3, [u'', u''], offset=1)
+ with pytest.raises(NotImplementedError):
+ pa.Array.from_buffers(pa.list_(pa.int16()), 4, [None, values_buf])
+
def test_dictionary_from_numpy():
indices = np.repeat([0, 1, 2], 2)
diff --git a/python/pyarrow/tests/test_types.py b/python/pyarrow/tests/test_types.py
index 60cd5be..e51715f 100644
--- a/python/pyarrow/tests/test_types.py
+++ b/python/pyarrow/tests/test_types.py
@@ -169,6 +169,11 @@ def test_is_temporal_date_time_timestamp():
assert not types.is_temporal(pa.int32())
+def test_is_primitive():
+ assert types.is_primitive(pa.int32())
+ assert not types.is_primitive(pa.list_(pa.int32()))
+
+
def test_timestamp_type():
# See ARROW-1683
assert isinstance(pa.timestamp('ns'), pa.TimestampType)
diff --git a/python/pyarrow/types.pxi b/python/pyarrow/types.pxi
index 2922dc2..eecf1b7 100644
--- a/python/pyarrow/types.pxi
+++ b/python/pyarrow/types.pxi
@@ -75,6 +75,11 @@ cdef bytes _datatype_to_pep3118(CDataType* type):
return char
+def _is_primitive(Type type):
+ # This is simply a redirect, the official API is in pyarrow.types.
+ return is_primitive(type)
+
+
# Workaround for Cython parsing bug
# https://github.com/cython/cython/issues/2143
ctypedef CFixedWidthType* _CFixedWidthTypePtr
diff --git a/python/pyarrow/types.py b/python/pyarrow/types.py
index 2455714..6ce4386 100644
--- a/python/pyarrow/types.py
+++ b/python/pyarrow/types.py
@@ -283,3 +283,10 @@ def is_dictionary(t):
Return True if value is an instance of a dictionary-encoded type
"""
return t.id == lib.Type_DICTIONARY
+
+
+def is_primitive(t):
+ """
+ Return True if the value is an instance of a primitive type
+ """
+ return lib._is_primitive(t.id)
--
To stop receiving notification emails like this one, please contact
uwe@apache.org.