Skip to content

Commit 65e90b7

Browse files
authored
fix(python): Add iterator for null/na type (#467)
Closes #465
1 parent 490b980 commit 65e90b7

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

python/src/nanoarrow/iterator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import warnings
1919
from functools import cached_property
20-
from itertools import islice
20+
from itertools import islice, repeat
2121
from typing import Iterable, Tuple
2222

2323
from nanoarrow._lib import CArrayView, CArrowType
@@ -482,6 +482,9 @@ def _primitive_iter(self, offset, length):
482482
else:
483483
return iter(items)
484484

485+
def _null_iter(self, offset, length):
486+
return repeat(None, length)
487+
485488

486489
class RowTupleIterator(PyIterator):
487490
"""Iterate over rows of a struct array (stream) where each row is a
@@ -545,6 +548,7 @@ def _get_tzinfo(tz_string, strategy=None):
545548

546549

547550
_ITEMS_ITER_LOOKUP = {
551+
CArrowType.NA: "_null_iter",
548552
CArrowType.BINARY: "_binary_iter",
549553
CArrowType.LARGE_BINARY: "_binary_iter",
550554
CArrowType.STRING: "_string_iter",

python/tests/test_iterator.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,3 +513,8 @@ def test_iterator_extension():
513513

514514
with pytest.warns(UnregisteredExtensionWarning):
515515
assert list(iter_py(extension_array)) == [1, 2, 3]
516+
517+
518+
def test_iterator_null():
519+
array = na.c_array_from_buffers(na.null(), 3, [])
520+
assert list(iter_py(array)) == [None, None, None]

0 commit comments

Comments
 (0)