def argument_symbolic_reference(self, arg): if hasattr(arg, '_eval'): arg = symbolic.to_callable(arg)(self.df) if isinstance(arg, pd.Series): return arg.name elif isinstance(arg, pd.DataFrame): return symbolic.sym_call(lambda *x: x, arg.columns.tolist()) elif isinstance(arg, (list, tuple)): arglist = [self.argument_symbolic_reference(subarg) for subarg in arg] return symbolic.sym_call(lambda *x: x, *arglist) return arg
def argument_symbolic_eval(self, arg): if isinstance(arg, (list, tuple)): arglist = [self.argument_symbolic_eval(subarg) for subarg in arg] return symbolic.sym_call(lambda *x: x, *arglist) else: if isinstance(arg, symbolic.Expression): self.call_has_symbolic = True return arg
def test_sym_call(self): expr = sym_call( 'func', Symbol('some_symbol'), 'arg1', 'arg2', kwarg_name='kwarg value') self.assertEqual( repr(expr), "'func'(*(Symbol('some_symbol'), 'arg1', 'arg2'), " + "**{'kwarg_name': 'kwarg value'})")
def test_pythagoras(self): from math import sqrt X = Symbol('X') Y = Symbol('Y') expr = sym_call(sqrt, X ** 2 + Y ** 2) func = to_callable(expr) self.assertEqual(func(X=3, Y=4), 5)