How to use the siuba.siu.MetaArg 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
def pipe_with_meta(f, *args, **kwargs):
    return create_pipe_call(f, MetaArg("_"), *args, **kwargs)
github machow / siuba / siuba / dply / verbs.py View on Github external
def wrapper(__data, *args, **kwargs):
        return create_pipe_call(f, MetaArg("_"), *args, **kwargs)
github machow / siuba / siuba / dply / verbs.py View on Github external
def wrapper(*args, **kwargs):
        return create_pipe_call(f, MetaArg("_"), *args, **kwargs)
    return f
github machow / siuba / siuba / dply / verbs.py View on Github external
def simple_varname(call):
    if isinstance(call, str):
        return call

    # check for expr like _.some_var or _["some_var"]
    if (isinstance(call, Call)
        and call.func in {"__getitem__", "__getattr__"}
        and isinstance(call.args[0], MetaArg)
        and isinstance(call.args[1], str)
        ):
        # return variable name
        return call.args[1]

    return None
github machow / siuba / siuba / siu.py View on Github external
def format(self, call, pad = 0):
        """Return a Symbolic or Call back as a nice tree, with boxes for nodes."""

        fmt_block = "█─"
        fmt_pipe = "├─"
        
        # TODO: why are some nodes still symbolic?
        if isinstance(call, Symbolic):
            return self.format(strip_symbolic(call))

        if isinstance(call, MetaArg):
            return "_"

        if isinstance(call, Call):
            call_str = fmt_block + ALL_OPS.get(call.func, repr(call.func))

            args_str = [self.format(arg) for arg in call.args]

            # format keyword args, making sure "└─ = █─" aligns box's children
            kwargs_str = []
            for k, v in call.kwargs.items():
                kwargs_str.append(
                        k + " = " + self.format(v, pad = len(k) + 3)
                        )

            all_args = [*args_str, *kwargs_str]
            padded = []
github machow / siuba / siuba / siu.py View on Github external
def str_to_getitem_call(x):
    return Call("__getitem__", MetaArg("_"), x)
github machow / siuba / siuba / spec / utils.py View on Github external
def replace_next(node):
        # swap in first replacement for meta arg (when possible)
        if isinstance(node, MetaArg):
            return next(replacements)
        
        # otherwise, recurse into node
        args, kwargs = node.map_subcalls(replace_next)

        # return a copy of node
        return node.__class__(node.func, *args, **kwargs)