From ecadd0bcb9f022a5067826ed564f513ffd0c578e Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Mon, 28 Mar 2016 09:38:13 -0700 Subject: [PATCH] ARROW-80: Handle len call for pre-init arrays Author: Uwe L. Korn Closes #45 from xhochy/arrow-80 and squashes the following commits: d9a1160 [Uwe L. Korn] Add unit test for repr on pre-init Array 6208d7d [Uwe L. Korn] ARROW-80: Handle len call for pre-init arrays --- python/pyarrow/array.pyx | 5 ++++- python/pyarrow/tests/test_array.py | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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