How to use the awkward1.forms.Form.fromjson function in awkward1

To help you get started, we’ve selected a few awkward1 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 CoffeaTeam / coffea / coffea / nanoevents / factory.py View on Github external
def _array(self, branch_name):
        interpretation = uproot.interpret(self._tree[branch_name])
        if isinstance(interpretation, uproot.asjagged):
            dtype = interpretation.content.type
            length = None
        else:
            dtype = interpretation.type
            length = len(self)
        parameters = {
            "__doc__": self._tree[branch_name].title.decode("ascii"),
            "__record__": "NanoColumn",
        }
        # use hint to resolve platform-dependent format
        formhint = awkward1.forms.Form.fromjson('"%s"' % dtype)
        form = awkward1.forms.NumpyForm(
            [], formhint.itemsize, formhint.format, parameters=parameters
        )
        generator = awkward1.layout.ArrayGenerator(
            self.reader, (branch_name, parameters), {}, form=form, length=length,
        )
        source = "file"
        return awkward1.layout.VirtualArray(
            generator,
            self._cache,
            "/".join([self._keyprefix, source, branch_name]),
            parameters=parameters,
        )
github CoffeaTeam / coffea / coffea / nanoevents / factory.py View on Github external
def _local2global(self, index, source_offsets, target_offsets, name):
        def globalindex():
            gidx = awkward1.Array(
                awkward1.layout.ListOffsetArray32(
                    awkward1.layout.Index32(source_offsets), index.generator(),
                )
            )
            gidx = gidx.mask[gidx >= 0] + target_offsets[:-1]
            return awkward1.fill_none(awkward1.flatten(gidx), -1)

        generator = awkward1.layout.ArrayGenerator(
            globalindex,
            (),
            {},
            form=awkward1.forms.Form.fromjson('"int64"'),
            length=index.generator.length,
        )
        return awkward1.layout.VirtualArray(
            generator,
            index.cache,
            "/".join([self._keyprefix, "local2global", name]),
            index.identities,
            index.parameters,
        )