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

Lookup for dicts is causing uproot backend function to fail #154

Open
masonproffitt opened this issue Oct 15, 2024 · 1 comment
Open

Lookup for dicts is causing uproot backend function to fail #154

masonproffitt opened this issue Oct 15, 2024 · 1 comment

Comments

@masonproffitt
Copy link
Member

masonproffitt commented Oct 15, 2024

I'm seeing basically the same problem as #148 with ToFourMomentum, which I use in func-adl-uproot to create vector objects:

self = <func_adl.type_based_replacement.remap_by_types.<locals>.type_transformer object at 0x7f016eee1400>
node = <ast.Attribute object at 0x7f016f56fe50>

    def visit_Attribute(self, node: ast.Attribute) -> Any:
        t_node = self.generic_visit(node)
        assert isinstance(t_node, ast.Attribute)
        # If this is a dict reference, then figure out what the
        # type is for that value of the dict.
        if isinstance(t_node.value, ast.Dict):
            key = t_node.attr
            key_index = [
                e for e, k in enumerate(t_node.value.keys) if k.value == key  # type: ignore
            ]
            if len(key_index) == 0:
                if t_node.attr.lower() == "zip":
                    return t_node
>               raise ValueError(f"Key {key} not found in dict expression!!")
E               ValueError: Key ToFourMomentum not found in dict expression!!

This is coming from something like:

{
    'pt': Electron_pt,
    'eta': Electron_eta,
    'phi': Electron_phi,
    'mass': Electron_mass,
}.ToFourMomentum()

I think I use other functions in a pattern like this (not just Zip() and ToFourMomentum()), and I can imagine this would be a common type of thing for backends to add, so probably this should not raise an error and be a warning at most...

@masonproffitt
Copy link
Member Author

Or maybe it should just skip trying to look things up if the Attribute is a function call? I think that's really what the problem is.

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

No branches or pull requests

1 participant