Misleading error message and silent failure with new ROOT 6.22

The new version of root breaks a few things with strings when the python interface is used. Principally, when using python to do something like this, with say RDataFrame:

for x in dataframe.GetColumnNames():
  if "Jet_" in x:

it will ‘silently fail,’ because the iterable returned now is of type “<class cppyy.gbl.std.string at 0x7504dd0>”. This is probably worse than the other place where this crops up in my own code, which is when constructing a TChain using filenames stored in a ROOT.std.vector. Upon calling .Add(filename), it fails with

TypeError: 'none of the 2 overloaded methods succeeded. Full details:
  int TChain::Add(TChain* chain) =>
 ... =>
    TypeError: could not convert argument 1 (expected string or Unicode object, string found)'

Which is a rather annoying failure message.

The workaround is to call str() on the iterable, but I don’t know if the current behavior is really ideal or acknowledged as a necessary tradeoff, so I’m reporting it here.


ROOT Version: 6.22/00
Platform: CentOS 7
Compiler: gcc800
Software Stack: LCG_98


Yes, this is indeed a backwards-incompatible change, it’s documented here"

(last one)

When iterating over an std::vector of std::string, cppyy now applies an optimization and returns the elements as std::strings, instead of copying them into Python strings by default, as happened before. Unfortunately, if those elements need to be used later as Python strings or used in a conversion that is allowed for Python string (but not for std::string), they need to turned into Python strings first with str() as you pointed out.

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