From 77b5af97f790a32f269da440f1f202682a8cdcfd Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 6 Nov 2026 11:19:30 -0500 Subject: [PATCH 1/6] test: enforce 100% line and branch coverage on Codecov With the tests of the previous PRs, every reachable line and branch is covered. Codecov now requires 100% of the project and of each patch, with branch coverage. Code that can't be reached is marked with "# pragma: no cover (reason)" or "# pragma: no branch (reason)", ends impossible elif chains with "raise AssertionError" (excluded from coverage), or is removed when it was dead, including the dead code that dev/make-models.py generated after unconditional raises. Assisted-by: Claude Code:claude-opus-5-5 --- AGENTS.md | 1 + README.md | 1 + codecov.yml | 11 +++--- dev/make-models.py | 32 +++++++++------- pyproject.toml | 9 +++++ src/uproot/_dask.py | 18 ++++----- src/uproot/_util.py | 2 + src/uproot/behaviors/RNTuple.py | 15 +++----- src/uproot/behaviors/TBranch.py | 7 +--- src/uproot/behaviors/TGraphAsymmErrors.py | 2 + src/uproot/containers.py | 14 ++++--- src/uproot/interpretation/identify.py | 4 +- src/uproot/interpretation/library.py | 45 +++++++++-------------- src/uproot/models/RNTuple.py | 12 ------ src/uproot/models/TArray.py | 2 +- src/uproot/models/TGraph.py | 42 --------------------- src/uproot/models/TH.py | 11 ------ src/uproot/models/THashList.py | 2 +- src/uproot/models/TObject.py | 2 +- src/uproot/models/TString.py | 2 +- src/uproot/reading.py | 10 ++--- src/uproot/writing/_cascadentuple.py | 10 +++-- src/uproot/writing/_cascadetree.py | 28 +++----------- src/uproot/writing/identify.py | 24 ++++++------ src/uproot/writing/interpret.py | 4 -- src/uproot/writing/writable.py | 19 ++++------ 26 files changed, 120 insertions(+), 209 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 07328425a..aa404d31d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -21,6 +21,7 @@ prek -a --quiet # lint/format (pre-commit: black, ruff, etc - Test files are named `test__.py`. New tests for a fix or feature go in a new file numbered after the issue/PR. - Tests pull sample ROOT files via `skhep_testdata`; many tests need network access. Markers: `slow`, `network`, `distributed`, `xrootd`. - Pytest treats warnings as errors (`filterwarnings = error`). +- Codecov enforces 100% line and branch coverage, measured on the CPU job plus the GPU job (`tests-cuda/`). Tests must not depend on the network or on timing to reach a line. Mark code that can't be reached with `# pragma: no cover (reason)` or `# pragma: no branch (reason)`; `raise AssertionError` is excluded in `pyproject.toml`. - Ruff lints `src/` but not `tests/`; isort requires `from __future__ import annotations` in every module. Every source file starts with the license header line `# BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/main/LICENSE`. - Version is derived from git tags via hatch-vcs (`src/uproot/version.py` is generated; don't edit). diff --git a/README.md b/README.md index 287a406fc..a3e711d6f 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ [![Scikit-HEP](https://scikit-hep.org/assets/images/Scikit--HEP-Project-blue.svg)](https://scikit-hep.org/) [![DOI 10.5281/zenodo.4340632](https://zenodo.org/badge/DOI/10.5281/zenodo.4340632.svg)](https://doi.org/10.5281/zenodo.4340632) [![Documentation](https://img.shields.io/badge/docs-online-success)](https://uproot.readthedocs.io/) +[![Coverage](https://codecov.io/gh/scikit-hep/uproot/graph/badge.svg?branch=main)](https://codecov.io/gh/scikit-hep/uproot) [![NSF-1836650](https://img.shields.io/badge/NSF-1836650-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1836650) [![NSF-2121686](https://img.shields.io/badge/NSF-2121686-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=2121686) diff --git a/codecov.yml b/codecov.yml index db09baa5b..074c56df6 100644 --- a/codecov.yml +++ b/codecov.yml @@ -11,16 +11,15 @@ comment: coverage: status: + # Every reachable line and branch must be tested. Mark what can't be reached + # with "# pragma: no cover (reason)" or "# pragma: no branch (reason)". project: default: - # 'auto' sets the target to our current coverage % - # 'threshold' allows a tiny 0.5% drop to prevent "flaky" failures - target: auto - threshold: 0.5% + target: 100% + threshold: 0% patch: default: - # Ensures 98% of NEW code added in the PR is covered - target: 98% + target: 100% threshold: 0% github_checks: diff --git a/dev/make-models.py b/dev/make-models.py index 5f1a699ec..fecff56d1 100644 --- a/dev/make-models.py +++ b/dev/make-models.py @@ -52,6 +52,22 @@ ] +def without_dead_code(class_code): + """ + Removes what follows the first unconditional raise in strided_interpretation. + """ + lines = [] + dead = False + for line in class_code.split("\n"): + if not dead: + lines.append(line) + dead = line.startswith(" raise CannotBeStrided(") + elif not line.startswith(" "): + lines.append(line) + dead = False + return "\n".join(lines) + + # with uproot.open("example-objects.root") as f: # f.file.streamers # pairs = [] @@ -69,19 +85,14 @@ for classname, class_version in superclasses: cls = f.file.class_named(classname, class_version) - print(cls.class_code) + print(without_dead_code(cls.class_code)) print(f""" writable = True def _serialize(self, out, header, name): - where = len(out) for x in self._bases: x._serialize(out, True, name) raise NotImplementedError("FIXME") - if header: - num_bytes = sum(len(x) for x in out[where:]) - version = {class_version} - out.insert(where, uproot.serialization.numbytes_version(num_bytes, version)) class {uproot.model.classname_encode(classname)}(uproot.model.DispatchByVersion): \"\"\" @@ -93,7 +104,7 @@ class {uproot.model.classname_encode(classname)}(uproot.model.DispatchByVersion) for key in keys: obj = f[key] - print(type(obj).class_code) + print(without_dead_code(type(obj).class_code)) print(""" class_rawstreamers = (""") for streamer_name, streamer_version in f.file.streamer_dependencies( @@ -112,18 +123,13 @@ class {uproot.model.classname_encode(classname)}(uproot.model.DispatchByVersion) {streamer_name!r}, {streamer_version}, ),""") - print(f""" ) + print(""" ) writable = True def _serialize(self, out, header, name): - where = len(out) for x in self._bases: x._serialize(out, True, name) raise NotImplementedError("FIXME") - if header: - num_bytes = sum(len(x) for x in out[where:]) - version = {obj.class_version} - out.insert(where, uproot.serialization.numbytes_version(num_bytes, version)) """) print(f""" diff --git a/pyproject.toml b/pyproject.toml index d982a9d8b..d7d506419 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -122,6 +122,15 @@ xrootd = ["fsspec-xrootd>=0.5.0"] Download = "https://github.com/scikit-hep/uproot/releases" Homepage = "https://github.com/scikit-hep/uproot" +[tool.coverage.report] +exclude_also = [ + "if TYPE_CHECKING:", + "raise AssertionError" +] + +[tool.coverage.run] +branch = true + [tool.hatch.build.hooks.vcs] version-file = "src/uproot/version.py" diff --git a/src/uproot/_dask.py b/src/uproot/_dask.py index 6f9425d19..f3d68ef66 100644 --- a/src/uproot/_dask.py +++ b/src/uproot/_dask.py @@ -363,7 +363,9 @@ def dask( interpretation_executor, ) else: - raise NotImplementedError() + raise AssertionError( + f"_regularize_library only gives np, ak and pd, and pd raised above, not {library}" + ) class _PackedArgCallable: @@ -515,7 +517,7 @@ def _dask_array_from_map( blockwise_kwargs["task"] = dask._task_spec.Task( name, io_func, dask._task_spec.TaskRef(dask.blockwise.blockwise_token(0)) ) - else: + else: # pragma: no cover (dask without _task_spec, whose Blockwise takes dsk instead of task) blockwise_kwargs["dsk"] = {name: (io_func, dask.blockwise.blockwise_token(0))} dsk = dask.blockwise.Blockwise(**blockwise_kwargs) @@ -818,10 +820,8 @@ def _get_dask_array( if explicit_chunks is None: for start in range(entry_start, entry_stop, entry_step): stop = min(start + entry_step, entry_stop) - length = stop - start - if length > 0: - chunks.append(length) - chunk_args.append((i, start, stop)) + chunks.append(stop - start) + chunk_args.append((i, start, stop)) else: for start, stop in explicit_chunks[i]: if (not 0 <= start <= entry_stop) or (not 0 <= stop <= entry_stop): @@ -1983,10 +1983,8 @@ def _get_dak_array( if explicit_chunks is None: for start in range(entry_start, entry_stop, entry_step): stop = min(start + entry_step, entry_stop) - length = stop - start - if length > 0: - divisions.append(divisions[-1] + length) - partition_args.append((i, start, stop)) + divisions.append(divisions[-1] + stop - start) + partition_args.append((i, start, stop)) else: for start, stop in explicit_chunks[i]: if (not 0 <= start <= entry_stop) or (not 0 <= stop <= entry_stop): diff --git a/src/uproot/_util.py b/src/uproot/_util.py index fa06577fd..7fdd08c85 100644 --- a/src/uproot/_util.py +++ b/src/uproot/_util.py @@ -734,6 +734,8 @@ def awkward_form(model, file, context): return model.awkward_form(file, context) +# Uproot itself no longer calls this (AwkwardForth reads these branches with their +# own dtypes), but coffea's UprootSourceMapping does, with _fix_awkward_form_of_iter def recursively_fix_awkward_form_of_iter(awkward, interpretation, form): """ Given an interpretation of a TBranch, fixup any form corresponding to diff --git a/src/uproot/behaviors/RNTuple.py b/src/uproot/behaviors/RNTuple.py index 747824cd7..54849b32d 100644 --- a/src/uproot/behaviors/RNTuple.py +++ b/src/uproot/behaviors/RNTuple.py @@ -521,14 +521,10 @@ def arrays( ) pandas_dict = {} for f, arr in numpy_data.items(): - try: - if getattr(arr, "ndim", 1) > 1: - pandas_dict[f] = list(arr) - else: - pandas_dict[f] = arr - except Exception: - msg = f"Field {f} cannot be converted to NumPy/Pandas" - raise ValueError(msg) from None + if getattr(arr, "ndim", 1) > 1: + pandas_dict[f] = list(arr) + else: + pandas_dict[f] = arr try: pandas_data = pd.DataFrame(pandas_dict, index=pandas_index) except Exception: @@ -1564,8 +1560,7 @@ def _cupy_insert(arr, obj, value): src_i += n out[dst_i] = value dst_i += 1 - if src_i < arr.size: - out[dst_i:] = arr[src_i:] + out[dst_i:] = arr[src_i:] return out diff --git a/src/uproot/behaviors/TBranch.py b/src/uproot/behaviors/TBranch.py index c78433143..cecb6823a 100644 --- a/src/uproot/behaviors/TBranch.py +++ b/src/uproot/behaviors/TBranch.py @@ -1576,8 +1576,6 @@ def iterate( previous_baskets = {} for sub_entry_start in range(entry_start, entry_stop, entry_step): sub_entry_stop = min(sub_entry_start + entry_step, entry_stop) - if sub_entry_stop - sub_entry_start == 0: - continue ranges_or_baskets = [] checked = set() @@ -2517,10 +2515,7 @@ def typename(self): :doc:`uproot.interpretation.identify.UnknownInterpretation`, the typename is ``"unknown"``. """ - if self.interpretation is None: - return "unknown" - else: - return self.interpretation.typename + return self.interpretation.typename @property def num_entries(self): diff --git a/src/uproot/behaviors/TGraphAsymmErrors.py b/src/uproot/behaviors/TGraphAsymmErrors.py index c5a16ce14..0fc29804b 100644 --- a/src/uproot/behaviors/TGraphAsymmErrors.py +++ b/src/uproot/behaviors/TGraphAsymmErrors.py @@ -34,6 +34,8 @@ def _reduce_errors(self, which, lowkey, highkey): ) / 2.0 elif which == "diff": return self._normalize_array(highkey) - self._normalize_array(lowkey) + else: + raise AssertionError(f"errors has validated which, but it is {which!r}") def values(self, axis="both"): """ diff --git a/src/uproot/containers.py b/src/uproot/containers.py index cbc04fe19..54a7345af 100644 --- a/src/uproot/containers.py +++ b/src/uproot/containers.py @@ -516,7 +516,7 @@ def read(self, chunk, cursor, context, file, selffile, parent, header=True): ) = uproot.deserialization.numbytes_version(chunk, cursor, context) if forth_obj is not None: cursor_jump = cursor._index - start_cursor._index - if cursor_jump != 0: + if cursor_jump != 0: # pragma: no branch (cursor always moves) forth_stash.pre_code.append(f"{cursor_jump} stream skip\n") if self._length_bytes == "1-5": @@ -819,7 +819,7 @@ def read(self, chunk, cursor, context, file, selffile, parent, header=True): if forth_obj is not None: forth_obj.pop_active_node() - if self._header and header: + if self._header and header: # pragma: no branch (same as outer if) uproot.deserialization.numbytes_check( chunk, start_cursor, @@ -1393,7 +1393,7 @@ def read(self, chunk, cursor, context, file, selffile, parent, header=True): is_memberwise = False if is_memberwise: - if self._header and header: + if self._header and header: # pragma: no branch (memberwise has header) cursor.skip(6) if forth_obj is not None: forth_stash.pre_code.append( @@ -1471,7 +1471,7 @@ def read(self, chunk, cursor, context, file, selffile, parent, header=True): out = STLMap(keys, values) - if self._header and header: + if self._header and header: # pragma: no branch (memberwise has header) uproot.deserialization.numbytes_check( chunk, start_cursor, @@ -1852,7 +1852,7 @@ def __eq__(self, other): return False keys_same = self._keys == other._keys - if isinstance(keys_same, bool): + if isinstance(keys_same, bool): # pragma: no cover (NumPy < 1.25 only) return keys_same else: return numpy.all(keys_same) @@ -2008,7 +2008,9 @@ def __eq__(self, other): keys_same = self._keys == other._keys values_same = self._values == other._values - if isinstance(keys_same, bool) and isinstance(values_same, bool): + if isinstance(keys_same, bool) and isinstance( + values_same, bool + ): # pragma: no cover (NumPy < 1.25 only) return keys_same and values_same else: return numpy.logical_and(keys_same, values_same).all() diff --git a/src/uproot/interpretation/identify.py b/src/uproot/interpretation/identify.py index 54574ca07..b7627d5fc 100644 --- a/src/uproot/interpretation/identify.py +++ b/src/uproot/interpretation/identify.py @@ -432,7 +432,7 @@ def interpretation_of(branch, context, simplify=True): try: if len(branch.member("fLeaves")) == 0: - raise NotNumerical() + raise AssertionError("_from_leaves has rejected a TBranch without TLeaves") elif len(branch.member("fLeaves")) == 1: leaf = branch.member("fLeaves")[0] @@ -510,7 +510,7 @@ def interpretation_of(branch, context, simplify=True): if leaf.classname == "TLeafC": return uproot.interpretation.strings.AsStrings() - elif len(branch.member("fLeaves")) > 1: + else: raise UnknownInterpretation( "more than one TLeaf ({}) in a non-numerical TBranch".format( len(branch.member("fLeaves")) diff --git a/src/uproot/interpretation/library.py b/src/uproot/interpretation/library.py index 806f8ebff..035e0498f 100644 --- a/src/uproot/interpretation/library.py +++ b/src/uproot/interpretation/library.py @@ -266,6 +266,8 @@ def concatenate(self, all_arrays): return [concatenated[k] for k in keys] elif isinstance(all_arrays[0], dict): return concatenated + else: + raise AssertionError(f"checked above, but it is {type(all_arrays[0])}") def _strided_to_awkward(awkward, path, interpretation, data): @@ -668,14 +670,9 @@ def group(self, arrays, expression_context, how): out = None if len(nonjagged) != 0: - if len(nonjagged) == 0: - out = awkward.Array( - awkward.contents.RecordArray([], fields=[], length=0) - ) - else: - out = awkward.Array( - {name: renamed_arrays[name] for name in nonjagged}, - ) + out = awkward.Array( + {name: renamed_arrays[name] for name in nonjagged}, + ) for number, jagged in enumerate(jaggeds): cut = len(jagged[0]) for name in jagged: @@ -695,27 +692,17 @@ def group(self, arrays, expression_context, how): cut = 0 if cut == 0: common = f"jagged{number}" - if len(jagged) == 0: - subarray = awkward.Array( - awkward.contents.RecordArray([], fields=[], length=0) - ) - else: - subarray = awkward.zip( - {name: renamed_arrays[name] for name in jagged} - ) + subarray = awkward.zip( + {name: renamed_arrays[name] for name in jagged} + ) else: common = jagged[0][:cut].strip("_./") - if len(jagged) == 0: - subarray = awkward.Array( - awkward.contents.RecordArray([], fields=[], length=0) - ) - else: - subarray = awkward.zip( - { - name[cut:].strip("_./"): renamed_arrays[name] - for name in jagged - } - ) + subarray = awkward.zip( + { + name[cut:].strip("_./"): renamed_arrays[name] + for name in jagged + } + ) if out is None: out = awkward.Array({common: subarray}) else: @@ -755,6 +742,8 @@ def concatenate(self, all_arrays): return [concatenated[k] for k in keys] elif isinstance(all_arrays[0], dict): return concatenated + else: + raise AssertionError(f"checked above, but it is {type(all_arrays[0])}") def _is_pandas_rangeindex(pandas, index): @@ -974,6 +963,8 @@ def concatenate(self, all_arrays): return [concatenated[k] for k in keys] elif isinstance(all_arrays[0], dict): return concatenated + else: + raise AssertionError(f"checked above, but it is {type(all_arrays[0])}") _libraries = { diff --git a/src/uproot/models/RNTuple.py b/src/uproot/models/RNTuple.py index fafe3e84c..a0f888bc5 100644 --- a/src/uproot/models/RNTuple.py +++ b/src/uproot/models/RNTuple.py @@ -2198,18 +2198,6 @@ def array( return arrays -# No cupy version of numpy.insert() provided -def _cupy_insert0(arr): - cupy = uproot.extras.cupy() - # Intended for flat cupy arrays - array_len = arr.shape[0] - array_dtype = arr.dtype - out_arr = cupy.empty(array_len + 1, dtype=array_dtype) - cupy.copyto(out_arr[1:], arr) - out_arr[0] = 0 - return out_arr - - CupyArray = Any diff --git a/src/uproot/models/TArray.py b/src/uproot/models/TArray.py index d6db2bbf2..858649fe5 100644 --- a/src/uproot/models/TArray.py +++ b/src/uproot/models/TArray.py @@ -30,7 +30,7 @@ def read_numbytes_version(self, chunk, cursor, context): def read_members(self, chunk, cursor, context, file): if uproot._awkwardforth.get_forth_obj(context) is not None: raise uproot.interpretation.objects.CannotBeForth() - if self.is_memberwise: + if self.is_memberwise: # pragma: no cover (always False: no header read) raise NotImplementedError( f"""memberwise serialization of {type(self).__name__} in file {self.file.file_path}""" diff --git a/src/uproot/models/TGraph.py b/src/uproot/models/TGraph.py index 6f81c8aaf..ec7617554 100644 --- a/src/uproot/models/TGraph.py +++ b/src/uproot/models/TGraph.py @@ -226,20 +226,6 @@ def strided_interpretation( raise uproot.interpretation.objects.CannotBeStrided( "class members defined by Model_TStreamerBasicPointer of type double* in member fX of class TGraph" ) - raise uproot.interpretation.objects.CannotBeStrided( - "class members defined by Model_TStreamerBasicPointer of type double* in member fY of class TGraph" - ) - raise uproot.interpretation.objects.CannotBeStrided( - "class members defined by Model_TStreamerObjectPointer of type TList* in member fFunctions of class TGraph" - ) - raise uproot.interpretation.objects.CannotBeStrided( - "class members defined by Model_TStreamerObjectPointer of type TH1F* in member fHistogram of class TGraph" - ) - members.append(("fMinimum", numpy.dtype(">f8"))) - members.append(("fMaximum", numpy.dtype(">f8"))) - return uproot.interpretation.objects.AsStridedObjects( - cls, members, original=original - ) @classmethod def awkward_form(cls, file, context): @@ -460,12 +446,6 @@ def strided_interpretation( raise uproot.interpretation.objects.CannotBeStrided( "class members defined by Model_TStreamerBasicPointer of type double* in member fEX of class TGraphErrors" ) - raise uproot.interpretation.objects.CannotBeStrided( - "class members defined by Model_TStreamerBasicPointer of type double* in member fEY of class TGraphErrors" - ) - return uproot.interpretation.objects.AsStridedObjects( - cls, members, original=original - ) @classmethod def awkward_form(cls, file, context): @@ -535,14 +515,9 @@ def awkward_form(cls, file, context): writable = True def _serialize(self, out, header, name, tobject_flags): - where = len(out) for x in self._bases: x._serialize(out, True, name, tobject_flags) raise NotImplementedError("FIXME") - if header: - num_bytes = sum(len(x) for x in out[where:]) - version = 3 - out.insert(where, uproot.serialization.numbytes_version(num_bytes, version)) class Model_TGraphErrors(uproot.model.DispatchByVersion): @@ -668,18 +643,6 @@ def strided_interpretation( raise uproot.interpretation.objects.CannotBeStrided( "class members defined by Model_TStreamerBasicPointer of type double* in member fEXlow of class TGraphAsymmErrors" ) - raise uproot.interpretation.objects.CannotBeStrided( - "class members defined by Model_TStreamerBasicPointer of type double* in member fEXhigh of class TGraphAsymmErrors" - ) - raise uproot.interpretation.objects.CannotBeStrided( - "class members defined by Model_TStreamerBasicPointer of type double* in member fEYlow of class TGraphAsymmErrors" - ) - raise uproot.interpretation.objects.CannotBeStrided( - "class members defined by Model_TStreamerBasicPointer of type double* in member fEYhigh of class TGraphAsymmErrors" - ) - return uproot.interpretation.objects.AsStridedObjects( - cls, members, original=original - ) @classmethod def awkward_form(cls, file, context): @@ -759,14 +722,9 @@ def awkward_form(cls, file, context): writable = True def _serialize(self, out, header, name, tobject_flags): - where = len(out) for x in self._bases: x._serialize(out, True, name, tobject_flags) raise NotImplementedError("FIXME") - if header: - num_bytes = sum(len(x) for x in out[where:]) - version = 3 - out.insert(where, uproot.serialization.numbytes_version(num_bytes, version)) class Model_TGraphAsymmErrors(uproot.model.DispatchByVersion): diff --git a/src/uproot/models/TH.py b/src/uproot/models/TH.py index c99c656b2..ff6b919cb 100644 --- a/src/uproot/models/TH.py +++ b/src/uproot/models/TH.py @@ -323,12 +323,6 @@ def strided_interpretation( raise uproot.interpretation.objects.CannotBeStrided( "class members defined by Model_TStreamerObjectPointer of type THashList* in member fLabels of class TAxis" ) - raise uproot.interpretation.objects.CannotBeStrided( - "class members defined by Model_TStreamerObjectPointer of type TList* in member fModLabs of class TAxis" - ) - return uproot.interpretation.objects.AsStridedObjects( - cls, members, original=original - ) @classmethod def awkward_form(cls, file, context): @@ -805,11 +799,6 @@ def strided_interpretation( raise uproot.interpretation.objects.CannotBeStrided( "class members defined by Model_TStreamerBasicPointer of type double* in member fBuffer of class TH1" ) - members.append(("fBinStatErrOpt", numpy.dtype(">i4"))) - members.append(("fStatOverflows", numpy.dtype(">i4"))) - return uproot.interpretation.objects.AsStridedObjects( - cls, members, original=original - ) @classmethod def awkward_form(cls, file, context): diff --git a/src/uproot/models/THashList.py b/src/uproot/models/THashList.py index b41199986..13eabdc12 100644 --- a/src/uproot/models/THashList.py +++ b/src/uproot/models/THashList.py @@ -20,7 +20,7 @@ def read_numbytes_version(self, chunk, cursor, context): def read_members(self, chunk, cursor, context, file): if uproot._awkwardforth.get_forth_obj(context) is not None: raise uproot.interpretation.objects.CannotBeForth() - if self.is_memberwise: + if self.is_memberwise: # pragma: no cover (always False: no header read) raise NotImplementedError( f"""memberwise serialization of {type(self).__name__} in file {self.file.file_path}""" diff --git a/src/uproot/models/TObject.py b/src/uproot/models/TObject.py index a045ec8d4..5e5bbee45 100644 --- a/src/uproot/models/TObject.py +++ b/src/uproot/models/TObject.py @@ -29,7 +29,7 @@ def read_members(self, chunk, cursor, context, file): forth_obj = uproot._awkwardforth.get_forth_obj(context) start_index = cursor._index - if self.is_memberwise: + if self.is_memberwise: # pragma: no cover (always False: no header read) raise NotImplementedError( f"""memberwise serialization of {type(self).__name__} in file {self.file.file_path}""" diff --git a/src/uproot/models/TString.py b/src/uproot/models/TString.py index a703de3d7..9ab2627b4 100644 --- a/src/uproot/models/TString.py +++ b/src/uproot/models/TString.py @@ -21,7 +21,7 @@ def read_numbytes_version(self, chunk, cursor, context): pass def read_members(self, chunk, cursor, context, file): - if self.is_memberwise: + if self.is_memberwise: # pragma: no cover (always False: no header read) raise NotImplementedError( f"""memberwise serialization of {type(self).__name__} in file {self.file.file_path}""" diff --git a/src/uproot/reading.py b/src/uproot/reading.py index a7fc900ed..336597948 100644 --- a/src/uproot/reading.py +++ b/src/uproot/reading.py @@ -852,12 +852,10 @@ def show_streamers(self, classname=None, version="max", stream=sys.stdout): names = self.streamer_dependencies(classname, version=version) first = True for name, version in names: - streamer = self.streamers[name].get(version) - if streamer is not None: - if not first: - stream.write("\n") - streamer.show(stream=stream) - first = False + if not first: + stream.write("\n") + self.streamers[name][version].show(stream=stream) + first = False @property def streamers(self): diff --git a/src/uproot/writing/_cascadentuple.py b/src/uproot/writing/_cascadentuple.py index 087536b16..ec6252215 100644 --- a/src/uproot/writing/_cascadentuple.py +++ b/src/uproot/writing/_cascadentuple.py @@ -120,8 +120,9 @@ def _cpp_typename(akform, subcall=False): elif isinstance(akform, awkward.forms.UnmaskedForm): return _cpp_typename(akform.content, subcall=subcall) else: - msg = "This should not have happened. Please report this issue to the Uproot developers." - raise AssertionError(msg) + raise AssertionError( + f"_to_packed_form only returns the forms above, not {akform}" + ) return typename @@ -487,8 +488,9 @@ def _build_field_col_records( description=description, ) else: - msg = "This should not have happened. Please report this issue to the Uproot developers." - raise AssertionError(msg) + raise AssertionError( + f"_to_packed_form only returns the forms above, not {akform}" + ) def generate_field_col_records(self): akform = self._akform diff --git a/src/uproot/writing/_cascadetree.py b/src/uproot/writing/_cascadetree.py index acad3eb36..1c2123e0a 100644 --- a/src/uproot/writing/_cascadetree.py +++ b/src/uproot/writing/_cascadetree.py @@ -192,8 +192,6 @@ def __init__( else: parameters = branch_datashape.parameters - if parameters is None: - parameters = {} if parameters.get("__array__") == "string": self._check_not_counter(branch_name) @@ -247,13 +245,8 @@ def __init__( self._check_not_counter(branch_name) if type(content).__name__ == "RecordType": - if hasattr(content, "contents"): - contents = content.contents - else: - contents = content.fields() + contents = content.contents keys = content.fields - if callable(keys): - keys = keys() if keys is None: keys = [str(x) for x in range(len(contents))] @@ -290,13 +283,8 @@ def __init__( ) elif type(branch_datashape).__name__ == "RecordType": - if hasattr(branch_datashape, "contents"): - contents = branch_datashape.contents - else: - contents = branch_datashape.fields() + contents = branch_datashape.contents keys = branch_datashape.fields - if callable(keys): - keys = keys() if keys is None: keys = [str(x) for x in range(len(contents))] @@ -373,8 +361,6 @@ def _branch_ak_to_np(self, branch_datashape): return numpy.dtype("float64") elif type(branch_datashape).__name__ == "NumpyType": return numpy.dtype(branch_datashape.primitive) - elif type(branch_datashape).__name__ == "PrimitiveType": - return numpy.dtype(branch_datashape.dtype) elif type(branch_datashape).__name__ == "RegularType": content = self._branch_ak_to_np(branch_datashape.content) if content is None: @@ -1094,8 +1080,6 @@ def _build_out(self): special_struct = uproot.models.TLeaf._tleafs1_format1 elif letter_upper == "I": special_struct = uproot.models.TLeaf._tleafi1_format1 - elif letter_upper == "G": - special_struct = uproot.models.TLeaf._tleafl1_format0 elif letter_upper == "L": special_struct = uproot.models.TLeaf._tleafl1_format0 elif letter_upper == "F": @@ -1104,6 +1088,8 @@ def _build_out(self): special_struct = uproot.models.TLeaf._tleafd1_format1 elif letter_upper == "C": special_struct = uproot.models.TLeaf._tleafc1_format1 + else: + raise AssertionError(f"not in _dtype_to_char: {letter_upper!r}") fLenType = datum["dtype"].itemsize fIsUnsigned = letter != letter_upper @@ -1621,11 +1607,7 @@ def write_string_basket(self, sink, branch_name, compression, array, offsets): + 1 ) - itemsize = array.dtype.itemsize - for item in array.shape[1:]: - itemsize *= item - - offsets *= itemsize + offsets *= array.dtype.itemsize offsets += fKeylen raw_array = array.tobytes() diff --git a/src/uproot/writing/identify.py b/src/uproot/writing/identify.py index 1ee22d665..8166d43b9 100644 --- a/src/uproot/writing/identify.py +++ b/src/uproot/writing/identify.py @@ -199,6 +199,10 @@ def to_writable(obj): elif ndim == 3: data = numpy.zeros((s[0] + 2, s[1] + 2, s[2] + 2), dtype=d) data[1:-1, 1:-1, 1:-1] = tmp + else: + raise AssertionError( + f"ndim is 1, 2, or 3 by now, but it is {ndim}" + ) from None tmp = ( obj.variances() @@ -218,6 +222,10 @@ def to_writable(obj): elif ndim == 3: fSumw2 = numpy.zeros((s[0] + 2, s[1] + 2, s[2] + 2), dtype=">f8") fSumw2[1:-1, 1:-1, 1:-1] = tmp + else: + raise AssertionError( + f"ndim is 1, 2, or 3 by now, but it is {ndim}" + ) from None else: # continuing to use flow=True, because it is supported @@ -683,6 +691,9 @@ def to_writable(obj): ), ) + else: + raise AssertionError(f"obj has 2 to 4 arrays by now, but it has {len(obj)}") + else: raise TypeError( "unrecognized type cannot be written to a ROOT file: " + type(obj).__name__ @@ -717,15 +728,6 @@ def _fLabels_maybe_categorical(axis, boost_histogram): return None labels = [str(label) for label in axis] - if isinstance(axis, boost_histogram.axis.IntCategory): - # Check labels are valid integers (this may be redundant) - for label in labels: - try: - int(label) - except ValueError: - raise ValueError( - f"IntCategory labels must be valid integers. Found {label!r} on axis {axis!r}" - ) from None labels = to_THashList([to_TObjString(label) for label in labels]) # we need to set the TObject.fUniqueID to the index of the bin as done by TAxis::SetBinLabel @@ -1388,7 +1390,7 @@ def to_TH2x( elif isinstance(tarray_data, uproot.models.TArray.Model_TArrayD): cls = uproot.models.TH.Model_TH2D_v4 else: - raise TypeError(f"no TH2* subclasses correspond to {tarray_data.classname}") + raise AssertionError(f"to_TH1x has already rejected {tarray_data.classname}") th2x = cls.empty() th2x._bases.append(th2) @@ -1566,7 +1568,7 @@ def to_TH3x( elif isinstance(tarray_data, uproot.models.TArray.Model_TArrayD): cls = uproot.models.TH.Model_TH3D_v4 else: - raise TypeError(f"no TH3* subclasses correspond to {tarray_data.classname}") + raise AssertionError(f"to_TH1x has already rejected {tarray_data.classname}") th3x = cls.empty() th3x._bases.append(th3) diff --git a/src/uproot/writing/interpret.py b/src/uproot/writing/interpret.py index 0f8c013b7..0a2963823 100644 --- a/src/uproot/writing/interpret.py +++ b/src/uproot/writing/interpret.py @@ -89,10 +89,6 @@ def _as_TGraph( raise ValueError( "uproot.as_TGraph requires all of the following: x_errors_low, x_errors_high, y_errors_low, y_errors_high" ) - if any(sym_errors_bool): - raise ValueError( - "uproot.as_TGraph can accept symmetrical errors OR asymmetrical errors, but not both" - ) tgraph_type = "TGraphAsymmErrors" tobject = uproot.models.TObject.Model_TObject.empty() diff --git a/src/uproot/writing/writable.py b/src/uproot/writing/writable.py index 575f99060..cf152f1e3 100644 --- a/src/uproot/writing/writable.py +++ b/src/uproot/writing/writable.py @@ -1037,14 +1037,11 @@ def _get_del_search(self, where, isget): step = step[item] elif isinstance(step, WritableTree): - rest = items[i:] - if len(rest) != 0: - raise uproot.KeyInFileError( - where, - because="TTrees in writable files can't be indexed by TBranch name", - file_path=self.file_path, - ) - return step + raise uproot.KeyInFileError( + where, + because="TTrees in writable files can't be indexed by TBranch name", + file_path=self.file_path, + ) else: raise uproot.KeyInFileError( @@ -1253,6 +1250,8 @@ def _load_existing_ttree(self, key): ), "tleaf_special_struct": _struct.Struct(">" + sc + sc), } + # only a registered custom interpretation could make a leafless TBranch + # interpretable; it can't be extended (see _rewrite_blockers) if _leaves: bd["leaf_name"] = _leaves[0].member("fName") bd["leaf_title"] = _leaves[0].member("fTitle") @@ -2666,10 +2665,6 @@ def _stage_branches( # extend()/add_branches() call (the same trust extend() itself places in # it), so there's no need to re-read and re-parse the whole tree from # disk here - if self._cascading is None: - raise RuntimeError( - "_cascading is None: this should not happen; please report this bug" - ) casc = self._cascading if counter_name is not None and not callable(counter_name): From 89638ebcf1757cd60988b0ddf11c701050276461 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 12 Nov 2026 15:05:27 -0500 Subject: [PATCH 2/6] test: cover the checks of RNTuple chunks with unknown types #1812 merged after the coverage PRs were split, and two of the ways a chunk with unknown types can mismatch the schema weren't tested: a field of a different kind, and a record with different fields. Assisted-by: Claude Code:claude-opus-5-5 --- tests/test_1834_cov_rntuple_unknown_types.py | 42 ++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/test_1834_cov_rntuple_unknown_types.py diff --git a/tests/test_1834_cov_rntuple_unknown_types.py b/tests/test_1834_cov_rntuple_unknown_types.py new file mode 100644 index 000000000..91b827e0c --- /dev/null +++ b/tests/test_1834_cov_rntuple_unknown_types.py @@ -0,0 +1,42 @@ +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/main/LICENSE + +from __future__ import annotations + +import pytest + +import uproot + +ak = pytest.importorskip("awkward") + + +@pytest.mark.parametrize( + "chunk", + [ + # "b" has lists of a fixed size where the RNTuple has variable-length lists + { + "a": ak.Array([[], []]), + "b": ak.to_regular(ak.Array([[7], [8]])), + "r": ak.Array([{"x": [], "y": []}] * 2), + }, + # "r" has a field "z" in place of "y" + { + "a": ak.Array([[], []]), + "b": ak.Array([[], []]), + "r": ak.Array([{"x": [], "z": [1]}] * 2), + }, + ], +) +def test_a_chunk_with_unknown_types_must_match_elsewhere(tmp_path, chunk): + path = tmp_path / "file.root" + data = { + "a": ak.Array([[1], [2]]), + "b": ak.Array([[3], [4]]), + "r": ak.Array([{"x": [5], "y": [6]}] * 2), + } + with uproot.recreate(path) as file: + ntuple = file.mkrntuple("ntuple", data) + with pytest.raises(ValueError, match="not compatible"): + ntuple.extend(chunk) + + with uproot.open(path) as file: + assert file["ntuple"].arrays().to_list() == ak.Array(data).to_list() From 11e87f53dc9fbc12b8e0302fe4f746710938b44a Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 12 Nov 2026 15:08:34 -0500 Subject: [PATCH 3/6] test: call the whole-dataset loader of uproot.graphed directly From graphed 0.0.11, session.materialize no longer goes through it for a dataset whose only file lacks the tree, so the test didn't reach the loader's handling of missing trees anymore. Assisted-by: Claude Code:claude-opus-5-5 --- tests/test_1720_graphed_read.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_1720_graphed_read.py b/tests/test_1720_graphed_read.py index 6e9902dcf..8a099044b 100644 --- a/tests/test_1720_graphed_read.py +++ b/tests/test_1720_graphed_read.py @@ -270,6 +270,11 @@ def test_the_whole_dataset_loader_concatenates_every_file(tmp_path): [missing], known_base_form=form, allow_missing=True, name="none" ) assert len(ak.Array(none.session.materialize(none.x))) == 0 + # the whole-dataset loader itself, which graphed may or may not call for these + assert _source_of(partial)().x.tolist() == [float(i) for i in range(6)] + empty = _source_of(none)() + assert len(empty) == 0 + assert empty.fields == ak.Array(g.session.materialize(g)).fields class _CountingExecutor: From 72f492c13a73f41e9c087a6b7b41b0e52f1199cc Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 18 Nov 2026 16:35:28 -0500 Subject: [PATCH 4/6] test: update and extend the coverage tests for what merged after the split #1837 removed numpy.asarray support of a whole RNTuple through __array__, and #1847 reworded the message about awkward-pandas, so the tests that pinned the old behavior are dropped or updated. #1822 added TEfficiency, and its native model left the streamerless memberwise error of containers without a test; both are covered now. Assisted-by: Claude Code:claude-opus-5-5 --- tests/test_1829_cov_interp_objects.py | 23 +++ tests/test_1830_cov_io_exceptions_extras.py | 3 +- tests/test_1831_cov_models_guards.py | 1 + tests/test_1832_cov_rntuple_api.py | 10 - tests/test_1834_cov_tefficiency.py | 192 ++++++++++++++++++++ 5 files changed, 218 insertions(+), 11 deletions(-) create mode 100644 tests/test_1834_cov_tefficiency.py diff --git a/tests/test_1829_cov_interp_objects.py b/tests/test_1829_cov_interp_objects.py index 1eb372b2b..b26e5a1eb 100644 --- a/tests/test_1829_cov_interp_objects.py +++ b/tests/test_1829_cov_interp_objects.py @@ -211,6 +211,29 @@ def test_memberwise_vector_of_nothing_with_streamers(): assert len(out) == 0 +def test_memberwise_vector_of_pairs_without_streamers(): + # a pair class that wasn't generated from a streamer (no DispatchByVersion) + cls = type( + uproot.model.classname_encode("pair"), (uproot.model.Model,), {} + ) + with uproot.open(skhep_testdata.data_path("uproot-issue38c.root")) as file: + data = numpy.frombuffer(memberwise(size(1)), dtype=numpy.uint8) + chunk = uproot.source.chunk.Chunk.wrap(file.file.source, data) + with pytest.raises(NotImplementedError) as excinfo: + AsVector(True, cls).read( + chunk, + uproot.source.cursor.Cursor(0), + {"breadcrumbs": ()}, + file.file, + file.file.detached, + None, + ) + assert str(excinfo.value) == ( + "streamerless memberwise serialization of class " + f"AsVector(pair)\n in file {file.file_path}" + ) + + def uint8_entries(n, start=0): return [bytes([start + i]) * 4 for i in range(n)] diff --git a/tests/test_1830_cov_io_exceptions_extras.py b/tests/test_1830_cov_io_exceptions_extras.py index 213dccbcc..552e89b8a 100644 --- a/tests/test_1830_cov_io_exceptions_extras.py +++ b/tests/test_1830_cov_io_exceptions_extras.py @@ -93,7 +93,8 @@ def test_message_narrows_huge_list_of_keys_by_prefix(): ( uproot.extras.awkward_pandas, ["awkward_pandas"], - "install the 'awkward-pandas' package", + # the message breaks the line before the package name + r"requires the\s+'awkward-pandas' package", ), (uproot.extras.cupy, ["cupy"], "Cupy is required for GDS reading"), (uproot.extras.kvikio, ["kvikio"], "Kvikio is required for GDS reading"), diff --git a/tests/test_1831_cov_models_guards.py b/tests/test_1831_cov_models_guards.py index 9c9206421..e18bd46be 100644 --- a/tests/test_1831_cov_models_guards.py +++ b/tests/test_1831_cov_models_guards.py @@ -61,6 +61,7 @@ ("TRef", "Model_TRefArray"), ("TTree", "Model_ROOT_3a3a_TIOFeatures"), ("TTree", "Model_TTree_NumEntries"), + ("TEfficiency", "Model_TEfficiency_v2"), ] # These generate AwkwardForth instead of raising, or (TTime) are tested on real data. diff --git a/tests/test_1832_cov_rntuple_api.py b/tests/test_1832_cov_rntuple_api.py index fc3547776..4f92be7ae 100644 --- a/tests/test_1832_cov_rntuple_api.py +++ b/tests/test_1832_cov_rntuple_api.py @@ -230,16 +230,6 @@ def test_array_protocol_of_a_field(ntuple): assert converted.tolist() == [10.0, 20.0, 30.0] -def test_array_protocol_of_an_rntuple(ntuple): - # An RNTuple is a table of fields, not one array - assert ntuple.__array__()["x"].tolist() == [10, 20, 30] - with pytest.raises(ValueError, match="__array__"): - np.asarray(ntuple) - wrapped = ntuple.__array__(dtype=object) - assert wrapped.shape == () - assert wrapped.item()["x"].tolist() == [10, 20, 30] - - def test_iterate_report(three_files): out = list( iterate( diff --git a/tests/test_1834_cov_tefficiency.py b/tests/test_1834_cov_tefficiency.py new file mode 100644 index 000000000..7b7506175 --- /dev/null +++ b/tests/test_1834_cov_tefficiency.py @@ -0,0 +1,192 @@ +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/main/LICENSE + +""" +Coverage of the TEfficiency support of #1822, which was merged after the coverage +tests of #1814 were split into PRs. +""" + +from __future__ import annotations + +import struct + +import numpy as np +import pytest +import skhep_testdata + +import uproot +import uproot.behaviors.TEfficiency +import uproot.models.TEfficiency + +TOTAL = np.array([0, 1, 5, 10, 20, 50], np.float64) +PASSED = np.array([0, 1, 0, 3, 20, 26], np.float64) +EDGES = np.arange(7, dtype=np.float64) + +kByteCount = 0x40000000 +kMemberwise = 0x4000 + + +def efficiency(**kwargs): + return uproot.writing.to_TEfficiency( + "eff", "", (PASSED, EDGES), (TOTAL, EDGES), **kwargs + ) + + +# ---- intervals ----------------------------------------------------------------------- +def test_mid_p_interpolates_a_fractional_passed_count(): + pytest.importorskip("scipy") + mid_p = uproot.behaviors.TEfficiency.mid_p + for upper in (False, True): + # as TEfficiency::MidPInterval, between 0 and 1 passed events + p0, p1, p = mid_p(10, [0.0, 1.0, 0.25], 0.9, upper) + assert p == pytest.approx((p1 - p0) * 0.25 + p0) + assert p0 < p < p1 + + +def test_beta_shortest_interval_without_a_distribution(): + pytest.importorskip("scipy") + # as TEfficiency::BetaShortestInterval, a non-positive parameter has no + # distribution, and the interval is everything + lower, upper = uproot.behaviors.TEfficiency.beta_shortest_interval( + 0.68, [0.0, 2.0, -1.0], [3.0, 0.0, 1.0] + ) + assert lower.tolist() == [0.0, 0.0, 0.0] + assert upper.tolist() == [1.0, 1.0, 1.0] + + +# ---- the behavior -------------------------------------------------------------------- +def test_axes_of_the_total_histogram(): + eff = efficiency() + assert eff.ndim == 1 + assert len(eff.axes) == 1 + assert eff.axes[0].edges().tolist() == EDGES.tolist() + assert eff.axis().edges().tolist() == EDGES.tolist() + assert eff.axis(0) is not None + + +def test_an_unknown_statistic_option_is_clopper_pearson(): + # TEfficiency::GetEfficiencyErrorLow falls back to Clopper-Pearson + eff = efficiency() + eff._members["fStatisticOption"] = 99 + assert eff.statistic_option == "kFCP" + eff._members["fStatisticOption"] = -1 + assert eff.statistic_option == "kFCP" + + +# ---- to_TEfficiency ------------------------------------------------------------------ +def test_arguments_that_are_not_histograms(): + with pytest.raises( + TypeError, match=r"passed histogram .*\(not a profile\), not str$" + ): + uproot.writing.to_TEfficiency("eff", "", "abc", (TOTAL, EDGES)) + with uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: + profile = f["hprof"] + with pytest.raises( + TypeError, match=r"total histogram .*\(not a profile\), not Model_TProfile" + ): + uproot.writing.to_TEfficiency("eff", "", (PASSED, EDGES), profile) + + +def test_histograms_of_different_dimensions(): + two_d = (np.ones((6, 2)), EDGES, np.arange(3, dtype=np.float64)) + with pytest.raises(ValueError, match="same number of dimensions"): + uproot.writing.to_TEfficiency("eff", "", (PASSED, EDGES), two_d) + + +@pytest.mark.parametrize("option", [-1, 9, 100]) +def test_statistic_option_numbers_out_of_range(option): + with pytest.raises(ValueError, match=f"statistic option {option}"): + efficiency(fStatisticOption=option) + + +def test_statistic_option_as_a_number(): + assert efficiency(fStatisticOption=2).statistic_option == "kFWilson" + + +def test_bin_priors_as_a_structured_array(): + params = np.array( + [(1.0, 2.0), (3.0, 4.0)], dtype=[("first", "f4"), ("second", "f4")] + ) + eff = efficiency(fBeta_bin_params=params, fStatisticOption="kBBayesian") + assert eff.beta_bin_params.dtype == uproot.models.TEfficiency._beta_bin_params_dtype + assert eff.beta_bin_params.tolist() == [(1.0, 2.0), (3.0, 4.0)] + # with priors per bin and a general Bayesian option, they are used + assert eff.member("@fBits") & uproot.behaviors.TEfficiency.kUseBinPrior + + +@pytest.mark.parametrize("option", ["kBJeffrey", "kBUniform"]) +def test_bin_priors_are_not_used_with_a_fixed_prior(option): + eff = efficiency(fBeta_bin_params=[(1.0, 2.0)], fStatisticOption=option) + assert not eff.member("@fBits") & uproot.behaviors.TEfficiency.kUseBinPrior + + +@pytest.mark.parametrize("use_weights", [True, False]) +def test_explicit_use_weights(use_weights): + eff = efficiency(use_weights=use_weights) + assert eff.uses_weights == use_weights + + +# ---- the model ----------------------------------------------------------------------- +def read_beta_bin_params(data): + with uproot.open(skhep_testdata.data_path("uproot-small-flat-tree.root")) as f: + chunk = uproot.source.chunk.Chunk.wrap( + f.file.source, np.frombuffer(data, np.uint8) + ) + cursor = uproot.source.cursor.Cursor(0) + out = uproot.models.TEfficiency._read_beta_bin_params( + chunk, cursor, {}, f.file, f.file.detached, None + ) + assert cursor.index == len(data) + return out.tolist() + + +def with_header(payload, version): + return struct.pack(">IH", kByteCount | (len(payload) + 2), version) + payload + + +def test_objectwise_pairs_with_a_version(): + # a pair with a nonzero version has no checksum after its header + pairs = struct.pack(">i", 2) + b"".join( + with_header(struct.pack(">dd", a, b), 1) for a, b in [(1.0, 2.0), (3.0, 4.0)] + ) + assert read_beta_bin_params(with_header(pairs, 9)) == [(1.0, 2.0), (3.0, 4.0)] + + +def test_memberwise_pairs_with_a_version(): + # a pair class with a nonzero version has no checksum after its version + payload = ( + struct.pack(">h", 1) + + struct.pack(">i", 2) + + struct.pack(">2d", 1.0, 3.0) + + struct.pack(">2d", 2.0, 4.0) + ) + assert read_beta_bin_params(with_header(payload, 9 | kMemberwise)) == [ + (1.0, 2.0), + (3.0, 4.0), + ] + + +def test_bin_priors_given_as_plain_pairs_are_written(): + out = [] + uproot.models.TEfficiency._serialize_beta_bin_params(out, [[1.0, 2.0], [3.0, 4.0]]) + assert read_beta_bin_params(b"".join(out)) == [(1.0, 2.0), (3.0, 4.0)] + + +def test_class_rawstreamers_without_histograms(): + eff = efficiency() + with_histograms = eff.class_rawstreamers + eff._members["fPassedHistogram"] = None + eff._members["fTotalHistogram"] = None + without = eff.class_rawstreamers + assert uproot.models.TEfficiency._rawstreamer_TEfficiency_v2 in without + assert set(without) < set(with_histograms) + + +def test_serialize_without_a_header(): + eff = efficiency() + with_header_ = [] + eff._serialize(with_header_, True, "eff", np.uint32(0)) + without_header = [] + eff._serialize(without_header, False, "eff", np.uint32(0)) + # the header is the byte count and version 2 + assert b"".join(with_header_)[6:] == b"".join(without_header) + assert b"".join(with_header_)[4:6] == b"\x00\x02" From b22aa0367ea9c3868910cd499295028ab033fd48 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 18 Nov 2026 16:35:30 -0500 Subject: [PATCH 5/6] chore: use the new repo name in the tests merged after the rename Assisted-by: Claude Code:claude-opus-5-5 --- tests/test_1782_rntuple_arrays_zip_and_asarray.py | 2 +- tests/test_1808_rntuple_schema_evolution.py | 2 +- tests/test_1827_fix_writing.py | 2 +- tests/test_1829_cov_interp_arrays.py | 2 +- tests/test_1829_cov_interp_containers.py | 2 +- tests/test_1829_cov_interp_forth.py | 2 +- tests/test_1829_cov_interp_identify.py | 2 +- tests/test_1829_cov_interp_language.py | 2 +- tests/test_1829_cov_interp_library.py | 2 +- tests/test_1829_cov_interp_objects.py | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/test_1782_rntuple_arrays_zip_and_asarray.py b/tests/test_1782_rntuple_arrays_zip_and_asarray.py index b5923c256..63fe0fc71 100644 --- a/tests/test_1782_rntuple_arrays_zip_and_asarray.py +++ b/tests/test_1782_rntuple_arrays_zip_and_asarray.py @@ -1,4 +1,4 @@ -# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/main/LICENSE from __future__ import annotations diff --git a/tests/test_1808_rntuple_schema_evolution.py b/tests/test_1808_rntuple_schema_evolution.py index 6db841ebd..fc63b9add 100644 --- a/tests/test_1808_rntuple_schema_evolution.py +++ b/tests/test_1808_rntuple_schema_evolution.py @@ -1,4 +1,4 @@ -# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/main/LICENSE from __future__ import annotations diff --git a/tests/test_1827_fix_writing.py b/tests/test_1827_fix_writing.py index bc6bf4d87..dd40059cb 100644 --- a/tests/test_1827_fix_writing.py +++ b/tests/test_1827_fix_writing.py @@ -1,4 +1,4 @@ -# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/main/LICENSE from __future__ import annotations diff --git a/tests/test_1829_cov_interp_arrays.py b/tests/test_1829_cov_interp_arrays.py index 038d05b4b..ab058907a 100644 --- a/tests/test_1829_cov_interp_arrays.py +++ b/tests/test_1829_cov_interp_arrays.py @@ -1,4 +1,4 @@ -# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/main/LICENSE """ Tests of the interpretations that are not objects: uproot.interpretation.numerical, diff --git a/tests/test_1829_cov_interp_containers.py b/tests/test_1829_cov_interp_containers.py index e90ced2cb..892e9bd91 100644 --- a/tests/test_1829_cov_interp_containers.py +++ b/tests/test_1829_cov_interp_containers.py @@ -1,4 +1,4 @@ -# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/main/LICENSE """ Unit tests of uproot.containers: the AsContainer descriptions (their typename, diff --git a/tests/test_1829_cov_interp_forth.py b/tests/test_1829_cov_interp_forth.py index 663ca2109..d198d8694 100644 --- a/tests/test_1829_cov_interp_forth.py +++ b/tests/test_1829_cov_interp_forth.py @@ -1,4 +1,4 @@ -# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/main/LICENSE """ Tests of the Forth node tree in uproot._awkwardforth, independently of any diff --git a/tests/test_1829_cov_interp_identify.py b/tests/test_1829_cov_interp_identify.py index ffeb5a3aa..2ec1fd883 100644 --- a/tests/test_1829_cov_interp_identify.py +++ b/tests/test_1829_cov_interp_identify.py @@ -1,4 +1,4 @@ -# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/main/LICENSE """ Tests of uproot.interpretation.identify: the C++ typename parser, driven by diff --git a/tests/test_1829_cov_interp_language.py b/tests/test_1829_cov_interp_language.py index 640b8c408..382f607e1 100644 --- a/tests/test_1829_cov_interp_language.py +++ b/tests/test_1829_cov_interp_language.py @@ -1,4 +1,4 @@ -# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/main/LICENSE """ Tests of uproot.language.python, the default language of expressions. diff --git a/tests/test_1829_cov_interp_library.py b/tests/test_1829_cov_interp_library.py index 10f2341d2..cfff415cd 100644 --- a/tests/test_1829_cov_interp_library.py +++ b/tests/test_1829_cov_interp_library.py @@ -1,4 +1,4 @@ -# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/main/LICENSE """ Tests of uproot.interpretation.library: finalizing, grouping and concatenating diff --git a/tests/test_1829_cov_interp_objects.py b/tests/test_1829_cov_interp_objects.py index b26e5a1eb..7ae21b527 100644 --- a/tests/test_1829_cov_interp_objects.py +++ b/tests/test_1829_cov_interp_objects.py @@ -1,4 +1,4 @@ -# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/main/LICENSE """ Tests of deserialization through uproot.interpretation.objects and the read From f1939cb02d40c461f3244ccb43740be5279617eb Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 18 Nov 2026 16:37:34 -0500 Subject: [PATCH 6/6] test: cover the message about a missing scipy #1822 added uproot.extras.scipy for the TEfficiency intervals. Assisted-by: Claude Code:claude-opus-5-5 --- tests/test_1830_cov_io_exceptions_extras.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_1830_cov_io_exceptions_extras.py b/tests/test_1830_cov_io_exceptions_extras.py index 552e89b8a..fdd10964d 100644 --- a/tests/test_1830_cov_io_exceptions_extras.py +++ b/tests/test_1830_cov_io_exceptions_extras.py @@ -69,6 +69,7 @@ def test_message_narrows_huge_list_of_keys_by_prefix(): (uproot.extras.XRootD_client, ["XRootD"], "Install XRootD python bindings"), (uproot.extras.isal, ["isal"], "install the 'isal' package"), (uproot.extras.deflate, ["deflate"], "install the 'deflate' package"), + (uproot.extras.scipy, ["scipy"], "install the 'scipy' package"), ( uproot.extras.boost_histogram, ["boost_histogram"],