Error when filling histogram with boolean in python

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

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

in ROOT 6.32 I now get the following error:

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

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

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 about this.

Cheers,
Jonas

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

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