Closed gordonwatts closed 1 year ago
Turns out it is the following lambda that is causing the problem here. Here is the minimum expression to cause the exception:
r = source.Where(lambda e:
# == 1 lep
e.electron_pt.Where(lambda pT: pT > 25).Count() + e.muon_pt.Where(lambda pT: pT > 25).Count()== 1
)\
.Where(lambda e:\
# >= 4 jets
e.jet_pt.Where(lambda pT: pT > 25).Count() >= 4
)
The lambda that fails to find is, I think, the first Where
.
If you let black
format this, then this works correctly (I've been using black
as the "must work" standard for lambda
's).
Even more condensed - this fails:
r = source.Where(lambda e:
e.electron_pt.Where(lambda pT: pT > 25).Count() + e.muon_pt.Where(lambda pT: pT > 25).Count()== 1)\
.Where(lambda e:\
e.jet_pt.Where(lambda pT: pT > 25).Count() >= 4
)
but this passes:
r = source.Where(lambda e:
e.electron_pt.Where(lambda pT: pT > 25).Count() + e.muon_pt.Where(lambda pT: pT > 25).Count()== 1)\
.Where(lambda e:
e.jet_pt.Where(lambda pT: pT > 25).Count() >= 4
)
(note the use of the uncessary continuation character in the Where
).
Ok - this comes down to the fact we aren't handling line continuation characters properly. python
hands us source code with the line continuation characters in them - which is crazy! So we need to take them out.
The below code (which is a test case) cauess an
assert
failure - no lambda is found.