Skip to content

fix: reading RNTuple fields into NumPy#1591

Merged
ianna merged 4 commits intomainfrom
ariostas/fix_rntuple_numpy
Mar 12, 2026
Merged

fix: reading RNTuple fields into NumPy#1591
ianna merged 4 commits intomainfrom
ariostas/fix_rntuple_numpy

Conversation

@ariostas
Copy link
Member

@ariostas ariostas commented Mar 4, 2026

There was an issue when trying to read a particular RNTuple field into a NumPy array. The conversion is now done at the end, so that it is handled correctly.

At some point I'll have to revisit this to make sure everything is converted into NumPy correctly and to figure out what to do with Pandas.

Closes #1586

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves RNTuple NumPy output support by ensuring RField.array(library="np") performs conversion after selecting the requested field, and adds a regression test to cover NumPy reads from RNTuples.

Changes:

  • Force RField.array() to read via Awkward first, then convert to NumPy at the end when library="np".
  • Align RNTuple.arrays() NumPy conversion comment with the new RField.array() behavior.
  • Add a test that compares results between Awkward and NumPy reads for an RNTuple sample file.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
tests/test_1591_rntuple_read_to_numpy.py Adds a regression test for reading RNTuple content via library="np" and comparing with Awkward reads.
src/uproot/models/RNTuple.py Updates RField.array() to always construct arrays as Awkward first, then convert to NumPy at the end.
src/uproot/behaviors/RNTuple.py Updates/clarifies comment around NumPy conversion behavior for RNTuple arrays().
Comments suppressed due to low confidence (1)

src/uproot/models/RNTuple.py:1883

  • RField.array now always reads via self.arrays(library="ak"), which bypasses HasFields.arrays's validation that virtual=True requires library="ak". As a result, array(library="np", virtual=True) will no longer raise and will materialize data during the final NumPy conversion, which is inconsistent with the documented/established virtual-array behavior. Consider adding an explicit check in array() to raise the same ValueError when virtual=True and the requested library isn't Awkward (or otherwise ensure the returned object remains virtual).
        arrays = self.arrays(
            entry_start=entry_start,
            entry_stop=entry_stop,
            array_cache=array_cache,
            library="ak",  # conversion needs to be done at the end
            interpreter=interpreter,
            backend=backend,
            ak_add_doc=ak_add_doc,
            virtual=virtual,

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Member

@ianna ianna left a comment

Choose a reason for hiding this comment

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

@ariostas - looks great! Thanks.

@ianna ianna merged commit f19065d into main Mar 12, 2026
28 checks passed
@ianna ianna deleted the ariostas/fix_rntuple_numpy branch March 12, 2026 18:43
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.

Reading RNTuple into numpy array

3 participants