@@ -1126,6 +1126,7 @@ def keys(
11261126 filter_branch = no_filter ,
11271127 recursive = True ,
11281128 full_paths = True ,
1129+ ignore_duplicates = False ,
11291130 ):
11301131 """
11311132 Args:
@@ -1143,6 +1144,7 @@ def keys(
11431144 full_paths (bool): If True, include the full path to each subbranch
11441145 with slashes (``/``); otherwise, use the descendant's name as
11451146 the output name.
1147+ ignore_duplicates (bool): If True, return a set of the keys; otherwise, return the full list of keys.
11461148
11471149 Returns the names of the subbranches as a list of strings.
11481150 """
@@ -1153,6 +1155,7 @@ def keys(
11531155 filter_branch = filter_branch ,
11541156 recursive = recursive ,
11551157 full_paths = full_paths ,
1158+ ignore_duplicates = ignore_duplicates ,
11561159 )
11571160 )
11581161
@@ -1279,6 +1282,7 @@ def iterkeys(
12791282 filter_branch = no_filter ,
12801283 recursive = True ,
12811284 full_paths = True ,
1285+ ignore_duplicates = False ,
12821286 ):
12831287 """
12841288 Args:
@@ -1296,6 +1300,8 @@ def iterkeys(
12961300 full_paths (bool): If True, include the full path to each subbranch
12971301 with slashes (``/``); otherwise, use the descendant's name as
12981302 the output name.
1303+ ignore_duplicates (bool): If True, return a set of the keys; otherwise, return the full list of keys.
1304+
12991305
13001306 Returns the names of the subbranches as an iterator over strings.
13011307 """
@@ -1305,6 +1311,7 @@ def iterkeys(
13051311 filter_branch = filter_branch ,
13061312 recursive = recursive ,
13071313 full_paths = full_paths ,
1314+ ignore_duplicates = ignore_duplicates ,
13081315 ):
13091316 yield k
13101317
@@ -1353,6 +1360,7 @@ def iteritems(
13531360 filter_branch = no_filter ,
13541361 recursive = True ,
13551362 full_paths = True ,
1363+ ignore_duplicates = False ,
13561364 ):
13571365 """
13581366 Args:
@@ -1370,6 +1378,8 @@ def iteritems(
13701378 full_paths (bool): If True, include the full path to each subbranch
13711379 with slashes (``/``) in the name; otherwise, use the descendant's
13721380 name as the name without modification.
1381+ ignore_duplicates (bool): If True, return a set of the keys; otherwise, return the full list of keys.
1382+
13731383
13741384 Returns (name, branch) pairs of the subbranches as an iterator over
13751385 2-tuples of (str, :doc:`uproot.behaviors.TBranch.TBranch`).
@@ -1385,6 +1395,8 @@ def iteritems(
13851395 f"filter_branch must be None or a function: TBranch -> bool, not { filter_branch !r} "
13861396 )
13871397
1398+ keys_set = set ()
1399+
13881400 for branch in self .branches :
13891401 if (
13901402 (
@@ -1394,7 +1406,11 @@ def iteritems(
13941406 and (filter_typename is no_filter or filter_typename (branch .typename ))
13951407 and (filter_branch is no_filter or filter_branch (branch ))
13961408 ):
1397- yield branch .name , branch
1409+ if ignore_duplicates and branch .name in keys_set :
1410+ pass
1411+ else :
1412+ keys_set .add (branch .name )
1413+ yield branch .name , branch
13981414
13991415 if recursive :
14001416 for k1 , v in branch .iteritems (
@@ -1408,7 +1424,11 @@ def iteritems(
14081424 if filter_name is no_filter or _filter_name_deep (
14091425 filter_name , self , v
14101426 ):
1411- yield k2 , v
1427+ if ignore_duplicates and branch .name in keys_set :
1428+ pass
1429+ else :
1430+ keys_set .add (k2 )
1431+ yield k2 , v
14121432
14131433 def itertypenames (
14141434 self ,
0 commit comments