From 6208d7dabee944aeb82d623a569770e515185966 Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Sun, 27 Mar 2016 18:59:42 +0200 Subject: [PATCH 1/2] ARROW-80: Handle len call for pre-init arrays --- python/pyarrow/array.pyx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/pyarrow/array.pyx b/python/pyarrow/array.pyx index c5d40ddd7a481..5ed5034b95c94 100644 --- a/python/pyarrow/array.pyx +++ b/python/pyarrow/array.pyx @@ -61,7 +61,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 From d9a1160b57004792ca1e88a1ab09951fa3e89738 Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Mon, 28 Mar 2016 10:18:17 +0200 Subject: [PATCH 2/2] Add unit test for repr on pre-init Array --- python/pyarrow/tests/test_array.py | 4 ++++ 1 file changed, 4 insertions(+) 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