How to use the awkward.type.TableType 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 / util.py View on Github external
for n in tpe.columns:
                arrayn = unwrap(array[n])
                if isinstance(arrayn, awkward.array.jagged.JaggedArray):
                    if unflattened is None:
                        localindex.insert(0, out[n].localindex.flatten())
                    else:
                        oldloc = unflattened.content.localindex
                        tab = JaggedArray(oldloc.starts, oldloc.stops, Table({"oldloc": oldloc.content}))
                        tab["newloc"] = arrayn.localindex.flatten()
                        localindex.insert(0, tab["newloc"].flatten())
                    break

            return out[tpe.columns]

        else:
            return recurse(Table({"": array}), awkward.type.TableType(**{"": tpe}), cols, False)[""]
github scikit-hep / awkward-array / awkward / array / table.py View on Github external
def _gettype(self, seen):
        out = awkward.type.TableType()
        for n, x in self._contents.items():
            out[n] = awkward.type._fromarray(x, seen)
        return out
github scikit-hep / awkward-array / awkward / type.py View on Github external
def _canonical(x, seen):
        if id(x) not in seen:
            # apply string-integer commutation so that TableTypes are nested as deeply as possible
            if isinstance(x, TableType) and len(x._fields) > 0 and all(isinstance(y, ArrayType) for y in x._fields.values()):
                newtable = TableType.__new__(TableType)
                newtable._fields = OrderedDict()
                first = None
                for n, y in x._fields.items():
                    if first is None:
                        first = y._takes
                    elif first != y._takes or math.isinf(y._takes):
                        break
                    newtable._fields[n] = y._to
                else:
                    x = ArrayType.__new__(ArrayType)
                    x._takes = first
                    x._to = newtable

            # apply union(X, union(Y)) == union(X, Y)
            if isinstance(x, UnionType) and any(isinstance(y, UnionType) for y in x._possibilities):
                possibilities = []
github scikit-hep / awkward-array / impl_flatpandas.py View on Github external
for n in tpe.columns:
                if isinstance(array[n], awkward.array.jagged.JaggedArray):
                    if unflattened is None:
                        localindex.insert(0, out[n].localindex.flatten())
                    else:
                        oldloc = unflattened.content.localindex
                        tab = JaggedArray(oldloc.starts, oldloc.stops, Table({"oldloc": oldloc.content}))
                        tab["newloc"] = array[n].localindex.flatten()
                        localindex.insert(0, tab["newloc"].flatten())
                    break

            return out[tpe.columns]

        else:
            return recurse(Table({"": array}), awkward.type.TableType(**{"": tpe}), cols, False)[""]
github scikit-hep / awkward-array / awkward / type.py View on Github external
def __hash__(self):
        return hash((TableType, tuple((n, self._fields[n]) for n in sorted(self._fields))))
github scikit-hep / awkward-array / awkward / persist.py View on Github external
def recurse(obj):
        if isinstance(obj, awkward.type.Type):
            if id(obj) in seen:
                for i, x in enumerate(labeled):
                    if obj is x:
                        return {"ref": "T{0}".format(i)}

            else:
                seen.add(id(obj))
                if isinstance(obj, awkward.type.ArrayType):
                    out = {"takes": takes(obj._takes), "to": recurse(obj._to)}

                elif isinstance(obj, awkward.type.TableType):
                    out = {"fields": [[n, recurse(x)] for n, x in obj._fields.items()]}

                elif isinstance(obj, awkward.type.UnionType):
                    out = {"possibilities": [recurse(x) for x in obj._possibilities]}

                elif isinstance(obj, awkward.type.OptionType):
                    out = {"type": recurse(obj._type)}

                for i, x in enumerate(labeled):
                    if obj is x:
                        return {"set": "T{0}".format(i), "as": out}
                else:
                    return out

        elif isinstance(obj, numpy.dtype):
            return {"dtype": dtype2json(obj)}
github scikit-hep / awkward-array / awkward / type.py View on Github external
def __init__(self, *args):
        if len(args) < 2:
            raise ValueError("type specification missing")

        elif isinstance(args[0], awkward.util.string):
            self.__class__ = TableType
            self._fields = OrderedDict()
            if len(args) == 2:
                self[args[0]] = args[1]
            else:
                self[args[0]] = ArrayType(*args[1:])

        else:
            self.takes = args[0]
            if len(args) == 2:
                self.to = args[1]
            else:
                self.to = ArrayType(*args[1:])