How to use the siuba.siu.Symbolic 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 / siu.py View on Github external
def create_sym_call(source, *args, **kwargs):
    return Symbolic(Call(
            "__call__",
            strip_symbolic(source),
            *map(strip_symbolic, args),
            **{k: strip_symbolic(v) for k,v in kwargs.items()}
            ),
            ready_to_call = True)
github machow / siuba / siuba / dply / verbs.py View on Github external
0  3  1
        1  1  1

    """
    # NOTE: using min_rank, since it can return a lazy expr for min_rank(ing)
    #       but I would rather not have it imported in verbs. will be more 
    #       reasonable if each verb were its own file? need abstract verb / vector module.
    #       vector imports experimental right now, so we need to invert deps
    # TODO: 
    #   * what if wt is a string? should remove all str -> expr in verbs like group_by etc..
    #   * verbs like filter allow lambdas, but this func breaks with that   
    from .vector import min_rank
    if wt is None:
        sym_wt = getattr(Symbolic(MetaArg("_")), __data.columns[-1])
    elif isinstance(wt, Call):
        sym_wt = Symbolic(wt)
    else:
        raise TypeError("wt must be a symbolic expression, eg. _.some_col")

    if n > 0:
        return filter(__data, min_rank(-sym_wt) <= n)
    else:
        return filter(__data, min_rank(sym_wt) <= abs(n))
github machow / siuba / siuba / meta_hook.py View on Github external
def wrapper(*args, **kwargs):
        return Symbolic(source = f)(*args, **kwargs)
github machow / siuba / siuba / siu.py View on Github external
return _unary_op

for k, v in BINARY_OPS.items():
    if k in {"__getattr__", "__getitem__"}: continue
    rop = k.replace("__", "__r", 1)
    setattr(Symbolic, k, create_binary_op(k))
    setattr(Symbolic, rop, create_binary_op(k, left_assoc = False))

for k, v in UNARY_OPS.items():
    if k != "__invert__":
        setattr(Symbolic, k, create_unary_op(k))

Lam = Lazy

_ = Symbolic()
github machow / siuba / siuba / siu.py View on Github external
def _binary_op(self, x):
        if left_assoc:
            node = BinaryOp(op_name, strip_symbolic(self), strip_symbolic(x))
        else:
            node = BinaryOp(op_name, strip_symbolic(x), strip_symbolic(self))

        return Symbolic(node, ready_to_call = True)
    return _binary_op
github machow / siuba / siuba / siu.py View on Github external
    @dispatch_func.register(Symbolic)
    def _dispatch_symbol(__data, *args, **kwargs):
        return create_sym_call(FuncArg(dispatch_func), strip_symbolic(__data), *args, **kwargs)
github machow / siuba / siuba / siu.py View on Github external
def __op_invert(self):
        return Symbolic(UnaryOp('__invert__', self.__source), ready_to_call = True)
github machow / siuba / siuba / siu.py View on Github external
def _unary_op(self):
        node = UnaryOp(op_name, strip_symbolic(self))

        return Symbolic(node, ready_to_call = True)