Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: https://root-forum.cern.ch/t/wrong-branch-type-detection/59236/25 #1207

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/uproot/writing/_cascadetree.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,11 @@ def _branch_np(
if letter is None:
raise TypeError(f"cannot write NumPy dtype {branch_dtype} in TTree")

if branch_shape == ():
dims = ""
else:
dims = "".join("[" + str(x) + "]" for x in branch_shape)
dims = ""
if counter is not None:
dims = "[" + counter["fName"] + "]"
if len(branch_shape) > 0:
dims = dims + "".join("[" + str(x) + "]" for x in branch_shape)

title = f"{branch_name}{dims}/{letter}"

Expand Down
21 changes: 21 additions & 0 deletions tests/test_1207_fix_title_of_TBranch_with_counter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE

import os

import awkward as ak

import uproot


def test(tmp_path):
filename = os.path.join(tmp_path, "file.root")

with uproot.recreate(filename) as file:
file["tree"] = {"branch": ak.Array([[1.1, 2.2, 3.3], [], [4.4, 5.5]])}

with uproot.open(filename) as file:
assert file["tree"]["branch"].title == "branch[nbranch]/D"
assert (
file["tree"]["branch"].member("fLeaves")[0].member("fTitle")
== "branch[nbranch]"
)