Skip to content

Commit

Permalink
ARROW-80: Handle len call for pre-init arrays
Browse files Browse the repository at this point in the history
Author: Uwe L. Korn <uwelk@xhochy.com>

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
  • Loading branch information
xhochy authored and wesm committed Mar 28, 2016
1 parent 1fd0668 commit ecadd0b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion python/pyarrow/array.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions python/pyarrow/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ecadd0b

Please sign in to comment.