Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if self._cache is not None and isinstance(self._array, VirtualArray.TransientKey):
try:
del self._cache[self._array]
except:
pass
def __len__(self):
return self.shape[0]
def __getitem__(self, where):
return self.array[where]
def __setitem__(self, where, what):
raise ValueError("assignment destination is read-only")
class VirtualObjectArray(awkward.array.base.AwkwardArray):
def __init__(self, generator, content):
self.generator = generator
self.content = content
@property
def generator(self):
return self._generator
@generator.setter
def generator(self, value):
if not callable(value):
raise TypeError("generator must be a callable (of one argument: the array slice)")
self._generator = value
@property
def content(self):
def _util_pandas(self, seen):
import awkward.pandas
if id(self) in seen:
return seen[id(self)]
else:
out = seen[id(self)] = self.copy()
out.__class__ = awkward.pandas.mixin("UnionSeries", self)
out._contents = [x._util_pandas(seen) if isinstance(x, awkward.array.base.AwkwardArray) else x for x in out._contents]
return out
def maybemixin(sample, awkwardtype):
if issubclass(sample, Methods):
assert issubclass(sample, awkward.array.base.AwkwardArray)
allbases = tuple(x for x in sample.__bases__ if not issubclass(x, awkward.array.base.AwkwardArray)) + (awkwardtype,)
return type(awkwardtype.__name__ + "Methods", allbases, {})
else:
return awkwardtype
def _util_isstringslice(cls, where):
if isinstance(where, awkward.util.string):
return True
elif isinstance(where, bytes):
raise TypeError("column selection must be str, not bytes, in Python 3")
elif isinstance(where, tuple):
return False
elif isinstance(where, (cls.numpy.ndarray, AwkwardArray)) and issubclass(where.dtype.type, (numpy.str, numpy.str_)):
return True
elif isinstance(where, (cls.numpy.ndarray, AwkwardArray)) and issubclass(where.dtype.type, (numpy.object, numpy.object_)) and not issubclass(where.dtype.type, (numpy.bool, numpy.bool_)):
return len(where) > 0 and all(isinstance(x, awkward.util.string) for x in where)
elif isinstance(where, (cls.numpy.ndarray, AwkwardArray)):
return False
try:
assert len(where) > 0 and all(isinstance(x, awkward.util.string) for x in where)
except (TypeError, AssertionError):
return False
else:
return True
import numbers
import re
import types
from collections import OrderedDict
try:
from collections.abc import Iterable
except ImportError:
from collections import Iterable
import numpy
import awkward.array.base
import awkward.type
import awkward.util
class Table(awkward.array.base.AwkwardArray):
"""
Table
"""
##################### class Row
class Row(awkward.util.NDArrayOperatorsMixin):
"""
Table.Row
"""
__slots__ = ["_table", "_index"]
def __init__(self, table, index):
self._table = table
self._index = index
def _util_arraystr(cls, array):
if isinstance(array, cls.numpy.ndarray):
return cls._util_arraystr_draw(array)
elif isinstance(array, AwkwardArray):
return str(array).replace("\n", "")
else:
return repr(array)
if len(self) <= 6:
return "[{0}]".format(" ".join(repr(x) for x in self))
else:
return "[{0} ... {1}]".format(" ".join(repr(x) for x in self[:3]), ", ".join(repr(x) for x in self[-3:]))
def __getitem__(self, where):
content = self._content[where]
if isinstance(where, (numbers.Integral, numpy.integer)):
return self.generator(content)
else:
return [self.generator(x) for x in content]
def __setitem__(self, where, what):
raise ValueError("assignment destination is read-only")
class PersistentArray(awkward.array.base.AwkwardArray):
def __init__(self, dtype, shape, read, write):
self.dtype = dtype
self.shape = shape
self.read = read
self.write = write
@property
def dtype(self):
return self._dtype
@dtype.setter
def dtype(self, value):
self._dtype = numpy.dtype(value)
@property
def shape(self):
def _util_pandas(self, seen):
import awkward.pandas
if id(self) in seen:
return seen[id(self)]
else:
out = seen[id(self)] = self.copy()
out.__class__ = awkward.pandas.mixin("StringSeries", self)
if isinstance(self._content, awkward.array.base.AwkwardArray):
out._content = out._content._util_pandas(seen)
return out