Skip to content

Commit c94a38f

Browse files
authored
fix: avoid misinterpreting counter branch as dimension (#1521)
* Fix misinterpreting counter branch as dimension * Fixed logic to check for consistency of leaf dimensions * Pick the common dimensions among leaves
1 parent 2bd58b6 commit c94a38f

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

src/uproot/interpretation/identify.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,16 @@ def _leaf_to_dtype(leaf, getdims):
141141
_item_any_pattern = re.compile(r"(\[.*\])")
142142

143143

144-
def _from_leaves_one(leaf, title):
144+
def _from_leaves_one(leaf, title, count_branch_name):
145145
dims, is_jagged = (), False
146146

147147
m = _title_has_dims.match(title)
148148
if m is not None:
149-
dims = tuple(int(x) for x in re.findall(_item_dim_pattern, title))
149+
dims = tuple(
150+
int(x)
151+
for x in re.findall(_item_dim_pattern, title)
152+
if x != count_branch_name
153+
)
150154
if dims == () and leaf.member("fLen") > 1:
151155
dims = (leaf.member("fLen"),)
152156

@@ -170,22 +174,40 @@ def _from_leaves(branch, context):
170174
elif len(branch.member("fLeaves")) == 1:
171175
leaf = branch.member("fLeaves")[0]
172176
title = leaf.member("fTitle")
173-
return _from_leaves_one(leaf, title)
177+
count_branch_name = (
178+
branch.count_branch.name if branch.count_branch is not None else ""
179+
)
180+
return _from_leaves_one(leaf, title, count_branch_name)
174181

175182
else:
176183
first = True
184+
count_branch_name = (
185+
branch.count_branch.name if branch.count_branch is not None else ""
186+
)
177187
for leaf in branch.member("fLeaves"):
178188
title = leaf.member("fTitle")
179189
if first:
180-
dims, is_jagged = _from_leaves_one(leaf, title)
190+
dims, is_jagged = _from_leaves_one(leaf, title, count_branch_name)
191+
first = False
181192
else:
182-
trial_dims, trial_is_jagged = _from_leaves_one(leaf, title)
183-
if dims != trial_dims or is_jagged != trial_is_jagged:
193+
trial_dims, trial_is_jagged = _from_leaves_one(
194+
leaf, title, count_branch_name
195+
)
196+
if is_jagged != trial_is_jagged:
184197
raise UnknownInterpretation(
185-
"leaf-list with different dimensions among the leaves",
198+
"leaf-list with different jaggedness among the leaves",
186199
branch.file.file_path,
187200
branch.object_path,
188201
)
202+
if dims != trial_dims:
203+
# pick the common dimensions
204+
i = 0
205+
for d1, d2 in zip(dims, trial_dims):
206+
if d1 == d2:
207+
i += 1
208+
else:
209+
break
210+
dims = dims[:i]
189211
return dims, is_jagged
190212

191213

0 commit comments

Comments
 (0)