Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _chain(self, sourcenames, compiledintermediates, entryvars, aliases, interpretations, entryvar, entrysteps, entrystart, entrystop, cache, basketcache, keycache, readexecutor, numba):
branches = uproot.tree.OrderedDict()
for branchname in sourcenames:
if branchname in interpretations:
branches[branchname] = interpretations[branchname]
else:
branches[branchname] = uproot.interp.auto.interpret(self.tree[branchname])
waits = list(self.tree.iterate(branches=branches, entrysteps=entrysteps, outputtype=list, reportentries=True, entrystart=entrystart, entrystop=entrystop, cache=cache, basketcache=basketcache, keycache=keycache, executor=readexecutor, blocking=False))
def calculate(start, stop, wait):
numentries = stop - start
arrays = wait()
for i in range(len(compiledintermediates)):
arrays.append(numpy.empty(numentries, dtype=self.NEW_ARRAY_DTYPE))
if len(entryvars) > 0:
arrays.append(numpy.arange(start, stop))
return start, stop, numentries, tuple(arrays)
def wrap_for_python_scope(start, stop, wait):
flats = []
lists = OrderedDict()
for name, branch in parent.items():
if len(branch.fLeaves) == 1 and branch.fLeaves[0].fLeafCount is not None:
leafcount = branch.fLeaves[0].fLeafCount
if leafcount not in lists:
lists[leafcount] = []
lists[leafcount].append((name, branch))
else:
flats.append((name, branch))
out = oamap.schema.Record({})
for name, branch in flats:
x = frominterp(name, branch, uproot.interp.auto.interpret(branch))
if x is not None:
out[name.split(".")[-1]] = x
for leafcount, namebranches in lists.items():
rec = oamap.schema.Record({})
for name, branch in namebranches:
x = frominterp(name, branch, uproot.interp.auto.interpret(branch))
if x is not None:
assert isinstance(x, oamap.schema.List)
rec[name.split(".")[-1]] = x.content
found = False
for branchname, branch in self.tree.allitems():
if branch.fLeaves == [leafcount]:
found = True
break
def wrapped_interpret(branch, *args, **kwargs):
from uproot.interp.auto import interpret
result = interpret(branch, *args, **kwargs)
if result:
return result
if isinstance(branch, WrappedTree.FakeBranch):
if isinstance(branch._values, awkward.JaggedArray):
return asjagged(asdtype(branch._values.content.dtype.fields))
else:
return branch._values
return None
def _normalize_branches(self, arg, awkward, allownone=True, allowcallable=True, allowdict=True, allowstring=True, aliases=True):
if allownone and arg is None: # no specification; read all branches
for branch in self.allvalues(): # that have interpretations
interpretation = interpret(branch, awkward)
if interpretation is not None:
yield branch, interpretation
elif allowcallable and callable(arg):
for branch in self.allvalues():
result = arg(branch)
if result is None or result is False:
pass
elif result is True: # function is a filter
interpretation = interpret(branch, awkward)
if interpretation is not None:
yield branch, interpretation
else: # function is giving interpretations
yield branch, branch._normalize_dtype(result, awkward)
elif allowdict and isinstance(arg, dict):
for word, interpretation in arg.items():
word = _bytesid(word)
isregex = re.match(self._branch_regex, word)
if isregex is not None:
regex, flags = isregex.groups()
for name, branch in self.iteritems(recursive=True, aliases=aliases):
if re.match(regex, name, self._branch_flags(flags)):
yield branch, branch._normalize_dtype(interpretation, awkward)
def _normalize_dtype(self, interpretation, awkward):
if inspect.isclass(interpretation) and issubclass(interpretation, awkward.numpy.generic):
return self._normalize_dtype(awkward.numpy.dtype(interpretation), awkward)
elif isinstance(interpretation, awkward.numpy.dtype): # user specified a Numpy dtype
default = interpret(self, awkward)
if isinstance(default, (asdtype, asjagged)):
return default.to(interpretation)
else:
raise ValueError("cannot cast branch {0} (default interpretation {1}) as dtype {2}".format(repr(self.name), default, interpretation))
elif isinstance(interpretation, awkward.numpy.ndarray): # user specified a Numpy array
default = interpret(self, awkward)
if isinstance(default, asdtype):
return default.toarray(interpretation)
else:
raise ValueError("cannot cast branch {0} (default interpretation {1}) as dtype {2}".format(repr(self.name), default, interpretation))
elif not isinstance(interpretation, uproot.interp.interp.Interpretation):
raise TypeError("branch interpretation must be an Interpretation, not {0} (type {1})".format(interpretation, type(interpretation)))
else:
return interpretation
def _normalize_interpretation(self, interpretation, awkward):
if interpretation is None:
interpretation = interpret(self, awkward)
else:
interpretation = self._normalize_dtype(interpretation, awkward)
if interpretation is None:
raise ValueError("cannot interpret branch {0} as a Python type\n in file: {1}".format(repr(self.name), self._context.sourcepath))
if interpretation.awkward is not awkward:
interpretation = interpretation.awkwardlib(awkward)
return interpretation