How to use the siuba.siu.Call function in siuba

To help you get started, we’ve selected a few siuba 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 machow / siuba / siuba / dply / verbs.py View on Github external
@if_else.register(Call)
@if_else.register(Symbolic)
def _if_else(__data, *args, **kwargs):
    return create_sym_call(if_else, __data, *args, **kwargs)
github machow / siuba / siuba / siu.py View on Github external
self.args = (dict, dict(self.args[1]))

    def map_subcalls(self, f):
        d = self.args[1]

        new_d = {
                f(k) if isinstance(k, Call) else k: f(v) if isinstance(v, Call) else v
                        for k,v in d.items()
                        }

        return (self.args[0], new_d), {}

    def __call__(self, x):
        return self.args[1]

class SliceOp(Call):
    def __init__(self, func, *args, **kwargs):
        self.func = "__siu_slice__"
        self.args = args

        if kwargs:
            raise ValueError("a slice cannot accept keyword arguments")

        self.kwargs = {}

    def __repr__(self):
        return ":".join(repr(x) for x in self.args if x is not None)

    def __call__(self, x):
        args = [self.evaluate_calls(arg, x) for arg in self.args]
        
        return slice(*args)
github machow / siuba / siuba / siu.py View on Github external
    @dispatch_func.register(Call)
    def _dispatch_call(__data, *args, **kwargs):
        # TODO: want to just create call, for now use hack of creating a symbolic
        #       call and getting the source off of it...
        return strip_symbolic(create_sym_call(FuncArg(dispatch_func), __data, *args, **kwargs))
github machow / siuba / siuba / siu.py View on Github external
else:
            fmt_args = list(map(repr, args))

        return fmt.format(func = func, args = fmt_args, spaces = spaces)

    def needs_paren(self, x):
        if isinstance(x, BinaryOp):
            sub_lvl = BINARY_LEVELS[x.func]
            level = BINARY_LEVELS[self.func]
            if sub_lvl != 0 and sub_lvl > level:
                return True

        return False


class DictCall(Call):
    """evaluates both keys and vals."""

    def __init__(self, f, *args, **kwargs):
        # TODO: validation, clean up class
        super().__init__(f, *args, **kwargs)
        self.args = (dict, dict(self.args[1]))

    def map_subcalls(self, f):
        d = self.args[1]

        new_d = {
                f(k) if isinstance(k, Call) else k: f(v) if isinstance(v, Call) else v
                        for k,v in d.items()
                        }

        return (self.args[0], new_d), {}
github machow / siuba / siuba / siu.py View on Github external
varnames.add(op_var)

        if (not attr_calls
            and self.func == "__call__"
            and isinstance(self.args[0], Call)
            and self.args[0].func == "__getattr__"
            ):
            # skip obj, since it fetches an attribute this node is calling
            prev_obj, prev_attr = self.args[0].args
            all_args = itertools.chain([prev_obj], self.args[1:], self.kwargs.values())
        else:
            all_args = itertools.chain(self.args, self.kwargs.values())


        for arg in all_args:
            if isinstance(arg, Call):
                varnames.update(arg.op_vars(attr_calls = attr_calls))

        return varnames
github machow / siuba / siuba / dply / verbs.py View on Github external
def __call__(self, *args, **kwargs):
        call = Call('__call__',
                    BinaryOp('__getattr__', MetaArg("_"), self.name),
                    *args,
                    **kwargs
                    )

        return self.to_copy(name = call)