-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[df] Unify local and distributed API #16681
Open
vepadulano
wants to merge
1
commit into
root-project:master
Choose a base branch
from
vepadulano:rdf-distrdf-unify-api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+220
−69
Open
Changes from all commits
Commits
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 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
This file contains 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 |
---|---|---|
@@ -1,15 +1,17 @@ | ||
## @author Vincenzo Eduardo Padulano | ||
# @author Vincenzo Eduardo Padulano | ||
# @author Enric Tejedor | ||
# @date 2021-02 | ||
|
||
################################################################################ | ||
# Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. # | ||
# Copyright (C) 1995-2024, Rene Brun and Fons Rademakers. # | ||
# All rights reserved. # | ||
# # | ||
# For the licensing terms see $ROOTSYS/LICENSE. # | ||
# For the list of contributors see $ROOTSYS/README/CREDITS. # | ||
################################################################################ | ||
from __future__ import annotations | ||
import warnings | ||
|
||
|
||
def RDataFrame(*args, **kwargs): | ||
""" | ||
|
@@ -18,6 +20,29 @@ def RDataFrame(*args, **kwargs): | |
|
||
from DistRDF.Backends.Spark import Backend | ||
sparkcontext = kwargs.get("sparkcontext", None) | ||
spark = Backend.SparkBackend(sparkcontext=sparkcontext) | ||
executor = kwargs.get("executor", None) | ||
msg_warn = ( | ||
"The keyword argument 'sparkcontext' is not necessary anymore and will " | ||
"be removed in a future release. Use 'executor' instead to provide the " | ||
"SparkContext object." | ||
) | ||
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. To provide the SparkContext object, use 'executor' instead. |
||
msg_err = ( | ||
"Both the 'sparkcontext' and 'executor' keyword arguments were provided. " | ||
"This is not supported. Please provide only the 'executor' argument." | ||
) | ||
|
||
if sparkcontext is not None: | ||
warnings.warn(msg_warn, FutureWarning) | ||
if executor is not None: | ||
raise ValueError(msg_err) | ||
else: | ||
executor = sparkcontext | ||
sparkcontext = None | ||
|
||
if executor is not None and sparkcontext is not None: | ||
warnings.warn(msg_warn, FutureWarning) | ||
raise ValueError(msg_err) | ||
|
||
spark = Backend.SparkBackend(sparkcontext=executor) | ||
|
||
return spark.make_dataframe(*args, **kwargs) |
This file contains 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
This file contains 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
This file contains 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
85 changes: 85 additions & 0 deletions
85
bindings/pyroot/pythonizations/python/ROOT/_pythonization/_rdf_namespace.py
This file contains 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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Author: Vincenzo Eduardo Padulano CERN 10/2024 | ||
|
||
################################################################################ | ||
# Copyright (C) 1995-2024, Rene Brun and Fons Rademakers. # | ||
# All rights reserved. # | ||
# # | ||
# For the licensing terms see $ROOTSYS/LICENSE. # | ||
# For the list of contributors see $ROOTSYS/README/CREDITS. # | ||
################################################################################ | ||
|
||
""" | ||
This module contains utilities to help in the organization of the RDataFrame | ||
namespace and the interaction between the C++ and Python functionalities | ||
""" | ||
|
||
|
||
def _create_distributed_module(parent): | ||
""" | ||
Create the ROOT.RDF.Experimental.Distributed python module. | ||
|
||
This module will be injected into the ROOT.RDF namespace. | ||
|
||
Arguments: | ||
parent: The ROOT.RDF namespace. Needed to define __package__. | ||
|
||
Returns: | ||
types.ModuleType: The ROOT.RDF.Experimental.Distributed submodule. | ||
""" | ||
import DistRDF | ||
|
||
return DistRDF.create_distributed_module(parent) | ||
|
||
|
||
def _rungraphs(distrdf_rungraphs, rdf_rungraphs): | ||
""" | ||
Create a callable that correctly dispatches either to the local or | ||
distributed version of RunGraphs. | ||
""" | ||
|
||
def rungraphs(handles): | ||
# Caveat: we should not call `hasattr` on the result pointer, since | ||
# this will implicitly trigger the connected computation graph | ||
if len(handles) > 0 and "DistRDF" in str(type(handles[0])): | ||
return distrdf_rungraphs(handles) | ||
else: | ||
return rdf_rungraphs(handles) | ||
|
||
return rungraphs | ||
|
||
|
||
def _variationsfor(distrdf_variationsfor, rdf_variationsfor): | ||
""" | ||
Create a callable that correctly dispatches either to the local or | ||
distributed version of VariationsFor. | ||
""" | ||
|
||
def variationsfor(resptr): | ||
# Caveat: we should not call `hasattr` on the result pointer, since | ||
# this will implicitly trigger the connected computation graph | ||
if "DistRDF" in str(type(resptr)): | ||
return distrdf_variationsfor(resptr) | ||
else: | ||
# Help local VariationsFor with the type of the value held by the result pointer | ||
inner_type = type(resptr).__name__ | ||
inner_type = inner_type[ | ||
inner_type.index("<") + 1: inner_type.rindex(">")] | ||
return rdf_variationsfor[inner_type](resptr) | ||
|
||
return variationsfor | ||
|
||
|
||
def _rdataframe(local_rdf, distributed_rdf): | ||
""" | ||
Create a callable that correctly dispatches either to the local or | ||
distributed RDataFrame constructor, depending on whether the "executor" | ||
keyword argument is absent or not. | ||
""" | ||
|
||
def rdataframe(*args, **kwargs): | ||
if kwargs.get("executor", None) is not None: | ||
return distributed_rdf(*args, **kwargs) | ||
else: | ||
return local_rdf(*args, **kwargs) | ||
|
||
return rdataframe |
Oops, something went wrong.
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.
last sentence I would just change order to make it more clear:
"To provide the distributed.Client object, use 'executor' instead".