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_pipe_call(source, *args, **kwargs):
first, *rest = args
return Pipeable(Call(
"__call__",
strip_symbolic(source),
strip_symbolic(first),
*(Lazy(strip_symbolic(x)) for x in rest),
**{k: Lazy(strip_symbolic(v)) for k,v in kwargs.items()}
))
def __rrshift__(self, x):
if isinstance(x, Pipeable):
return Pipeable(calls = x.calls + self.calls)
elif callable(x):
return Pipeable(calls = [x] + self.calls)
return self(x)
def __rrshift__(self, x):
if isinstance(x, Pipeable):
return Pipeable(calls = x.calls + self.calls)
elif callable(x):
return Pipeable(calls = [x] + self.calls)
return self(x)
def __call__(self, x):
res = x
for f in self.calls:
res = f(res)
return res
pipe = Pipeable
def _regroup(df):
# try to regroup, when user kept index (e.g. group_keys = True)
if len(df.index.names) > 1:
# handle cases where...
# 1. grouping with named indices (as_index = True)
# 2. grouping is level 0 (as_index = False)
grp_levels = [x for x in df.index.names if x is not None] or [0]
return df.groupby(level = grp_levels)
def simple_varname(call):
if isinstance(call, str):
return call
def __rshift__(self, x):
if isinstance(x, Pipeable):
return Pipeable(calls = self.calls + x.calls)
elif callable(x):
return Pipeable(calls = self.calls + [x])
raise Exception()
def __rshift__(self, x):
if isinstance(x, Pipeable):
return Pipeable(calls = self.calls + x.calls)
elif callable(x):
return Pipeable(calls = self.calls + [x])
raise Exception()