You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by jo...@apache.org on 2024/05/14 15:58:47 UTC

(arrow-nanoarrow) branch main updated: fix(python): Add iterator for null/na type (#467)

This is an automated email from the ASF dual-hosted git repository.

jorisvandenbossche pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-nanoarrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 65e90b7f fix(python): Add iterator for null/na type (#467)
65e90b7f is described below

commit 65e90b7f340ca40901a30fee577453c08abdba77
Author: Dewey Dunnington <de...@dunnington.ca>
AuthorDate: Tue May 14 12:58:41 2024 -0300

    fix(python): Add iterator for null/na type (#467)
    
    Closes #465
---
 python/src/nanoarrow/iterator.py | 6 +++++-
 python/tests/test_iterator.py    | 5 +++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/python/src/nanoarrow/iterator.py b/python/src/nanoarrow/iterator.py
index 2364ea82..3ff1714f 100644
--- a/python/src/nanoarrow/iterator.py
+++ b/python/src/nanoarrow/iterator.py
@@ -17,7 +17,7 @@
 
 import warnings
 from functools import cached_property
-from itertools import islice
+from itertools import islice, repeat
 from typing import Iterable, Tuple
 
 from nanoarrow._lib import CArrayView, CArrowType
@@ -482,6 +482,9 @@ class PyIterator(ArrayViewBaseIterator):
         else:
             return iter(items)
 
+    def _null_iter(self, offset, length):
+        return repeat(None, length)
+
 
 class RowTupleIterator(PyIterator):
     """Iterate over rows of a struct array (stream) where each row is a
@@ -545,6 +548,7 @@ def _get_tzinfo(tz_string, strategy=None):
 
 
 _ITEMS_ITER_LOOKUP = {
+    CArrowType.NA: "_null_iter",
     CArrowType.BINARY: "_binary_iter",
     CArrowType.LARGE_BINARY: "_binary_iter",
     CArrowType.STRING: "_string_iter",
diff --git a/python/tests/test_iterator.py b/python/tests/test_iterator.py
index ff0b34e2..fe6e8bbd 100644
--- a/python/tests/test_iterator.py
+++ b/python/tests/test_iterator.py
@@ -513,3 +513,8 @@ def test_iterator_extension():
 
     with pytest.warns(UnregisteredExtensionWarning):
         assert list(iter_py(extension_array)) == [1, 2, 3]
+
+
+def test_iterator_null():
+    array = na.c_array_from_buffers(na.null(), 3, [])
+    assert list(iter_py(array)) == [None, None, None]