Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _concatenate_axis1(cls, arrays):
assert all(isinstance(x, VirtualArray) for x in arrays)
return awkward.array.base.AwkwardArray.concatenate([x.array for x in arrays], axis=1)
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("SparseSeries", self)
if isinstance(self._content, awkward.array.base.AwkwardArray):
out._content = out._content._util_pandas(seen)
return out
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import awkward.array.base
class SparseArray(awkward.array.base.AwkwardArrayWithContent):
def __init__(self, length, coordinates, content):
self.length = length
self.coordinates = coordinates
self.content = content
@classmethod
def fromCOO(cls, length, coordinates, content, default=0):
content = awkward.util.toarray(content, awkward.util.DEFAULTTYPE)
if isinstance(content, awkward.util.numpy.ndarray):
content = awkward.util.numpy.insert(content, 0, default)
else:
# FIXME: maybe something with an IndexedArray of ChunkedArrays?
raise NotImplementedError(type(content))
return cls(length, coordinates, content)
def copy(self, index=None, content=None):
if isinstance(result, tuple):
if out is None:
out = list(result)
for i, x in enumerate(result):
if isinstance(x, (self.numpy.ndarray, awkward.array.base.AwkwardArray)):
if i not in contents:
contents[i] = []
contents[i].append(x)
types[i] = type(x)
elif method == "at":
pass
else:
if isinstance(result, (self.numpy.ndarray, awkward.array.base.AwkwardArray)):
if None not in contents:
contents[None] = []
contents[None].append(result)
types[None] = type(result)
if out is None:
if None in contents:
return self.Methods.maybemixin(types[None], UnionArray)(outtags, outindex, contents[None])
else:
return None
else:
for i in range(len(out)):
if i in contents:
out[i] = self.Methods.maybemixin(types[i], UnionArray)(outtags, outindex, contents[i])
return tuple(out)
import numbers
import numpy
from pandas.api.extensions import ExtensionDtype
from .accessor import DelegatedMethod, DelegatedProperty, delegated_method
import awkward.persist
import awkward.type
import awkward.array as awkarr
class AwkwardType(ExtensionDtype):
name = 'awkward'
type = awkarr.base.AwkwardArray
kind = 'O'
@classmethod
def construct_from_string(cls, string):
if string == cls.name:
return cls()
else:
raise TypeError("Cannot construct a '{}' from"
"'{}'".format(cls, string))
# -----------------------------------------------------------------------------
# Pandas accessors
# -----------------------------------------------------------------------------
@pd.api.extensions.register_series_accessor("awkward")
class AwkwardAccessor:
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
return self._content[self._index]
else:
return self._content._prepare(identity, dtype)[self._index]
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("IndexedSeries", self)
if isinstance(self._content, awkward.array.base.AwkwardArray):
out._content = out._content._util_pandas(seen)
return out
class SparseArray(awkward.array.base.AwkwardArrayWithContent):
"""
SparseArray
"""
# TODO for 1.0: replace length with an indexshape
def __init__(self, length, index, content, default=None):
self.length = length
self.index = index
self.content = content
self.default = default
def copy(self, length=None, index=None, content=None, default=None):
out = self.__class__.__new__(self.__class__)
out._length = self._length
out._index = self._index
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("IndexedSeries", self)
if isinstance(self._content, awkward.array.base.AwkwardArray):
out._content = out._content._util_pandas(seen)
return out
import functools
import math
import numbers
import operator
from collections import OrderedDict
try:
from collections.abc import Iterable
except ImportError:
from collections import Iterable
import awkward.array.base
import awkward.persist
import awkward.type
import awkward.util
class JaggedArray(awkward.array.base.AwkwardArrayWithContent):
"""
JaggedArray
"""
@classmethod
def offsetsaliased(cls, starts, stops):
return (isinstance(starts, cls.numpy.ndarray) and isinstance(stops, cls.numpy.ndarray) and
starts.base is not None and stops.base is not None and starts.base is stops.base and
starts.ctypes.data == starts.base.ctypes.data and
stops.ctypes.data == stops.base.ctypes.data + stops.dtype.itemsize and
len(starts) == len(starts.base) - 1 and
len(stops) == len(stops.base) - 1)
@classmethod
def counts2offsets(cls, counts):
offsets = cls.numpy.empty(len(counts) + 1, dtype=cls.JaggedArray.fget(None).INDEXTYPE)
if isinstance(result, tuple):
if out is None:
out = list(result)
for i, x in enumerate(result):
if isinstance(x, (self.numpy.ndarray, awkward.array.base.AwkwardArray)):
if i not in contents:
contents[i] = []
contents[i].append(x)
types[i] = type(x)
elif method == "at":
pass
else:
if isinstance(result, (self.numpy.ndarray, awkward.array.base.AwkwardArray)):
if None not in contents:
contents[None] = []
contents[None].append(result)
types[None] = type(result)
if out is None:
if None in contents:
return self.Methods.maybemixin(types[None], UnionArray)(outtags, outindex, contents[None])
else:
return None
else:
for i in range(len(out)):
if i in contents:
out[i] = self.Methods.maybemixin(types[i], UnionArray)(outtags, outindex, contents[i])
return tuple(out)