Skip to content

Missing numpy.uint8 pythonisation in SetBranchAddress in ROOT 6.38 #21379

@dpiparo

Description

@dpiparo

Check duplicate issues.

  • Checked for duplicates

Description

(from this post on the Forum)

In my code I had the following part:

self.pcd = np.zeros((X, Y, A, B), dtype=np.uint8)
self.tree_chain.SetBranchAddress("photon_count_data", self.pcd)

where photon_count_data is photon_count_data[1][1][48][48]/b

It used to work in older ROOT versions (6.30 I think), but now I get an error:

  File "/home/lewhoo/workspace/etos/eusottrees/datatree.py", line 1652, in set_physical_tree
    self.tree_chain.SetBranchAddress("photon_count_data", self.pcd)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lewhoo/software/root/root-6.38.00/lib/ROOT/_pythonization/_ttree.py", line 266, in _SetBranchAddress
    data_type = _determine_data_type(addr)
  File "/home/lewhoo/software/root/root-6.38.00/lib/ROOT/_pythonization/_ttree.py", line 233, in _determine_data_type
    return _get_cpp_type_from_numpy_type(addr.__array_interface__["typestr"][1:])
  File "/home/lewhoo/software/root/root-6.38.00/lib/ROOT/_pythonization/_rvec.py", line 149, in _get_cpp_type_from_numpy_type
    raise RuntimeError("Object not convertible: Python object has unknown data-type '" + dtype + "'.")
RuntimeError: Object not convertible: Python object has unknown data-type 'u1'.

The workaround (suggested by Gemini 😉 ) is to use GetBranch(“…”).SetAddress(…) and this works. However, it seems that proper conversion from numpy array uint8 to C++ unsigned char is missing.

Reproducer

See above

ROOT version

6.38 onwards

Installation method

all

Operating system

all

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions