Skip to content
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

Add other python functions to the syntatic sugar transformer #93

Open
gordonwatts opened this issue Mar 6, 2022 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@gordonwatts
Copy link
Member

It would be nice to use more python idioms in func_adl. A complete set in python 3.10.2 can be found here. A lot of them (filter, map, etc.) could be useful. A stretch goal would be enumerate which would allow you to do object pairing when you had a symmetric pairing function. This last perhaps does not belong here as it will require backend modifications.

@gordonwatts gordonwatts added the enhancement New feature or request label Mar 6, 2022
@alexander-held
Copy link
Member

Another useful feature would be support for list comprehensions. When Selecting many columns without the need to change names, there is a risk for typos (and lots of duplicate text) that could be avoided in that manner.

from func_adl_uproot import UprootDataset

dataset_opendata = "https://xrootd-local.unl.edu:1094//store/user/AGC/nanoAOD/TT_TuneCUETP8M1_13TeV-powheg-pythia8/"\
    "cmsopendata2015_ttbar_19980_PU25nsData2015v1_76X_mcRun2_asymptotic_v12_ext3-v1_00000_0000.root"

ds = UprootDataset(dataset_opendata, "Events")
# jet_query = ds.Select(lambda e: {"jet_pt": e["Jet_pt"], "jet_eta": e.Jet_eta})  # this works
jet_query = ds.Select(lambda e: {branch: getattr(e, branch) for branch in ["Jet_pt", "Jet_eta"]})  # does not work
# jet_query = ds.Select("lambda e: {" + ",".join(f"{repr(branch)}: e[{repr(branch)}]" for branch in ["Jet_pt", "Jet_eta"]) + "}")  # works via strings
print(jet_query.value())

The example above result in NameError: Unknown id: branch. @masonproffitt suggested the string-based approach as a workaround, which does work, but suffers from not being too readable (and no syntax highlighting in strings). Instead of getattr, another way to do this would be e[branch], but runs into the same problem.

I am not sure if there is any way to make this work with func_adl.func_adl_callable instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants