Skip to content

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

Merged
paleolimbot merged 2 commits into
apache:mainfrom
edgarrmondragon:feat/map
Oct 29, 2026
Merged

paleolimbot merged 2 commits 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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review :D. I added a quick return for the zero-length case at the top of the function.

Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
@edgarrmondragon
edgarrmondragon marked this pull request as ready for review October 29, 2026 05:47

@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!

@paleolimbot
paleolimbot merged commit 65d2067 into apache:main Oct 29, 2026
12 checks passed
@edgarrmondragon
edgarrmondragon deleted the feat/map branch October 29, 2026 17:03
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