B.root (5.3 KB)
A.root (5.3 KB)
Hi everyone,
I’m having some problems setting a default value for a column of type Char_t.
I have two root files with trees, which I load into a dataframe. The first file contains a branch A of type Char_t which I interpret as boolean values. The second file is missing this branch, so I’m trying to set a default value that will evaluate to false when I do bool(A).
I managed setting a default value for a float branch by using ROOT.float(0), but the same approach with ROOT.Char_t(0) doesn’t work as expected, as the default is set to 48 which evaluates to true. I can work around this by checking explicitly for A==1, but this seems a bit awkward (especially since I cannot set 1 as a default value either), so I was wondering if there is a cleaner solution for this.
import ROOT
df = ROOT.RDataFrame("tree", ["A.root", "B.root"])
print(df.GetColumnType("A"))
df = df.DefaultValueFor("A", ROOT.Char_t(0))
df = df.Define("passA", "bool(A)")
df.Display(["A", "passA"]).Print()
Output:
Char_t
+-----+----+-------+
| Row | A | passA |
+-----+----+-------+
| 0 | 0 | false |
+-----+----+-------+
| 1 | 1 | true |
+-----+----+-------+
| 2 | 48 | true |
+-----+----+-------+
| 3 | 48 | true |
+-----+----+-------+
ROOT Version: 6.36.04
Platform: EL9
Compiler: gcc14