Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/uproot/behaviors/RNTuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,10 @@ def arrays(
"The array was not constructed correctly. Please report this issue."
)

# FIXME: This is not right, but it might temporarily work
# TODO: The conversion would be ideally be fully handled by Awkward.
# However, jagged arrays fail to be converted.
# We still need to match the TTree behavior for jagged arrays, and implement
# the conversion to Pandas.
if library.name == "np":
return arrays.to_numpy()

Expand Down
10 changes: 9 additions & 1 deletion src/uproot/models/RNTuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -1876,7 +1876,7 @@ def array(
entry_start=entry_start,
entry_stop=entry_stop,
array_cache=array_cache,
library=library,
library="ak", # conversion needs to be done at the end
interpreter=interpreter,
backend=backend,
ak_add_doc=ak_add_doc,
Expand All @@ -1893,6 +1893,14 @@ def array(
raise AssertionError(
"The array was not constructed correctly. Please report this issue."
)
library = uproot.interpretation.library._regularize_library(library)
# TODO: The conversion would be ideally be fully handled by Awkward.
# However, jagged arrays fail to be converted.
# We still need to match the TTree behavior for jagged arrays, and implement
# the conversion to Pandas.
if library.name == "np":
return arrays.to_numpy()

return arrays


Expand Down
23 changes: 23 additions & 0 deletions tests/test_1591_rntuple_read_to_numpy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE

import skhep_testdata
import awkward as ak
import uproot


def test_reading_into_numpy():
filename = skhep_testdata.data_path(
"Run2012BC_DoubleMuParked_Muons_1000evts_rntuple_v1-0-0-0.root"
)
with uproot.open(filename) as f:
obj = f["Events"]
ak_arrays = obj.arrays(filter_name="n*")
np_arrays = obj.arrays(library="np", filter_name="n*")

nmuon_ak_array = obj["nMuon"].array()
nmuon_np_array = obj["nMuon"].array(library="np")

assert ak.array_equal(nmuon_ak_array, nmuon_np_array)
assert ak.array_equal(ak_arrays["nMuon"], np_arrays["nMuon"])
assert ak.array_equal(ak_arrays["nMuon"], nmuon_ak_array)
assert ak.array_equal(np_arrays["nMuon"], nmuon_np_array)
Loading