How to use the awkward.array.jagged function in awkward

To help you get started, we’ve selected a few awkward examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scikit-hep / awkward-array / awkward / array / indexed.py View on Github external
def default(self):
        import awkward.array.jagged

        if self._default is None:
            if isinstance(self._content, awkward.array.jagged.JaggedArray):
                return self.JaggedArray([0], [0], self._content.content)
            elif self._content.shape[1:] == ():
                return self._content.dtype.type(0)
            else:
                return self.numpy.zeros(self._content.shape[1:], dtype=self._content.dtype)

        else:
            return self._default

        self._isvalid = False
github scikit-hep / uproot / uproot / interp / jagged.py View on Github external
# 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 math

import awkward.type
import awkward.util
import awkward.array.jagged

import uproot.interp.interp
import uproot.interp.numerical

class JaggedArray(awkward.array.jagged.JaggedArray):
    class _Prep(object):
        def __init__(self, counts, content):
            self.counts = counts
            self.content = content

def _destructive_divide(array, divisor):
    if divisor == 1:
        pass
    elif divisor == 2:
        awkward.util.numpy.right_shift(array, 1, out=array)
    elif divisor == 4:
        awkward.util.numpy.right_shift(array, 2, out=array)
    elif divisor == 8:
        awkward.util.numpy.right_shift(array, 3, out=array)
    else:
        awkward.util.numpy.floor_divide(array, divisor, out=array)
github scikit-hep / awkward-array / awkward / pandas / array / jagged.py View on Github external
#!/usr/bin/env python

# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-array/blob/master/LICENSE

import numpy

import awkward.array.jagged
from pandas.api.extensions import ExtensionArray
from awkward.pandas.accessor import AwkwardType

class JaggedArrayPandas(awkward.array.jagged.JaggedArray, ExtensionArray):

    @property
    def dtype(self):
        return AwkwardType()

    def __array__(self, dtype=None):
        return numpy.array(self.tolist(), dtype='object')
github scikit-hep / awkward-array / awkward / array / base.py View on Github external
def JaggedArray(self):
        import awkward.array.jagged
        return awkward.array.jagged.JaggedArray
github scikit-hep / uproot-methods / uproot_methods / classes / TLorentzVector.py View on Github external
def __init__(self, x, y, z, t):
        if isinstance(x, awkward.array.jagged.JaggedArray) or isinstance(y, awkward.array.jagged.JaggedArray) or isinstance(z, awkward.array.jagged.JaggedArray) or isinstance(t, awkward.array.jagged.JaggedArray):
            raise TypeError("TLorentzVectorArray constructor arguments must not be jagged; use TLorentzVectorArray.from_cartesian for jaggedness-handling")
        self._initObjectArray(self.awkward.Table())
        self["fX"] = x
        self["fY"] = y
        self["fZ"] = z
        self["fE"] = t
github scikit-hep / uproot-methods / uproot_methods / classes / TVector3.py View on Github external
def __init__(self, x, y, z):
        if isinstance(x, awkward.array.jagged.JaggedArray) or isinstance(y, awkward.array.jagged.JaggedArray) or isinstance(z, awkward.array.jagged.JaggedArray):
            raise TypeError("TVector3Array constructor arguments must not be jagged; use TVector3.from_cartesian for jaggedness-handling")
        self._initObjectArray(self.awkward.Table())
        self["fX"] = x
        self["fY"] = y
        self["fZ"] = z
github scikit-hep / awkward-array / awkward / derived / strings.py View on Github external
elif isinstance(left, awkward.util.numpy.ndarray) and left.dtype == awkward.util.numpy.dtype(object):
                left = StringArray.fromiter(left)
            elif not isinstance(left, StringMethods):
                return awkward.util.numpy.zeros(len(right), dtype=awkward.util.BOOLTYPE)

            if isinstance(right, (str, bytes)):
                right = StringArray.fromstr(len(left), right)
            elif isinstance(right, awkward.util.numpy.ndarray) and (right.dtype.kind == "U" or right.dtype.kind == "S"):
                right = StringArray.fromnumpy(right)
            elif isinstance(right, awkward.util.numpy.ndarray) and right.dtype == awkward.util.numpy.dtype(object):
                right = StringArray.fromiter(right)
            elif not isinstance(right, StringMethods):
                return awkward.util.numpy.zeros(len(left), dtype=awkward.util.BOOLTYPE)

            left = awkward.array.jagged.JaggedArray(left.starts, left.stops, left.content)
            right = awkward.array.jagged.JaggedArray(right.starts, right.stops, right.content)

            maybeequal = (left.counts == right.counts)

            leftmask = left[maybeequal]
            rightmask = right[maybeequal]

            reallyequal = (leftmask == rightmask).count_nonzero() == leftmask.counts

            out = awkward.util.numpy.zeros(len(left), dtype=awkward.util.BOOLTYPE)
            out[maybeequal] = reallyequal

            if ufunc is awkward.util.numpy.equal:
                return out
            else:
                return awkward.util.numpy.logical_not(out)
github scikit-hep / awkward-array / impl_flatpandas.py View on Github external
tmp = array[n]

                elif isinstance(tpen, type) and issubclass(tpen, (str, bytes)):
                    columns.append(colsn)
                    tmp = array[n]

                elif isinstance(tpen, awkward.type.ArrayType) and tpen.takes == numpy.inf:
                    tmp = JaggedArray(array[n].starts, array[n].stops, recurse(array[n].content, tpen.to, colsn, True))

                elif isinstance(tpen, awkward.type.TableType):
                    tmp = recurse(array[n], tpen, colsn, True)

                else:
                    raise ValueError("this array has unflattenable substructure:\n\n{0}".format(str(tpen)))

                if isinstance(tmp, awkward.array.jagged.JaggedArray):
                    if isinstance(tmp.content, awkward.array.jagged.JaggedArray):
                        unflattened = tmp
                        tmp = tmp.flatten(axis=1)

                    if starts is None:
                        starts, stops = tmp.starts, tmp.stops
                    elif not numpy.array_equal(starts, tmp.starts) or not numpy.array_equal(stops, tmp.stops):
                        raise ValueError("this array has more than one jagged array structure")
                    if out is None:
                        out = JaggedArray(starts, stops, Table({n: tmp.content}))
                    else:
                        out[n] = tmp

                else:
                    deferred[n] = tmp
github scikit-hep / awkward-array / awkward / util.py View on Github external
def unwrap(a):
        if isinstance(a, awkward.array.chunked.ChunkedArray):
            chunks = [unwrap(x) for x in a.chunks]
            if any(isinstance(x, awkward.array.jagged.JaggedArray) for x in chunks):
                return awkward.array.jagged.JaggedArray.concatenate(chunks)
            else:
                return numpy.concatenate([x.regular() for x in chunks])
        elif isinstance(a, awkward.array.virtual.VirtualArray):
            return a.array
        else:
            return a