# Error when filling histogram with boolean in python

**URL:** <https://root-forum.cern.ch/t/error-when-filling-histogram-with-boolean-in-python/60398>\
**Category:** ROOT\
**Tags:** python, hist, root\
**Created:** [August 2, 2024, 4:06am UTC](https://root-forum.cern.ch/t/error-when-filling-histogram-with-boolean-in-python/60398 "2024-08-02T04:06:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![meowz](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/dc4da7/32.png) [@meowz](https://root-forum.cern.ch/u/meowz)\
**Post date:** [August 2, 2024, 4:06am UTC](https://root-forum.cern.ch/t/error-when-filling-histogram-with-boolean-in-python/60398/1 "2024-08-02T04:06:48Z")

</div>

I’ve encountered an error when attempting to fill histograms with boolean values in python. In previous versions of ROOT (e.g. 6.26) I have been able to successfully fill python True and Falses into TH1D’s with ROOT handling the type-casting. This is no longer the case in 6.32

The following is the most basic version of code that used to work in 6.26, and no longer works in 6.32

```auto
import ROOT
h = ROOT.TH1D("test", "test", 10, 0, 10)
h.Fill(True)

```

in ROOT 6.32 I now get the following error:

```auto
TypeError: none of the 3 overloaded methods succeeded. Full details:
  int TH1::Fill(Double_t x) =>
    TypeError: could not convert argument 1

```

Is this functionality that was removed, or is this potentially another unexpected change due to the changes in cppyy?

_ROOT Version:_ 6.32.02  
_Platform:_ macOS Sonoma

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [August 2, 2024, 6:22am UTC](https://root-forum.cern.ch/t/error-when-filling-histogram-with-boolean-in-python/60398/2 "2024-08-02T06:22:14Z")

</div>

Welcome to the RROOT Forum!  
Let’s ask @vpadulan or @jonas

---

<div class="post-metadata">

**Author:** ![jonas](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jonas/32/24756_2.png) [@jonas](https://root-forum.cern.ch/u/jonas)\
**Post date:** [August 2, 2024, 6:47am UTC](https://root-forum.cern.ch/t/error-when-filling-histogram-with-boolean-in-python/60398/3 "2024-08-02T06:47:33Z")

</div>

That was probably intentional by the cppyy developers. The new cppyy became a bit stricter with types in order to reduce the margin for user error.

Would it be a solution to make the type conversion explicit? E.g. `Fill(float(True))`?

There could be other changes with the cppyy upgrade, but you will know where they are because your code will just stop working like in this case.

If you think the explicit casting is too much to ask and the old behavior should be recovered, please open a [GitHub issue](https://github.com/root-project/root/issues) about this.

Cheers,  
Jonas

---

<div class="post-metadata">

**Author:** ![meowz](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/dc4da7/32.png) [@meowz](https://root-forum.cern.ch/u/meowz)\
**Post date:** [August 5, 2024, 2:01am UTC](https://root-forum.cern.ch/t/error-when-filling-histogram-with-boolean-in-python/60398/4 "2024-08-05T02:01:26Z")

</div>

Thanks so much, Jonas!

We’re happy to explicitly type-cast to a float here. Thank you for clarifying the situation with cppyy.

Cheers,  
Mike

---

<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:** [August 19, 2024, 2:02am UTC](https://root-forum.cern.ch/t/error-when-filling-histogram-with-boolean-in-python/60398/5 "2024-08-19T02:02:03Z")

</div>

Closed on August 19, 2024, 2:02am UTC

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