def wrapper(*args, **kwargs): if any(isinstance(arg, frame_base.DeferredBase) for arg in args + tuple(kwargs.values())): return frame_base._elementwise_function(func, name)(*args, **kwargs) res = func(*args, **kwargs) return _maybe_wrap_constant_expr(res)
def test_elementwise_func(self): a = pd.Series([1, 2, 3]) b = pd.Series([100, 200, 300]) empty_proxy = a[:0] x = frames.DeferredSeries(expressions.PlaceholderExpression(empty_proxy)) y = frames.DeferredSeries(expressions.PlaceholderExpression(empty_proxy)) sub = frame_base._elementwise_function(lambda x, y: x - y) session = expressions.Session({x._expr: a, y._expr: b}) self.assertTrue(sub(x, y)._expr.evaluate_at(session).equals(a - b)) self.assertTrue(sub(x, 1)._expr.evaluate_at(session).equals(a - 1)) self.assertTrue(sub(1, x)._expr.evaluate_at(session).equals(1 - a)) self.assertTrue(sub(x, b)._expr.evaluate_at(session).equals(a - b)) self.assertTrue(sub(a, y)._expr.evaluate_at(session).equals(a - b))