def numpy_pandas_function_from_str(f): """ reconstruct function from string representation """ if f.startswith(np.__name__): mod = np elif f.startswith(pd.__name__): mod = pd elif f.startswith(builtins.__name__): mod = builtins else: msg = ("Function {} not recognized; only numpy, pandas, or builtin " "functions are supported.") raise wz_ex.NotImplemented(msg.format(f)) fcn = reduce(getattr, f.split('.')[1:], mod) return fcn
def test_simple_add(n): x = symbol('x', 'int') expr = reduce(operator.add, [x] * n) assert compute(expr, 1) == n