Merged
Conversation
Contributor
There was a problem hiding this comment.
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 whenlibrary="np". - Align
RNTuple.arrays()NumPy conversion comment with the newRField.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.arraynow always reads viaself.arrays(library="ak"), which bypassesHasFields.arrays's validation thatvirtual=Truerequireslibrary="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 inarray()to raise the sameValueErrorwhenvirtual=Trueand 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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