Skip to content

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

@masonproffitt

Description

@masonproffitt

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions