diff --git a/python/pyarrow/array.pyx b/python/pyarrow/array.pyx index 88770cdaa966e..155c965f3e8aa 100644 --- a/python/pyarrow/array.pyx +++ b/python/pyarrow/array.pyx @@ -67,7 +67,10 @@ cdef class Array: return '{0}\n{1}'.format(type_format, values) def __len__(self): - return self.sp_array.get().length() + if self.sp_array.get(): + return self.sp_array.get().length() + else: + return 0 def isnull(self): raise NotImplemented diff --git a/python/pyarrow/tests/test_array.py b/python/pyarrow/tests/test_array.py index 36aaaa4f93d5d..d608f8167df65 100644 --- a/python/pyarrow/tests/test_array.py +++ b/python/pyarrow/tests/test_array.py @@ -22,6 +22,10 @@ class TestArrayAPI(unittest.TestCase): + def test_repr_on_pre_init_array(self): + arr = pyarrow.array.Array() + assert len(repr(arr)) > 0 + def test_getitem_NA(self): arr = pyarrow.from_pylist([1, None, 2]) assert arr[1] is pyarrow.NA