From 5fe476eca529cc5e1437ff728d60e8b39efae198 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Wed, 7 Aug 2019 12:09:56 +0200 Subject: [PATCH] ARROW-6132: [Python] validate result in ListArray.from_arrays --- python/pyarrow/array.pxi | 8 ++++++-- python/pyarrow/tests/test_array.py | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/python/pyarrow/array.pxi b/python/pyarrow/array.pxi index b93cf10a096..cd6c190d48a 100644 --- a/python/pyarrow/array.pxi +++ b/python/pyarrow/array.pxi @@ -1050,7 +1050,9 @@ cdef class ListArray(Array): with nogil: check_status(CListArray.FromArrays(_offsets.ap[0], _values.ap[0], cpool, &out)) - return pyarrow_wrap_array(out) + cdef Array result = pyarrow_wrap_array(out) + result.validate() + return result @property def values(self): @@ -1102,7 +1104,9 @@ cdef class LargeListArray(Array): check_status(CLargeListArray.FromArrays(_offsets.ap[0], _values.ap[0], cpool, &out)) - return pyarrow_wrap_array(out) + cdef Array result = pyarrow_wrap_array(out) + result.validate() + return result def flatten(self): """ diff --git a/python/pyarrow/tests/test_array.py b/python/pyarrow/tests/test_array.py index 03db7e94655..350922fa158 100644 --- a/python/pyarrow/tests/test_array.py +++ b/python/pyarrow/tests/test_array.py @@ -520,6 +520,12 @@ def test_list_from_arrays(list_array_type, list_type_factory): type=list_type_factory(pa.binary())) assert result.equals(expected) + # raise on invalid array + offsets = [1, 3, 10] + values = np.arange(5) + with pytest.raises(ValueError): + list_array_type.from_arrays(offsets, values) + def test_union_from_dense(): binary = pa.array([b'a', b'b', b'c', b'd'], type='binary')