# TypeError from RDataFrame::Reduce on std::vector\<myClass\> column

**URL:** <https://root-forum.cern.ch/t/typeerror-from-rdataframe-reduce-on-std-vector-myclass-column/62471>\
**Category:** ROOT\
**Tags:** python, rdataframe\
**Created:** [December 14, 2024, 2:41am UTC](https://root-forum.cern.ch/t/typeerror-from-rdataframe-reduce-on-std-vector-myclass-column/62471 "2024-12-14T02:41:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mtROOT](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/3d9bf3/32.png) [@mtROOT](https://root-forum.cern.ch/u/mtROOT)\
**Post date:** [December 14, 2024, 2:41am UTC](https://root-forum.cern.ch/t/typeerror-from-rdataframe-reduce-on-std-vector-myclass-column/62471/1 "2024-12-14T02:41:41Z")

</div>

Running the code below results in:

> Traceback (most recent call last):  
> File “/storage/gpfs\_data/neutrino/users/mt/ANA/spill\_slicing/test.py”, line 52, in   
> my\_vect = rdf.Reduce(ROOT.myS\_aggregator(), “v”, ROOT.std.vector(ROOT.myS)())  
> TypeError: can not resolve method template call for ‘Reduce’

It is not clear to me what’s wrong with the code.  
Using `ROOT::VecOps::Rec` as suggested [here](https://root-forum.cern.ch/t/pyroot-rdataframe-reduce-vector-branch-typeerror/42981) doesn.'t solve the issue.

```auto
# %%
import ROOT

# %%
ROOT.gInterpreter.ProcessLine("""
struct myS {
    int a;
    int b;
}
""")

# %%
ROOT.gInterpreter.ProcessLine("""
std::vector<myS> fill_row() {
    return std::vector<myS>(2);
}
""")

# %%
ROOT.gInterpreter.ProcessLine("""
int counter() {
    static int counter = 0;
    return counter++;
}
""")

# %%
rdf = ROOT.RDataFrame(5)
rdf = rdf.Define("i", "counter()")
rdf = rdf.Define("v", "fill_row()")

# %%
ROOT.gInterpreter.ProcessLine("""
struct myS_aggregator {                                                                                                  
    std::vector<myS> operator()(std::vector<myS> orig, std::vector<myS> toadd) {
        orig.insert(orig.end(), toadd.begin(), toadd.end());
        return orig;
    }                                                                             
};
""")

# %%
ROOT.gInterpreter.ProcessLine("""
struct my_sum {                                                                                                  
    int operator()(int orig, int toadd) {
        return orig + toadd;
    }                                                                             
};
""")

# %%
my_vect = rdf.Reduce(ROOT.myS_aggregator(), "v", ROOT.std.vector(ROOT.myS)())
print(my_vect)

# %%
my_sum = rdf.Reduce(ROOT.my_sum(), "i", 0)
print(my_sum.GetValue())

```

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [December 14, 2024, 9:35am UTC](https://root-forum.cern.ch/t/typeerror-from-rdataframe-reduce-on-std-vector-myclass-column/62471/2 "2024-12-14T09:35:42Z")

</div>

Hi,

I am sorry to read this code did not work out of the box for you.  
I tried it with master, 6.32.08 and 6.34.00 and it worked for me.  
What version are you using?

Cheers,  
Danilo

---

<div class="post-metadata">

**Author:** ![mtROOT](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/3d9bf3/32.png) [@mtROOT](https://root-forum.cern.ch/u/mtROOT)\
**Post date:** [December 15, 2024, 8:48am UTC](https://root-forum.cern.ch/t/typeerror-from-rdataframe-reduce-on-std-vector-myclass-column/62471/3 "2024-12-15T08:48:41Z")

</div>

Hi Danilo,

Thank you for your prompt response. I apologize for not mentioning earlier the specific ROOT version I am using. It is version 6.20/00.

Based on your reply, I understand that my code should, in principle, be compatible with this version (6.20/00). Could you please verify if this is the case? I would like to determine whether the issue lies with my code or with the ROOT version I am currently using.

Thank you in advance for your help.

Best regards,  
Matteo

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [December 15, 2024, 10:03am UTC](https://root-forum.cern.ch/t/typeerror-from-rdataframe-reduce-on-std-vector-myclass-column/62471/4 "2024-12-15T10:03:41Z")

</div>

Hi Matteo,

Yes, we do strive for providing maximum stability of interfaces.  
However, let me point out that ROOT 6.20 was released 4.5 y ago - The effort we have at disposal to backport fixes for that releases, provided it’s possible, is very limited.  
Is it possible that you update to 6.32.08? Your code will continue to work there.

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![mtROOT](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/3d9bf3/32.png) [@mtROOT](https://root-forum.cern.ch/u/mtROOT)\
**Post date:** [December 17, 2024, 12:18pm UTC](https://root-forum.cern.ch/t/typeerror-from-rdataframe-reduce-on-std-vector-myclass-column/62471/5 "2024-12-17T12:18:17Z")

</div>

Of course, I wasn’t complaining about that. I understand that it’s my responsibility to upgrade the ROOT version I’m using. I just wanted to confirm that the code is working properly. You can go ahead and close the ticket

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [December 17, 2024, 2:55pm UTC](https://root-forum.cern.ch/t/typeerror-from-rdataframe-reduce-on-std-vector-myclass-column/62471/6 "2024-12-17T14:55:20Z")

</div>

Hi Matteo,

Thanks for your reply. I was not implying at all it was your responsibility or fault: it’s just that the effort at our disposal is limited, and we need sometimes to make choices about what is supported - I agree that it would be awesome to maintain versions within, say, a 5 years window, but, so far, the effort at our disposal and the contributions by our community did not allow us to do so.

I am glad you managed to update and solve this problem. Do not hesitate to come back with questions, if any!

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [December 31, 2024, 2:56pm UTC](https://root-forum.cern.ch/t/typeerror-from-rdataframe-reduce-on-std-vector-myclass-column/62471/7 "2024-12-31T14:56:11Z")

</div>

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