Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def type(self):
return awkward.type.ArrayType(len(self), awkward.type._resolve(self._gettype({}), {}))
def _fromarray(array, seen):
if id(array) not in seen:
seen[id(array)] = placeholder = Placeholder()
if isinstance(array, numpy.ndarray):
if array.dtype.names is None:
out = array.dtype
else:
out = TableType.__new__(TableType)
out._fields = OrderedDict()
for n in array.dtype.names:
out[n] = array.dtype[n]
for x in array.shape[:0:-1]:
out = ArrayType(x, out)
if isinstance(array, numpy.ma.MaskedArray):
out = OptionType(out)
placeholder.value = out
else:
placeholder.value = array._gettype(seen)
return seen[id(array)]
def _gettype(self, seen):
out = awkward.type.UnionType()
for x in self._contents:
out.append(awkward.type._fromarray(x, seen))
for x in self._tags.shape[:0:-1]:
out = awkward.type.ArrayType(x, out)
return out
def _finalize(self, name, events):
parent_type = awkward.type.ArrayType(float('inf'), awkward.type.OptionType(self.type.to.to))
parent_type.check = False # break recursion
gen_parent = type(self)(
self._lazy_crossref,
args=(self._getcolumn('genPartIdxMother'), self),
type=parent_type,
)
gen_parent.__doc__ = self.__doc__
self['parent'] = gen_parent
if self.enable_children:
child_type = awkward.type.ArrayType(float('inf'), float('inf'), self.type.to.to)
child_type.check = False
children = type(self)(
self._lazy_findchildren,
args=(self._getcolumn('genPartIdxMother'),),
type=child_type,
)
children.__doc__ = self.__doc__
self['children'] = children
self.type.check = False
del self['genPartIdxMother']
def virtual(self, name: str, cache: MutableMapping = None):
col = self._columns[name]
dtype = numpy.dtype(col["dtype"])
if col["dimension"] == 2:
virtualtype = awkward.type.ArrayType(float("inf"), dtype)
elif col["dimension"] == 1:
virtualtype = awkward.type.ArrayType(
self._partition["stop"] - self._partition["start"], dtype
)
else:
raise NotImplementedError
return awkward.VirtualArray(
self.__getitem__,
(name,),
{},
type=virtualtype,
persistentkey=self._key(col),
cache=cache,
)
elif isinstance(tpe, pyarrow.lib.StructType):
out = None
for i in range(tpe.num_children):
x = awkward.type.ArrayType(tpe[i].name, recurse(tpe[i].type, tpe[i].nullable))
if out is None:
out = x
else:
out = out & x
if nullable:
return awkward.type.OptionType(out)
else:
return out
elif isinstance(tpe, pyarrow.lib.ListType):
out = awkward.type.ArrayType(float("inf"), recurse(tpe.value_type, nullable))
if nullable:
return awkward.type.OptionType(out)
else:
return out
elif isinstance(tpe, pyarrow.lib.UnionType):
out = None
for i in range(tpe.num_children):
x = recurse(tpe[i].type, nullable)
if out is None:
out = x
else:
out = out | x
if nullable:
return awkward.type.OptionType(out)
else:
else:
return out
elif isinstance(tpe, pyarrow.lib.DataType):
if nullable:
return awkward.type.OptionType(tpe.to_pandas_dtype())
else:
return tpe.to_pandas_dtype()
else:
raise NotImplementedError(repr(tpe))
out = None
for name in schema.names:
field = schema.field_by_name(name)
mytype = awkward.type.ArrayType(name, recurse(field.type, field.nullable))
if out is None:
out = mytype
else:
out = out & mytype
return out
def type(self):
return awkward.type.ArrayType(*(self._starts.shape + (self._length,) + awkward.type.fromarray(self._content).to))
def _gettype(self, seen):
return awkward.type.ArrayType(*(self._starts.shape[1:] + (self.numpy.inf, awkward.type._fromarray(self._content, seen))))