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')