-
Notifications
You must be signed in to change notification settings - Fork 135
feat: support explicit bulk preloading (uproot-only) #1387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -267,6 +267,7 @@ def from_root( | |
| decompression_executor=None, | ||
| interpretation_executor=None, | ||
| delayed=uproot._util.unset, | ||
| preload=None, | ||
| ): | ||
| """Quickly build NanoEvents from a root file | ||
|
|
||
|
|
@@ -310,6 +311,9 @@ def from_root( | |
| see: https://github.com/scikit-hep/uproot5/blob/main/src/uproot/_dask.py#L109 | ||
| interpretation_executor (None or Executor with a ``submit`` method): | ||
| see: https://github.com/scikit-hep/uproot5/blob/main/src/uproot/_dask.py#L113 | ||
| preload (None or Callable): | ||
| A function to call to preload specific branches/columns in bulk. Only works in eager and virtual mode. | ||
| Passed to ``tree.arrays`` as the ``filter_branch`` argument to filter branches to be preloaded. | ||
|
Comment on lines
+314
to
+316
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above, I'd not put this in the end. |
||
|
|
||
| Returns | ||
| ------- | ||
|
|
@@ -415,6 +419,24 @@ def from_root( | |
| f"{entry_start}-{entry_stop}", | ||
| ) | ||
| uuidpfn = {partition_key[0]: tree.file.file_path} | ||
|
|
||
| preloaded_arrays = None | ||
| if preload is not None: | ||
| preloaded_arrays = tree.arrays( | ||
| filter_branch=preload, | ||
| entry_start=entry_start, | ||
| entry_stop=entry_stop, | ||
| ak_add_doc=True, | ||
| decompression_executor=decompression_executor, | ||
| interpretation_executor=interpretation_executor, | ||
| how=dict, | ||
| ) | ||
| # this ensures that the preloaded arrays are only sliced as they are supposed to be | ||
| preloaded_arrays = { | ||
| k: _OnlySliceableAs(v, slice(entry_start, entry_stop)) | ||
| for k, v in preloaded_arrays.items() | ||
| } | ||
|
|
||
| mapping = UprootSourceMapping( | ||
| TrivialUprootOpener(uuidpfn, uproot_options), | ||
| entry_start, | ||
|
|
@@ -423,6 +445,7 @@ def from_root( | |
| access_log=access_log, | ||
| use_ak_forth=use_ak_forth, | ||
| virtual=mode == "virtual", | ||
| preloaded_arrays=preloaded_arrays, | ||
| ) | ||
| mapping.preload_column_source(partition_key[0], partition_key[1], tree) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably move this further up the list. Maybe after entry start and entry stop? We want this to be visible no?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't mean to mess with the order in case people pass positional args here - that would be a breaking change. Maybe coffea may want to force all of those options to be passed as kw-only at some point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh yeah you're right about that. I guess I've never seen a person not pass kwargs that's why I said this. Indeed forcing kwargs would be best here from the coffea side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lgray what do you think? Should we enforce kwargs in a separate PR? Should we just break the order here and not care? I've actually never seen anybody use positional args here because the first argument
treepathis something that's never used because no one is actually passing in anuproot.reading.ReadOnlyDirectorytofrom_root.`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah - sorry for missing this. I would take it to a separate PR. I hope no one is actually using those and positional arguments though.