Dealing with NaN results while JITing in RDFs

Hi,

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?

Okay Maybe I sent this too soon :smiley:

A solution can be

df.Define("ztmp","x/y").Define("z","TMath::Finite(ztmp) ? ztmp: 0"); 

which seems to work. Is there a better/cleaner way?

Hello,

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” :wink: )

I hope it helps.

Cheers,
D

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.