Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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))
def wrapper(*args, **kwargs):
return Symbolic(source = f)(*args, **kwargs)
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()
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
@dispatch_func.register(Symbolic)
def _dispatch_symbol(__data, *args, **kwargs):
return create_sym_call(FuncArg(dispatch_func), strip_symbolic(__data), *args, **kwargs)
def __op_invert(self):
return Symbolic(UnaryOp('__invert__', self.__source), ready_to_call = True)
def _unary_op(self):
node = UnaryOp(op_name, strip_symbolic(self))
return Symbolic(node, ready_to_call = True)