Skip to content

Commit

Permalink
fix: aggregate keys to read ahead of time
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Oct 4, 2023
1 parent 5095382 commit 4a69863
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/uproot/_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,16 +897,23 @@ def read_tree(self, tree: HasBranches, start: int, stop: int) -> AwkArray:
# Populate container with placeholders if keys aren't required
# Otherwise, read from disk
container = {}
for buffer_key, dtype in form.expected_from_buffers(

expected_from_buffers = form.expected_from_buffers(
buffer_key=form_info.buffer_key
).items():
# Which key(s) does this buffer require. This code permits the caller
# to require multiple keys to compute a single buffer.
keys_for_buffer = form_info.keys_for_buffer_keys({buffer_key})
)

# At this point, we've dispensed with the information pertaining to
# which buffer keys were read. Instead, we'll populate the mapping for
# each buffer key whose source TTree keys were loaded.
keys_to_read = set.intersection(
*(form_info.keys_for_buffer_keys({k}) for k in expected_from_buffers)
)

for buffer_key, dtype in expected_from_buffers.items():
# If reading this buffer loads a permitted key, read from the tree
# We might not have _all_ keys if e.g. buffer A requires one
# but not two of the keys required for buffer B
if all(k in self.common_keys for k in keys_for_buffer):
if all(k in self.common_keys for k in keys_to_read):
container[buffer_key] = mapping[buffer_key]
# Otherwise, introduce a placeholder
else:
Expand Down

0 comments on commit 4a69863

Please sign in to comment.