I was wondering if there is a way to handle NaN results when passing strings to be JIT compiled in RDFs, without knowing in advance what the cause of a Nan value can be.
For example if I pass
df.Define("z","x/y")
and let’s say I don’t know a priori how to protect this operation, then I want a behaviour similar to TTree.Draw which is to get a 0 from the operation where y=0 instead of a NaN. I am basically looking for an RDF equivalent to fillna in python’s pandas.DataFrame. Does this exist? Is there a way to hack it? Can I use some hack with the Define method to get it to work?
Thanks for posting and answering your own question. Jokes apart, I think you have suggested a pretty good solution already.
Since this is a division, and assuming x or y cannot be NaNs (which seem reasonable - correct me if I am wrong), one could use one single Define:
df.Define("ztmp", "x == 0. && y ==0. ? 0 : x/y")
or compiled
df.Define("ztmp", [](double x, double y){return x == 0. && y ==0. ? 0 : x/y}, {"x", "y"})
(assuming x and y are double if not float and “0.f” )