diff --git a/tests/samples/issue434.root b/tests/samples/issue434.root new file mode 100644 index 00000000..8e44f957 Binary files /dev/null and b/tests/samples/issue434.root differ diff --git a/tests/test_issues.py b/tests/test_issues.py index be91df51..e7547b9b 100644 --- a/tests/test_issues.py +++ b/tests/test_issues.py @@ -391,3 +391,16 @@ def test_issue429(self): dtype = [(fix(x._fName), "float32" if type(x).__name__ == "TLeafF" else "int32") for x in branch._fLeaves] array = branch.array(uproot.asdtype(dtype + [("padding", "S4")])) assert (array["padding"] == b"\xff\xff\xff\xff").all() + + def test_issue434(self): + f = uproot.open("tests/samples/issue434.root") + fromdtype = [("pmt", "u1"), ("tdc", "u4"), ("tot", "u1")] + tree = f[b'KM3NET_TIMESLICE_L1'][b'KM3NETDAQ::JDAQTimeslice'] + superframes = tree[b'vector'] + hits_buffer = superframes[b'vector.buffer'] + hits = hits_buffer.lazyarray( + uproot.asjagged( + uproot.astable( + uproot.asdtype(fromdtype, todtype)), skipbytes=6)) + assert 486480 == hits['tdc'][0][0] diff --git a/uproot/interp/numerical.py b/uproot/interp/numerical.py index 33707b9b..03b0d5c3 100644 --- a/uproot/interp/numerical.py +++ b/uproot/interp/numerical.py @@ -17,6 +17,9 @@ else: string_types = (str, bytes) +BYTEORDER_INDICATORS = (">", "<", "=", "|", b">", b"<", b"=", b"|") + + def _dtypeshape(obj): out = () while obj.subdtype is not None: @@ -85,7 +88,9 @@ class asdtype(_asnumeric): def __init__(self, fromdtype, todtype=None): if isinstance(fromdtype, self.awkward.numpy.dtype): self.fromdtype = fromdtype - elif isinstance(fromdtype, string_types) and len(fromdtype) > 0 and fromdtype[0] in (">", "<", "=", "|", b">", b"<", b"=", b"|"): + elif isinstance(fromdtype, string_types) and len(fromdtype) > 0 and fromdtype[0] in BYTEORDER_INDICATORS: + self.fromdtype = self.awkward.numpy.dtype(fromdtype) + elif isinstance(fromdtype, list) and any(e[1][0] in BYTEORDER_INDICATORS for e in fromdtype): self.fromdtype = self.awkward.numpy.dtype(fromdtype) else: self.fromdtype = self.awkward.numpy.dtype(fromdtype).newbyteorder(">") @@ -94,7 +99,9 @@ def __init__(self, fromdtype, todtype=None): self.todtype = self.fromdtype.newbyteorder("=") elif isinstance(todtype, self.awkward.numpy.dtype): self.todtype = todtype - elif isinstance(todtype, string_types) and len(todtype) > 0 and todtype[0] in (">", "<", "=", "|", b">", b"<", b"=", b"|"): + elif isinstance(todtype, string_types) and len(todtype) > 0 and todtype[0] in BYTEORDER_INDICATORS: + self.todtype = self.awkward.numpy.dtype(todtype) + elif isinstance(todtype, list) and any(e[1][0] in BYTEORDER_INDICATORS for e in todtype): self.todtype = self.awkward.numpy.dtype(todtype) else: self.todtype = self.awkward.numpy.dtype(todtype).newbyteorder("=")