def test_compound_aggregate_expr(table): # See ibis #24 compound_expr = (table['a'].sum() / table['a'].mean()).name('foo') assert L.is_reduction(compound_expr) # Validates internally table.aggregate([compound_expr])
def test_arbitrary(table, column, how, condition_fn): col = table[column] where = condition_fn(table) expr = col.arbitrary(how=how, where=where) assert expr.type() == col.type() assert isinstance(expr, ir.ScalarExpr) assert L.is_reduction(expr)
def reduction(argument, **kwargs): from ibis.expr.analysis import is_reduction if not is_reduction(argument): raise com.IbisTypeError("`argument` must be a reduction") return argument
def _visit_filter(self, expr): # Dumping ground for analysis of WHERE expressions # - Subquery extraction # - Conversion to explicit semi/anti joins # - Rewrites to generate subqueries op = expr.op() method = '_visit_filter_{0}'.format(type(op).__name__) if hasattr(self, method): f = getattr(self, method) return f(expr) unchanged = True if isinstance(expr, ir.ScalarExpr): if L.is_reduction(expr): return self._rewrite_reduction_filter(expr) if isinstance(op, ops.BinaryOp): left = self._visit_filter(op.left) right = self._visit_filter(op.right) unchanged = left is op.left and right is op.right if not unchanged: return expr._factory(type(op)(left, right)) else: return expr elif isinstance( op, (ops.Any, ops.BooleanValueOp, ops.TableColumn, ops.Literal)): return expr elif isinstance(op, ops.ValueOp): visited = [ self._visit_filter(arg) if isinstance(arg, ir.Expr) else arg for arg in op.args ] unchanged = True for new, old in zip(visited, op.args): if new is not old: unchanged = False if not unchanged: return expr._factory(type(op)(*visited)) else: return expr else: raise NotImplementedError(type(op))
def test_any_all_notany(table, column, operation): expr = operation(table[column]) assert isinstance(expr, ir.BooleanScalar) assert L.is_reduction(expr)