How to use the awkward1.behavior 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 / methods / mixin.py View on Github external
def mixin_class(cls):
    """Decorator to register a mixin class

    Fills in any known behaviors based on class inheritance
    """
    name = cls.__name__
    awkward1.behavior[name] = type(name + "Record", (cls, awkward1.Record), {})
    awkward1.behavior["*", name] = type(name + "Array", (cls, awkward1.Array), {})
    for basecls in cls.__mro__:
        for method in basecls.__dict__.values():
            if hasattr(method, "_awkward_mixin"):
                ufunc, rhs, transpose = method._awkward_mixin
                if rhs is None:
                    awkward1.behavior.setdefault((ufunc, name), method)
                    continue
                for rhs_name in list(rhs) + [name]:
                    awkward1.behavior.setdefault((ufunc, name, rhs_name), method)
                    if transpose is not None:
                        awkward1.behavior.setdefault((ufunc, rhs_name, name), transpose)
                if basecls.__name__ in rhs:
                    rhs.add(name)
    return cls
github CoffeaTeam / coffea / coffea / nanoaod / nanoawkward1.py View on Github external
def mixin_class(cls):
    name = cls.__name__
    cls._awkward_mixin = True
    awkward1.behavior[name] = type(name + "Record", (cls, awkward1.Record), {})
    awkward1.behavior["*", name] = type(name + "Array", (cls, awkward1.Array), {})
    possible_inherited = [
        tup for tup in awkward1.behavior if len(tup) >= 2 and callable(tup[0])
    ]
    for tup in possible_inherited:
        for basecls in cls.__mro__[1:]:
            if not hasattr(basecls, "_awkward_mixin"):
                continue
            basename = basecls.__name__
            if len(tup) == 2 and tup[1] == basename:
                signature = (tup[0], name)
                if signature not in awkward1.behavior:
                    awkward1.behavior[signature] = awkward1.behavior[tup]
                break
            elif len(tup) == 3 and basename in tup[1:]:
                if tup[1] == basename:
github CoffeaTeam / coffea / coffea / nanoaod / nanoawkward1.py View on Github external
def register(method):
        if transpose:
            mtransposed = lambda left, right: method(right, left)
        for signature in signatures:
            awkward1.behavior[signature] = method
            if transpose:
                if len(signature) != 3:
                    raise RuntimeError(
                        "Not sure how to create transposed method for non-binary signature"
                    )
                if signature[1] == signature[2]:
                    continue
                awkward1.behavior[
                    signature[0], signature[2], signature[1]
                ] = mtransposed
        return method
github CoffeaTeam / coffea / coffea / nanoevents / methods / mixin.py View on Github external
def mixin_class(cls):
    """Decorator to register a mixin class

    Fills in any known behaviors based on class inheritance
    """
    name = cls.__name__
    awkward1.behavior[name] = type(name + "Record", (cls, awkward1.Record), {})
    awkward1.behavior["*", name] = type(name + "Array", (cls, awkward1.Array), {})
    for basecls in cls.__mro__:
        for method in basecls.__dict__.values():
            if hasattr(method, "_awkward_mixin"):
                ufunc, rhs, transpose = method._awkward_mixin
                if rhs is None:
                    awkward1.behavior.setdefault((ufunc, name), method)
                    continue
                for rhs_name in list(rhs) + [name]:
                    awkward1.behavior.setdefault((ufunc, name, rhs_name), method)
                    if transpose is not None:
                        awkward1.behavior.setdefault((ufunc, rhs_name, name), transpose)
                if basecls.__name__ in rhs:
                    rhs.add(name)
    return cls