# NaN values in one column break histogram of another column

**URL:** <https://root-forum.cern.ch/t/nan-values-in-one-column-break-histogram-of-another-column/37091>\
**Category:** ROOT\
**Tags:** bug, rdataframe, hist\
**Created:** [December 6, 2019, 7:41pm UTC](https://root-forum.cern.ch/t/nan-values-in-one-column-break-histogram-of-another-column/37091 "2019-12-06T19:41:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [December 6, 2019, 7:41pm UTC](https://root-forum.cern.ch/t/nan-values-in-one-column-break-histogram-of-another-column/37091/1 "2019-12-06T19:41:49Z")

</div>

If I have an `RDataFrame` where some of the values in some of the columns are NaN, I cannot make a histogram from a column without NaN values:

```auto
Exception: TH1D& ROOT::RDF::RResultPtr<TH1D>::operator*() =>
    stoll: no conversion (C++ exception of type invalid_argument)

```

Reproducer follows.

* * *

Suppose I have 2 csv files, one with all filled values and one with some empty values:

```auto
$ cat temp_good.csv 
a,b,c
1,2,3
1,2,3
1,2,3

```

```auto
$ cat temp_bad.csv 
a,b,c
1,2,3
1,2,
1,,

```

I can successfully make a histogram of ‘a’ from `temp_good.csv`, but not `temp_bad.csv`, even though ‘a’ has all its values defined in both files:

```python
In [1]: import ROOT

In [2]: df_good = ROOT.RDF.MakeCsvDataFrame('temp_good.csv')

In [3]: h_good = df_good.Histo1D('a')

In [4]: h_good.SetFillStyle(3845)

In [5]: df_bad = ROOT.RDF.MakeCsvDataFrame('temp_bad.csv')

In [6]: h_bad = df_bad.Histo1D('a')

In [7]: h_bad.SetFillStyle(3845)
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-7-4aa1c7efd4fb> in <module>()
----> 1 h_bad.SetFillStyle(3845)

Exception: TH1D& ROOT::RDF::RResultPtr<TH1D>::operator*() =>
    stoll: no conversion (C++ exception of type invalid_argument)

```

* * *

_ROOT Version:_ master  
_Platform:_ macOS  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [December 9, 2019, 10:09am UTC](https://root-forum.cern.ch/t/nan-values-in-one-column-break-histogram-of-another-column/37091/2 "2019-12-09T10:09:19Z")

</div>

Can’t you make the 2nd file:

```auto
a,b,c
1,2,3
1,2,0
1,0,0

```

?

---

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [December 9, 2019, 2:10pm UTC](https://root-forum.cern.ch/t/nan-values-in-one-column-break-histogram-of-another-column/37091/3 "2019-12-09T14:10:07Z")

</div>

Well, no, if I have a dataset for which the correct value really is undefined or NaN. One could, of course, find a workaround that involves assigning a dummy value, say -1, instead of NaN, but I’m not sure why a user should have to; it seems the most desirable/intuitive workflow would be:

```python
h_bad_a = df_bad.Histo1D('a')
h_bad_b = df_bad.Filter('!TMath::IsNan("b")').Histo1D('b')

```

---

<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:** [December 9, 2019, 2:37pm UTC](https://root-forum.cern.ch/t/nan-values-in-one-column-break-histogram-of-another-column/37091/4 "2019-12-09T14:37:57Z")

</div>

Hi,  
I’m afraid the CSV datasource does not support NaN values (@etejedor can confirm).  
You can request the feature on JIRA, although I am not sure how long it might take for it to float at the top of the to-do list.

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [December 9, 2019, 3:29pm UTC](https://root-forum.cern.ch/t/nan-values-in-one-column-break-histogram-of-another-column/37091/5 "2019-12-09T15:29:07Z")

</div>

I confirm what Enrico said, unfortunately NaN are not supported by the CSV data source.

---

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [December 9, 2019, 3:53pm UTC](https://root-forum.cern.ch/t/nan-values-in-one-column-break-histogram-of-another-column/37091/6 "2019-12-09T15:53:02Z")

</div>

Okay, I added an [issue](https://sft.its.cern.ch/jira/browse/ROOT-10476) to the JIRA with minor priority. Hopefully a fix will be in the works eventually, as this needlessly limits the utility of `RDataFrame`.

---

<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 23, 2019, 3:53pm UTC](https://root-forum.cern.ch/t/nan-values-in-one-column-break-histogram-of-another-column/37091/7 "2019-12-23T15:53:03Z")

</div>

Closed on December 23, 2019, 3:53pm UTC

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

---

<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:** [May 4, 2022, 8:20am UTC](https://root-forum.cern.ch/t/nan-values-in-one-column-break-histogram-of-another-column/37091/8 "2022-05-04T08:20:01Z")

</div>

Hi,  
it took a while, but thanks to @ikabadzhov this is now fixed in master 🙂
