Skip to content

fix: Preserve schema metadata in RecordBatch PyCapsule export#474

Merged
kylebarron merged 1 commit intokylebarron:mainfrom
bretttully:473/fix-record-batch-pycapsule-metadata
Feb 11, 2026
Merged

fix: Preserve schema metadata in RecordBatch PyCapsule export#474
kylebarron merged 1 commit intokylebarron:mainfrom
bretttully:473/fix-record-batch-pycapsule-metadata

Conversation

@bretttully
Copy link
Contributor

Summary

  • Fix to_array_pycapsules dropping schema-level metadata by chaining .with_metadata() onto the Field::new_struct() call, matching the pattern already used in to_struct_array()
  • Add regression test that round-trips a RecordBatch with metadata through pyarrow via PyCapsule export

Closes #473

Test plan

  • New test fails on main (metadata is None after round-trip)
  • New test passes with the fix
  • All existing test_record_batch.py tests pass
  • cargo clippy -p pyo3-arrow clean

@kylebarron
Copy link
Owner

Ah the test is probably failing because the repo is half way through an update in pyo3 version. So arro3 is currently pinned to a git hash of pyo3-arrow

@bretttully
Copy link
Contributor Author

yeah, I had to comment out a bunch of stuff locally to get it to build. Wasn't sure how to approach it

@kylebarron
Copy link
Owner

The right way is to bump the pyo3 version at the root and use pyo3-arrow as a path dependency. You're welcome to try or I can get to it tomorrow

@bretttully
Copy link
Contributor Author

I couldn't get it to work. Keen to see your commit when you do!

@kylebarron
Copy link
Owner

#475

@kylebarron
Copy link
Owner

You should be able to merge in main now

…rron#473)

`to_array_pycapsules` was dropping schema-level metadata because
`Field::new_struct()` creates a field with empty metadata. Chain
`.with_metadata()` to carry it through, matching the pattern already
used in `to_struct_array()`.

Closes kylebarron#473
@bretttully bretttully force-pushed the 473/fix-record-batch-pycapsule-metadata branch from f0d7f76 to caebae3 Compare February 11, 2026 22:32
@kylebarron
Copy link
Owner

Thanks!

@kylebarron kylebarron merged commit 423d585 into kylebarron:main Feb 11, 2026
9 checks passed
@bretttully bretttully deleted the 473/fix-record-batch-pycapsule-metadata branch February 11, 2026 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PyRecordBatch::to_array_pycapsules drops schema-level metadata

2 participants

Comments