diana-hep / oamap

Perform high-speed calculations on columnar data without creating intermediate objects.
BSD 3-Clause "New" or "Revised" License
81 stars 11 forks source link

TypeError: data must be None or an array name (string), not b'NJet' #4

Closed jyn514 closed 6 years ago

jyn514 commented 6 years ago

Ran into this while doing the problems for GSOC. I think the problem is that the library is not compatible with Python3 unicode strings, but I may be wrong.

Traceback

>>> import oamap.source.root, uproot, functional
>>> events = uproot.open("http://scikit-hep.org/uproot/examples/HZZ.root")["events"].oamap() 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/joshua/.local/lib/python3.6/site-packages/oamap/source/root.py", line 187, in __call__
    generator = self.schema.generator()
  File "/home/joshua/.local/lib/python3.6/site-packages/oamap/source/root.py", line 184, in schema
    return oamap.schema.List(recurse(self.tree), starts="", stops="")
  File "/home/joshua/.local/lib/python3.6/site-packages/oamap/source/root.py", line 138, in recurse
    x = frominterp(name, branch, uproot.interp.auto.interpret(branch))
  File "/home/joshua/.local/lib/python3.6/site-packages/oamap/source/root.py", line 100, in frominterp
    return oamap.schema.Primitive(interpretation.todtype, data=name)
  File "/home/joshua/.local/lib/python3.6/site-packages/oamap/schema.py", line 346, in __init__
    self.data = data
  File "/home/joshua/.local/lib/python3.6/site-packages/oamap/schema.py", line 418, in data
    raise TypeError("data must be None or an array name (string), not {0}".format(repr(value)))
TypeError: data must be None or an array name (string), not b'NJet'
jpivarski commented 6 years ago

That's right. Another GSoC student ran into the same thing. uproot branch names are bytes (because ROOT files have no encoding) and OAMap hasn't been made aware of that.

It is a real bug, but for now just use Python 2. (Sorry!)

jyn514 commented 6 years ago

Tried changing basestring = str to basestring = (bytes, str), but then I got TypeError: a bytes-like object is required, not 'str'. Going to run if isinstance(input, str): str = input.encode() on all the relevant functions to keep python3 compat.

jpivarski commented 6 years ago

No longer relevant; that part of the code is gone and will be rewritten (with better Python 3 hygene in mind!).