Skip to content

Commit 2492876

Browse files
authored
feat: warn about TBranch name, alias name conflict. (#776)
1 parent f701c24 commit 2492876

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/uproot/exceptions.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
:doc:`uproot.exceptions.KeyInFileError`.
66
"""
77

8-
98
import uproot
109

1110

11+
class NameConflictWarning(Warning):
12+
pass
13+
14+
1215
class KeyInFileError(KeyError):
1316
"""
1417
Exception raised by attempts to find ROOT objects in ``TDirectories``

src/uproot/language/python.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
import ast
13+
import warnings
1314

1415
import numpy
1516

@@ -402,16 +403,27 @@ def compute_expressions(
402403
arrays (dict of arrays): Inputs to the computation.
403404
expression_context (list of (str, dict) tuples): Expression strings
404405
and a dict of metadata about each.
405-
keys (list of str): Names of branches or aliases (for aliases that
406+
keys (set of str): Names of branches or aliases (for aliases that
406407
refer to aliases).
407-
aliases (list of str): Names of aliases.
408+
aliases (dict of str \u2192 str): Names of aliases and their definitions.
408409
file_path (str): File path for error messages.
409410
object_path (str): Object path for error messages.
410411
411412
Computes an array for each expression.
412413
"""
413414
values = {}
414415

416+
if len(aliases) < len(keys):
417+
shorter, longer = aliases, keys
418+
else:
419+
shorter, longer = keys, aliases
420+
for x in shorter:
421+
if x in longer:
422+
warnings.warn(
423+
f"{x!r} is both an alias and a branch name",
424+
uproot.exceptions.NameConflictWarning,
425+
)
426+
415427
def getter(name):
416428
if name not in values:
417429
values[name] = _expression_to_function(

0 commit comments

Comments
 (0)