Using Take in pyROOT

Continuing the discussion from pyROOT and RDataFrame Take:

How can I use RDataFrame::Take in pyROOT? The instruction to do df.Take('std::vector<float>')('FT_true_z') in the above post does not seem to work.

Reproducer:

import ROOT as r
rdf = r.RDataFrame(10).Define("e", "rdfentry_")
rdf.Take(rdf.GetColumnType("e"))("e")

output:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [5], in <cell line: 1>()
----> 1 rdf.Take(rdf.GetColumnType("e"))("e")

TypeError: Template method resolution failed:
  Failed to instantiate "Take(std::string)"

ROOT Version: 6.26/04
Platform: macOS
Compiler: conda-forge


Hi @mwilkins,

It seems that cppyy is not finding the right Take() overload. Maybe @etejedor can provide some insights on this.

Cheers,
J.

Hi @mwilkins ,

new PyROOT wants square brackes rather than round brackets. If you saw round branches somewhere in our docs let us know.

This should work (works for me with master, but v6.26 should behave exactly the same way):

In [1]: import ROOT
ROOT
In [2]: df = ROOT.RDataFrame(10).Define("x", "42")
d.f
In [3]: r = df.Take['int']("x")

In [4]: r.GetValue()
Out[4]: <cppyy.gbl.std.vector<int> object at 0x561a06a46d10>

In [5]: r.GetValue().size()
Out[5]: 10

Cheers,
Enrico

I saw the round brackets in the solution linked above, not the docs, though I’m not sure where the square bracket behavior is documented, anyway. (I don’t have to do a lot of templating in pyROOT).

Hello,

It’s documented here:

Cheers,
Enric

1 Like

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