diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a9eb1839a..df300245b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,7 +23,7 @@ repos: - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.4 + rev: v0.8.3 hooks: - id: ruff args: [--fix, --show-fixes] diff --git a/src/uproot/interpretation/objects.py b/src/uproot/interpretation/objects.py index 37306a135..89f2c8b1d 100644 --- a/src/uproot/interpretation/objects.py +++ b/src/uproot/interpretation/objects.py @@ -758,7 +758,7 @@ def __init__(self, model, members, original=None): member, value = members[i] if member is not None and not all_headers_prepended: all_headers_prepended = True - if member is None and all_headers_prepended or len(members) == 1: + if (member is None and all_headers_prepended) or len(members) == 1: all_headers_prepended = False del members[i] diff --git a/src/uproot/language/python.py b/src/uproot/language/python.py index f72f68f65..2f39bf3bf 100644 --- a/src/uproot/language/python.py +++ b/src/uproot/language/python.py @@ -497,13 +497,13 @@ def getter(name): if is_pandas: pandas = uproot.extras.pandas() - for name in output: + for name, data in output.items(): if ( is_pandas and isinstance(cut.index, pandas.MultiIndex) - and not isinstance(output[name].index, pandas.MultiIndex) + and not isinstance(data.index, pandas.MultiIndex) ): - original = output[name] + original = data modified = pandas.DataFrame( {original.name: original.values}, index=pandas.MultiIndex.from_arrays( @@ -514,7 +514,7 @@ def getter(name): output[name] = selected[original.name] else: - output[name] = output[name][cut] + output[name] = data[cut] # clear dicts to get rid of big arrays. # note: without this these arrays are not properly released from memory! diff --git a/src/uproot/reading.py b/src/uproot/reading.py index f50154569..6ce050a34 100644 --- a/src/uproot/reading.py +++ b/src/uproot/reading.py @@ -1943,7 +1943,7 @@ def title_of(self, where, recursive=True): Note that this does not read any data from the file. """ - if recursive and "/" in where or ":" in where: + if (recursive and "/" in where) or ":" in where: step, last_item = self.descent_into_path(where) return step[last_item].title else: @@ -1965,7 +1965,7 @@ def classname_of(self, where, encoded=False, version=None, recursive=True): Note that this does not read any data from the file. """ - if recursive and "/" in where or ":" in where: + if (recursive and "/" in where) or ":" in where: step, last_item = self.descent_into_path(where) return step[last_item].classname else: @@ -1987,7 +1987,7 @@ def class_of(self, where, version=None, recursive=True): Note that this does not read any data from the file. """ - if recursive and "/" in where or ":" in where: + if (recursive and "/" in where) or ":" in where: return self._file.class_named( self.classname_of(where, version=version), version=version ) @@ -2009,7 +2009,7 @@ def streamer_of(self, where, version="max", recursive=True): Note that this does not read any data from the file. """ - if recursive and "/" in where or ":" in where: + if (recursive and "/" in where) or ":" in where: return self._file.streamer_named( self.classname_of(where, version=version), version=version ) diff --git a/src/uproot/serialization.py b/src/uproot/serialization.py index 632069168..9b9ff3d61 100644 --- a/src/uproot/serialization.py +++ b/src/uproot/serialization.py @@ -37,9 +37,9 @@ def bytestring(data): """ length = len(data) if length < 255: - return struct.pack(">B%ds" % length, length, data) + return struct.pack(f">B{length}s", length, data) else: - return struct.pack(">BI%ds" % length, 255, length, data) + return struct.pack(f">BI{length}s", 255, length, data) def numbytes_version(num_bytes, version): diff --git a/src/uproot/writing/__init__.py b/src/uproot/writing/__init__.py index 8d88957f7..add713a3b 100644 --- a/src/uproot/writing/__init__.py +++ b/src/uproot/writing/__init__.py @@ -35,6 +35,13 @@ ) __all__ = [ + "WritableBranch", + "WritableDirectory", + "WritableFile", + "WritableTree", + "create", + "dask_write", + "recreate", "to_TArray", "to_TH1x", "to_TH2x", @@ -45,12 +52,5 @@ "to_TProfile2D", "to_TProfile3D", "to_writable", - "WritableDirectory", - "WritableFile", - "WritableTree", - "WritableBranch", - "create", - "recreate", "update", - "dask_write", ] diff --git a/src/uproot/writing/_cascadetree.py b/src/uproot/writing/_cascadetree.py index abf06053c..0c5619ab6 100644 --- a/src/uproot/writing/_cascadetree.py +++ b/src/uproot/writing/_cascadetree.py @@ -1098,22 +1098,20 @@ def write_anew(self, sink): out.append(uproot._util.tobytes(leaf_header)) if len(leaf_name) < 255: out.append( - struct.pack(">B%ds" % len(leaf_name), len(leaf_name), leaf_name) + struct.pack(f">B{len(leaf_name)}s", len(leaf_name), leaf_name) ) else: out.append( - struct.pack( - ">BI%ds" % len(leaf_name), 255, len(leaf_name), leaf_name - ) + struct.pack(f">BI{len(leaf_name)}s", 255, len(leaf_name), leaf_name) ) if len(leaf_title) < 255: out.append( - struct.pack(">B%ds" % len(leaf_title), len(leaf_title), leaf_title) + struct.pack(f">B{len(leaf_title)}s", len(leaf_title), leaf_title) ) else: out.append( struct.pack( - ">BI%ds" % len(leaf_title), 255, len(leaf_title), leaf_title + f">BI{len(leaf_title)}s", 255, len(leaf_title), leaf_title ) )