# PyROOT6.16 & RDataFrame: Filter-function does not return bool

**URL:** <https://root-forum.cern.ch/t/pyroot6-16-rdataframe-filter-function-does-not-return-bool/33301>\
**Category:** ROOT\
**Tags:** rdataframe, python\
**Created:** [March 25, 2019, 9:46am UTC](https://root-forum.cern.ch/t/pyroot6-16-rdataframe-filter-function-does-not-return-bool/33301 "2019-03-25T09:46:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniil\_Ponomarenko](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/daniil_ponomarenko/32/18136_2.png) [@Daniil\_Ponomarenko](https://root-forum.cern.ch/u/Daniil_Ponomarenko)\
**Post date:** [March 25, 2019, 9:46am UTC](https://root-forum.cern.ch/t/pyroot6-16-rdataframe-filter-function-does-not-return-bool/33301/1 "2019-03-25T09:46:56Z")

</div>

* * *

_ROOT Version:_ tags/v6-16-00@v6-16-00  
_Platform:_ macosx64  
_Compiler:_ gcc 4.2.1

* * *

Dear experts,

I meat similar issue as it was described [here](https://root-forum.cern.ch/t/pyroot-rdataframe-filter-function-does-not-return-bool/31077). It was [mentioned](https://root-forum.cern.ch/t/pyroot-rdataframe-filter-function-does-not-return-bool/31077/4) that starting from ROOT 6.16 it will be able to handle collections as RVec automagically. In my case for some reason, it doesn’t work.

Input file: [CERNBOX](https://cernbox.cern.ch/index.php/s/WSjiVnmoJJ8sZyV)

A simple code to reproduce the problem:

```auto
	ROOT.ROOT.EnableImplicitMT()

	RDF = ROOT.ROOT.RDataFrame

	df = RDF('treeAnaWZ','data17_13TeV.00341294_el.root')
	filterCut = df.Filter('el_pt>0')
	model = ROOT.RDF.TH1DModel("el_pt", ";p_{T} (el_{0}) MeV;", 100, 0., 100000.)
	myHisto = filterCut.Define("myP4", "el_pt").Histo1D(model, "myP4")

	myHisto = myHisto.Clone("unicName")
	myHisto.SetDirectory(0)
	myHisto.Draw("")

	ROOT.ROOT.DisableImplicitMT()

```

Log files: [failed.txt](https://root-forum.cern.ch/uploads/default/original/3X/d/c/dcedeecd8d6a5ec12320f7477856614c71d42dc1.txt) (63.5 KB)

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [March 25, 2019, 10:03am UTC](https://root-forum.cern.ch/t/pyroot6-16-rdataframe-filter-function-does-not-return-bool/33301/2 "2019-03-25T10:03:09Z")

</div>

Hi Daniil,  
`Filter` must decide whether to keep processing a given event or not, and to take that decision it requires the filtering expression to return a single boolean.  
However, if `el_pt` is an array, the expression `el_pt>0` is an array of values (result of the inequality for each of the members of the array).

Maybe what you want is something like

```auto
df.Define("myP4", "el_pt[el_pt>0]").Histo1D("myP4");

```

?

That fills an histogram with the pt of electrons that have `pt > 0`.

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![Daniil\_Ponomarenko](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/daniil_ponomarenko/32/18136_2.png) [@Daniil\_Ponomarenko](https://root-forum.cern.ch/u/Daniil_Ponomarenko)\
**Post date:** [March 25, 2019, 1:31pm UTC](https://root-forum.cern.ch/t/pyroot6-16-rdataframe-filter-function-does-not-return-bool/33301/3 "2019-03-25T13:31:03Z")

</div>

Hi @eguiraud,

Thanks! But for some reason it is also crashes with the same error

```auto
       ROOT.ROOT.EnableImplicitMT()
	RDF = ROOT.ROOT.RDataFrame
	df = RDF(treeName, file)
	filterCut = df.Filter("el_pt[el_pt>0]")
	model = ROOT.RDF.TH1DModel("myP4", ";p_{T} (el_{0}) MeV;", 100, 0., 100000.)
	myHisto = filterCut.Define("myP4", "el_pt[el_pt>0]").Histo1D(model, "myP4")

	myHisto.SetDirectory(0)
	myHisto.Draw("")

	ROOT.ROOT.DisableImplicitMT()

```

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [March 25, 2019, 1:42pm UTC](https://root-forum.cern.ch/t/pyroot6-16-rdataframe-filter-function-does-not-return-bool/33301/4 "2019-03-25T13:42:47Z")

</div>

Yes, because you still have a `Filter` that returns an array 😄 I’m using `Define` in my example above.

---

<div class="post-metadata">

**Author:** ![Daniil\_Ponomarenko](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/daniil_ponomarenko/32/18136_2.png) [@Daniil\_Ponomarenko](https://root-forum.cern.ch/u/Daniil_Ponomarenko)\
**Post date:** [March 25, 2019, 2:00pm UTC](https://root-forum.cern.ch/t/pyroot6-16-rdataframe-filter-function-does-not-return-bool/33301/5 "2019-03-25T14:00:57Z")

</div>

Right 😁. Thanks! Now it works.

---

<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:** [April 8, 2019, 2:01pm UTC](https://root-forum.cern.ch/t/pyroot6-16-rdataframe-filter-function-does-not-return-bool/33301/6 "2019-04-08T14:01:02Z")

</div>

Closed on April 8, 2019, 2:01pm UTC

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