Skip to content

Commit

Permalink
[v4 backport] Set ReadOnlyDirectory attributes when fSeekKeys == 0 (#661
Browse files Browse the repository at this point in the history
)

* Set ReadOnlyDirectory attributes when fSeekKeys == 0

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* This B023 is okay (because it returns the last value seen; it doesn't allow the unbound value to change).

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* All of the B023 warnings are okay in this file.

I don't know why the v4 branch is complaining, whereas the v5 branch is not, and these should (ideally) be handled more centrally than tagging each use—that was probably done on the v5 branch. Nevertheless, we don't plan to develop this branch much more, just bug-fixes, so obfuscating it with "`# noqa: B023`" is not a problem here—just don't do it in the `main` (v5) branch!

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: Martin <ka_hei_martin_kwok@brown.edu>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jim Pivarski <jpivarski@users.noreply.github.com>
  • Loading branch information
4 people authored Aug 4, 2022
1 parent dd1c951 commit 68d1dd0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/uproot/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def regularize_rename(rename):
def applyrules(x):
for matcher, trans in rules:
if matcher.search(x) is not None:
return matcher.sub(trans, x)
return matcher.sub(trans, x) # noqa: B023
else:
return x

Expand Down
28 changes: 14 additions & 14 deletions src/uproot/behaviors/TBranch.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ def lazy(
is_self.append(True)

def real_filter_branch(branch):
return branch is original and filter_branch(branch)
return branch is original and filter_branch(branch) # noqa: B023

else:
is_self.append(False)
Expand Down Expand Up @@ -614,17 +614,17 @@ def real_filter_branch(branch):
)

def foreach(start):
stop = min(start + entry_step, entry_stop)
stop = min(start + entry_step, entry_stop) # noqa: B023
length = stop - start

fields = []
names = []
for key in common_keys:
branch = obj[key]
branch = obj[key] # noqa: B023

interpretation = branchid_interpretation[branch.cache_key]
interpretation = branchid_interpretation[branch.cache_key] # noqa: B023
form = interpretation.awkward_form(
obj.file,
obj.file, # noqa: B023
{
"index_format": "i64",
"header": False,
Expand All @@ -637,7 +637,7 @@ def foreach(start):
)

generator = awkward.layout.ArrayGenerator(
branch.array,
branch.array, # noqa: B023
(
None,
start,
Expand All @@ -654,7 +654,7 @@ def foreach(start):
length,
)
cache_key = "{}:{}:{}-{}:{}".format(
branch.cache_key,
branch.cache_key, # noqa: B023
interpretation.cache_key,
start,
stop,
Expand All @@ -665,7 +665,7 @@ def foreach(start):
generator, cache=array_cache, cache_key=cache_key
)
fields.append(virtualarray)
names.append(key)
names.append(key) # noqa: B023

recordarray = awkward.layout.RecordArray(fields, names, length)
partitions.append(recordarray)
Expand Down Expand Up @@ -3594,7 +3594,7 @@ def _get_dask_array(
is_self.append(True)

def real_filter_branch(branch):
return branch is original and filter_branch(branch)
return branch is original and filter_branch(branch) # noqa: B023

else:
is_self.append(False)
Expand Down Expand Up @@ -3671,13 +3671,13 @@ def delayed_get_array(ttree, key, start, stop):
dt, inner_shape = dt.subdtype

def foreach(start):
stop = min(start + entry_step, entry_stop)
stop = min(start + entry_step, entry_stop) # noqa: B023
length = stop - start

delayed_array = delayed_get_array(ttree, key, start, stop)
shape = (length,) + inner_shape
dask_arrays.append(
da.from_delayed(delayed_array, shape=shape, dtype=dt)
delayed_array = delayed_get_array(ttree, key, start, stop) # noqa: B023
shape = (length,) + inner_shape # noqa: B023
dask_arrays.append( # noqa: B023
da.from_delayed(delayed_array, shape=shape, dtype=dt) # noqa: B023
)

for start in range(entry_start, entry_stop, entry_step):
Expand Down
3 changes: 2 additions & 1 deletion src/uproot/reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,8 @@ def __init__(self, path, cursor, context, file, parent):
if self._fSeekKeys == 0:
self._header_key = None
self._keys = []

self._keys_lookup = {}
self._len = None
else:
keys_start = self._fSeekKeys
keys_stop = min(keys_start + self._fNbytesKeys + 8, file.fEND)
Expand Down

0 comments on commit 68d1dd0

Please sign in to comment.