Skip to content

feat: preserve attrs through Arrow serialization - #4349

Draft
ikrommyd wants to merge 4 commits into
scikit-hep:mainfrom
ikrommyd:arrow-attrs
Draft

ikrommyd wants to merge 4 commits into
scikit-hep:mainfrom
ikrommyd:arrow-attrs

Conversation

@ikrommyd

Copy link
Copy Markdown
Member

Closes #3278

Parquet already writes the attrs into the table's schema metadata, so ak.to_arrow_table does the same under the same key. A bare Arrow array has nowhere to put them other than its type, so ak.to_arrow stores them in the outermost AwkwardArrowType, which means it can only do it with extensionarray=True. Either way ak.from_arrow restores them, and an explicit attrs argument takes precedence. Transient attrs are dropped, as they are when pickling.

The second commit moves the parquet side onto the same two helpers instead of repeating the metadata key and the json handling in ak_to_parquet and ak_from_parquet.

ikrommyd and others added 2 commits September 12, 2026 23:11
A Table can carry the array's attrs in its schema metadata, under the same
`AWKWARD_ATTRS` key that Parquet already uses. A bare Arrow array has nowhere
to put them other than its type, so `ak.to_arrow` stores them in the outermost
`AwkwardArrowType` (and can therefore only do so with `extensionarray=True`).

Either way, `ak.from_arrow` restores them, with an explicit `attrs` argument
taking precedence. Transient attrs (whose keys start with "@") are dropped, as
they are when pickling.

Signed-off-by: Iason Krommydas <iason.krom@gmail.com>

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions github-actions Bot added the type/feat PR title type: feat (set automatically) label Sep 12, 2026
@codecov

codecov Bot commented Sep 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.96970% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.89%. Comparing base (5342e8d) to head (d97a6f2).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/awkward/_connect/pyarrow/__init__.py 0.00% 2 Missing ⚠️

❌ Your patch check has failed because the patch coverage (96.96%) is below the target coverage (98.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
Files with missing lines Coverage Δ
src/awkward/_attrs.py 92.45% <100.00%> (-1.30%) ⬇️
src/awkward/_connect/pyarrow/extn_types.py 94.68% <100.00%> (+0.70%) ⬆️
src/awkward/_connect/pyarrow/table_conv.py 89.75% <100.00%> (+0.87%) ⬆️
src/awkward/operations/ak_from_arrow.py 100.00% <100.00%> (ø)
src/awkward/operations/ak_from_parquet.py 93.67% <100.00%> (-0.31%) ⬇️
src/awkward/operations/ak_to_arrow.py 100.00% <100.00%> (ø)
src/awkward/operations/ak_to_arrow_table.py 100.00% <100.00%> (ø)
src/awkward/operations/ak_to_parquet.py 67.34% <100.00%> (-0.87%) ⬇️
src/awkward/_connect/pyarrow/__init__.py 43.13% <0.00%> (-1.77%) ⬇️

... and 1 file with indirect coverage changes

github-actions Bot added a commit that referenced this pull request Sep 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

The documentation preview is ready to be viewed at https://awkward-array.org/doc/pr/4349/

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

type/feat PR title type: feat (set automatically)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

attrs are not preserved in serializations through Arrow or Parquet

1 participant