Skip to content

fix(python): Support iterating map arrays as Python objects - #998

Draft
edgarrmondragon wants to merge 1 commit into
apache:mainfrom
edgarrmondragon:feat/map
Draft

edgarrmondragon wants to merge 1 commit into
apache:mainfrom
edgarrmondragon:feat/map

Conversation

@edgarrmondragon

@edgarrmondragon edgarrmondragon commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Adds support for iterating map arrays:

# mre_map.py

# /// script
# requires-python = ">=3.10"
# dependencies = [
#     "nanoarrow",
#     "pyarrow",
# ]
# ///
"""Iterating a map array with nanoarrow fails."""

import nanoarrow as na
import pyarrow as pa

array = pa.array(
    [[("a", 1), ("b", None)], [], None, [("c", 3)]],
    type=pa.map_(pa.string(), pa.int64()),
)

print(f"nanoarrow {na.__version__}, pyarrow {pa.__version__}")
print(na.Array(array).to_pylist())

Run it with uv run --no-project mre_map.py. The output is:

nanoarrow 0.9.0, pyarrow 26.0.0
...
KeyError: "Can't resolve iterator for type 'map'"

Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>

@paleolimbot paleolimbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Just one correctness issue I think. I appreciate the contribution!

Comment on lines +290 to +293
starts = offsets[:-1]
ends = offsets[1:]
entries = self._children[0]
entries_iter = entries._struct_tuple_iter(starts[0], ends[-1] - starts[0])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe here we have to handle the zero length case first (before indexing into the entries)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants