Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ prek -a --quiet # lint/format (pre-commit: black, ruff, etc
- Test files are named `test_<issue-or-PR-number>_<short_description>.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).

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 5 additions & 6 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
32 changes: 19 additions & 13 deletions dev/make-models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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):
\"\"\"
Expand All @@ -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(
Expand All @@ -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"""
Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
18 changes: 8 additions & 10 deletions src/uproot/_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions src/uproot/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 5 additions & 10 deletions src/uproot/behaviors/RNTuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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


Expand Down
7 changes: 1 addition & 6 deletions src/uproot/behaviors/TBranch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions src/uproot/behaviors/TGraphAsymmErrors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
"""
Expand Down
14 changes: 8 additions & 6 deletions src/uproot/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/uproot/interpretation/identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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"))
Expand Down
45 changes: 18 additions & 27 deletions src/uproot/interpretation/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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 = {
Expand Down
Loading
Loading