Skip to content

Commit

Permalink
fix: add support for new RNTuple switches (#1218)
Browse files Browse the repository at this point in the history
* Fix handling of RNTuple switches

* Re-enable RNTuple stl containers test

* Disabled RNTuple multiple page lists test until we have a smaller test file.

* Added missing import

* Switched to using a structured numpy dtype
  • Loading branch information
ariostas committed May 17, 2024
1 parent 13087b0 commit e4cd29a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/uproot/models/RNTuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,13 @@ def read_col_page(self, ncol, cluster_i):
pagelist = linklist[ncol]
dtype_byte = self.column_records[ncol].type
dtype_str = uproot.const.rntuple_col_num_to_dtype_dict[dtype_byte]
dtype = numpy.dtype("bool") if dtype_str == "bit" else numpy.dtype(dtype_str)

total_len = numpy.sum([desc.num_elements for desc in pagelist], dtype=int)
if dtype_str == "switch":
dtype = numpy.dtype([("index", "int64"), ("tag", "int32")])
elif dtype_str == "bit":
dtype = numpy.dtype("bool")
else:
dtype = numpy.dtype(dtype_str)
res = numpy.empty(total_len, dtype)
split = 14 <= dtype_byte <= 21 or 26 <= dtype_byte <= 28
zigzag = 26 <= dtype_byte <= 28
Expand Down Expand Up @@ -568,8 +572,8 @@ def arrays(

# Supporting function and classes
def _split_switch_bits(content):
kindex = numpy.bitwise_and(content, numpy.int64(0x00000000000FFFFF))
tags = (content >> 44).astype("int8") - 1
tags = content["tag"].astype(numpy.dtype("int8")) - 1
kindex = content["index"]
return kindex, tags


Expand Down
3 changes: 0 additions & 3 deletions tests/test_0662_rntuple_stl_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
ak = pytest.importorskip("awkward")


@pytest.mark.skip(
reason="FIXME: skipping test_ntuple_stl_containers.root until #928 is fixed"
)
def test_rntuple_stl_containers():
filename = skhep_testdata.data_path("test_ntuple_stl_containers.root")
with uproot.open(filename) as f:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_1191_rntuple_fixes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE

import pytest
import skhep_testdata

import uproot
Expand Down Expand Up @@ -57,6 +58,9 @@ def test_empty_page_list():
assert data[0] == 0


@pytest.mark.skip(
reason="The file takes too long to download (about 5 seconds). Need to find a smaller test file."
)
def test_multiple_page_lists():
url = "http://root.cern/files/tutorials/ntpl004_dimuon_v1rc2.root"
with uproot.open(f"simplecache::{url}") as f:
Expand Down

0 comments on commit e4cd29a

Please sign in to comment.