# Possible bug in RDataFrame Define with lambdas?

**URL:** <https://root-forum.cern.ch/t/possible-bug-in-rdataframe-define-with-lambdas/51132>\
**Category:** ROOT\
**Tags:** rdataframe, python\
**Created:** [August 10, 2022, 11:10am UTC](https://root-forum.cern.ch/t/possible-bug-in-rdataframe-define-with-lambdas/51132 "2022-08-10T11:10:28Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![FoxWise](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/foxwise/32/37588_2.png) [@FoxWise](https://root-forum.cern.ch/u/FoxWise)\
**Post date:** [August 10, 2022, 3:23pm UTC](https://root-forum.cern.ch/t/possible-bug-in-rdataframe-define-with-lambdas/51132/2 "2022-08-10T15:23:10Z")

</div>

Hi Day,

I guess it is expected and known behaviour that you need a `return` there.

I also stumbled in the same problem a while ago.  
You can see detailed Enrico’s reply in the post below on why is that the case:

> [@Call method for every object in RVec in a single line](https://root-forum.cern.ch/t/call-method-for-every-object-in-rvec-in-a-single-line/49428):
>
> Hi all, I have a std::vector\<XYZVector\> stored in TTree. Is there an easy way to get absolute momentum XYZVector.R() for each element of the array within RDataFrame? The one I am currently using is: ROOT.gInterpreter.Declare(''' using namespace ROOT::Math; using namespace ROOT::VecOps; RVec \<double\> getAbsOfVectors(const RVec\<XYZVector\>& vecs){ auto getAbs = [&](const XYZVector& vec) { return vec.R(); }; return Map(vecs, getAbs); } ''') df = ROOT.RDataFrame("tree", "file.root")…

as far as I understood, the issue is that in your expression inside lambda function you already have a `return` word. So RDF does not automatically put any returns inside to avoid confusion, so you have to write it manually in the beginning in this case.

I agree a better documentation&example for this case would be nice.

cheers,  
Bohdan

---

_[View the full topic](https://root-forum.cern.ch/t/possible-bug-in-rdataframe-define-with-lambdas/51132)._
