iris-hep / func_adl

Construct hierarchical data queries using SQL-like concepts in python
MIT License
7 stars 4 forks source link

Zip lookup for function types is causing a type tracing failure #148

Closed gordonwatts closed 1 month ago

gordonwatts commented 1 month ago

This is from @ponyisi.

You get this error:

  File "/home/onyisi/servicex/analysis-grand-challenge/analyses/cms-open-data-ttbar/venv/lib64/python3.9/site-packages/func_adl/type_based_replacement.py", line 971, in visit_Attribute
    raise ValueError(f"Key {key} not found in dict expression!!")
ValueError: Key Zip not found in dict expression!!

When running this AGC code:

    cuts = source.Where(lambda e: {"pt": e.Electron_pt,
                               "eta": e.Electron_eta,
                               "cutBased": e.Electron_cutBased,
                               "sip3d": e.Electron_sip3d,}.Zip()\
                        .Where(lambda electron: (electron.pt > 30
                                                 and abs(electron.eta) < 2.1
                                                 and electron.cutBased == 4
                                                 and electron.sip3d < 4)).Count()
                        + {"pt": e.Muon_pt,
                           "eta": e.Muon_eta,
                           "tightId": e.Muon_tightId,
                           "sip3d": e.Muon_sip3d,
                           "pfRelIso04_all": e.Muon_pfRelIso04_all}.Zip()\
                        .Where(lambda muon: (muon.pt > 30
                                             and abs(muon.eta) < 2.1
                                             and muon.tightId
                                             and muon.pfRelIso04_all < 0.15)).Count()== 1)\
                        .Where(lambda f: {"pt": f.Jet_pt,
                                          "eta": f.Jet_eta,
                                          "jetId": f.Jet_jetId}.Zip()\
                               .Where(lambda jet: (jet.pt > 25
                                                   and abs(jet.eta) < 2.4
                                                   and jet.jetId == 6)).Count() >= 4)\
                        .Where(lambda g: {"pt": g.Jet_pt,
                                          "eta": g.Jet_eta,
                                          "btagCSVV2": g.Jet_btagCSVV2,
                                          "jetId": g.Jet_jetId}.Zip()\
                        .Where(lambda jet: (jet.btagCSVV2 > 0.5
                                            and jet.pt > 25
                                            and abs(jet.eta) < 2.4)
                                            and jet.jetId == 6).Count() >= 1)

Likely the problem is the function lookup should trigger an Any type return, not a total failure like this. And, further, it should work if the system has some type information (to catch mispellings).

gordonwatts commented 1 month ago

The error isn't what I thought it was. The problem is that <object>.name is a name lookup in <object>. So that is what is failing.

Here this is a function call. So we'll have to special case this, if Zip does not exist in a dictionary.