From a48601d44dd4e1581f3ffcae71c4f52b44759e49 Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Mon, 16 Aug 2021 12:20:38 -0500 Subject: [PATCH] Float16_t with up to 32 bits is allowed (not just 16). (#411) --- src/uproot/interpretation/identify.py | 10 +++++----- src/uproot/interpretation/numerical.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/uproot/interpretation/identify.py b/src/uproot/interpretation/identify.py index eb3340c05..eb49ffee3 100644 --- a/src/uproot/interpretation/identify.py +++ b/src/uproot/interpretation/identify.py @@ -240,7 +240,7 @@ def _float16_or_double32(branch, context, leaf, is_float16, dims): right = title.index("]") except (ValueError, AttributeError): - low, high, num_bits = 0, 0, 0 + low, high, num_bits = 0, 0, "no brackets" # distinct from "None" else: source = title[left : right + 1] @@ -280,19 +280,19 @@ def _float16_or_double32(branch, context, leaf, is_float16, dims): ) if not is_float16: - if num_bits == 0: + if num_bits == "no brackets": return uproot.interpretation.numerical.AsDtype( numpy.dtype((">f4", dims)), numpy.dtype(("f8", dims)) ) - elif num_bits is None: + elif num_bits is None or not 2 <= num_bits <= 32: return uproot.interpretation.numerical.AsDouble32(low, high, 32, dims) else: return uproot.interpretation.numerical.AsDouble32(low, high, num_bits, dims) else: - if num_bits == 0: + if num_bits == "no brackets": return uproot.interpretation.numerical.AsFloat16(low, high, 12, dims) - elif num_bits is None: + elif num_bits is None or not 2 <= num_bits <= 32: return uproot.interpretation.numerical.AsFloat16(low, high, 32, dims) else: return uproot.interpretation.numerical.AsFloat16(low, high, num_bits, dims) diff --git a/src/uproot/interpretation/numerical.py b/src/uproot/interpretation/numerical.py index c9dbbeef7..615a3bbce 100644 --- a/src/uproot/interpretation/numerical.py +++ b/src/uproot/interpretation/numerical.py @@ -624,8 +624,8 @@ def __init__(self, low, high, num_bits, to_dims=()): self._num_bits = num_bits self._to_dims = to_dims - if not uproot._util.isint(num_bits) or not 2 <= num_bits <= 16: - raise TypeError("num_bits must be an integer between 2 and 16 (inclusive)") + if not uproot._util.isint(num_bits) or not 2 <= num_bits <= 32: + raise TypeError("num_bits must be an integer between 2 and 32 (inclusive)") if high <= low and not self.is_truncated: raise ValueError( "high ({0}) must be strictly greater than low ({1})".format(high, low)