Beispiel #1
0
def test_sort_by():
    t = ibis.table([('a', 'int64'), ('b', 'string'), ('c', 'int32')])
    expr = (
        t.groupby(t.b).aggregate(sum_a=t.a.sum().cast('double')).sort_by('b')
    )
    graph = viz.to_graph(expr)
    assert key(expr) in graph.source
Beispiel #2
0
def test_join(how):
    left = ibis.table([('a', 'int64'), ('b', 'string')])
    right = ibis.table([('b', 'string'), ('c', 'int64')])
    joined = left.join(right, left.b == right.b, how=how)
    result = joined[left.a, right.c]
    graph = viz.to_graph(result)
    assert key(result) in graph.source
Beispiel #3
0
def test_sort_by():
    t = ibis.table([('a', 'int64'), ('b', 'string'), ('c', 'int32')])
    expr = (
        t.groupby(t.b).aggregate(sum_a=t.a.sum().cast('double')).sort_by('c')
    )
    graph = viz.to_graph(expr)
    assert key(expr) in graph.source
Beispiel #4
0
 def _repr_png_(self):
     try:
         import ibis.expr.visualize as viz
     except ImportError:
         return None
     else:
         return viz.to_graph(self).pipe(format='png')
Beispiel #5
0
def test_join(how):
    left = ibis.table([('a', 'int64'), ('b', 'string')])
    right = ibis.table([('b', 'string'), ('c', 'int64')])
    joined = left.join(right, left.b == right.b, how=how)
    result = joined[left.a, right.c]
    graph = viz.to_graph(result)
    assert key(result) in graph.source
Beispiel #6
0
def test_asof_join():
    left = ibis.table([('time', 'int32'), ('value', 'double')])
    right = ibis.table([('time', 'int32'), ('value2', 'double')])
    right = right.mutate(foo=1)

    joined = api.asof_join(left, right, 'time')
    result = joined[left, right.foo]
    graph = viz.to_graph(result)
    assert key(result) in graph.source
Beispiel #7
0
def test_asof_join():
    left = ibis.table([('time', 'int32'), ('value', 'double')])
    right = ibis.table([('time', 'int32'), ('value2', 'double')])
    right = right.mutate(foo=1)

    joined = api.asof_join(left, right, 'time')
    result = joined[left, right.foo]
    graph = viz.to_graph(result)
    assert key(result) in graph.source
Beispiel #8
0
def test_between():
    t = ibis.table([('a', 'int64'), ('b', 'string'), ('c', 'int32')])
    expr = t.a.between(1, 1)
    lower_bound, upper_bound = expr.op().args[1:]
    graph = viz.to_graph(expr)
    source = graph.source

    # one for the node itself and one for the edge to between
    assert key(lower_bound, 'lower_bound') in source
    assert key(upper_bound, 'upper_bound') in source
Beispiel #9
0
def test_between():
    t = ibis.table([('a', 'int64'), ('b', 'string'), ('c', 'int32')])
    expr = t.a.between(1, 1)
    lower_bound, upper_bound = expr.op().args[1:]
    graph = viz.to_graph(expr)
    source = graph.source

    # one for the node itself and one for the edge to between
    assert key(lower_bound, 'lower_bound') in source
    assert key(upper_bound, 'upper_bound') in source
Beispiel #10
0
 def _repr_png_(self):
     try:
         import ibis.expr.visualize as viz
     except ImportError:
         return None
     else:
         try:
             return viz.to_graph(self).pipe(format='png')
         except Exception:
             # Something may go wrong, and we can't error in the notebook
             # so fallback to the default text representation.
             return None
Beispiel #11
0
def test_custom_expr():
    class MyExpr(ir.Expr):
        pass

    class MyExprNode(ops.Node):
        foo = rlz.string
        bar = rlz.numeric
        output_type = MyExpr

    op = MyExprNode('Hello!', 42.3)
    expr = op.to_expr()
    graph = viz.to_graph(expr)
    assert key(expr) in graph.source
Beispiel #12
0
 def _repr_png_(self):
     if not ibis.options.graphviz_repr:
         return None
     try:
         import ibis.expr.visualize as viz
     except ImportError:
         return None
     else:
         try:
             return viz.to_graph(self).pipe(format='png')
         except Exception:
             # Something may go wrong, and we can't error in the notebook
             # so fallback to the default text representation.
             return None
Beispiel #13
0
def test_custom_expr():
    class MyExpr(ir.Expr):
        pass

    class MyExprNode(ops.Node):
        foo = Arg(rlz.string)
        bar = Arg(rlz.numeric)

        def output_type(self):
            return MyExpr

    op = MyExprNode('Hello!', 42.3)
    expr = op.to_expr()
    graph = viz.to_graph(expr)
    assert key(expr) in graph.source
Beispiel #14
0
def test_custom_expr():
    class MyExpr(ir.Expr):
        pass

    class MyExprNode(ops.Node):
        foo = Arg(rlz.string)
        bar = Arg(rlz.numeric)

        def output_type(self):
            return MyExpr

    op = MyExprNode('Hello!', 42.3)
    expr = op.to_expr()
    graph = viz.to_graph(expr)
    assert key(expr) in graph.source
Beispiel #15
0
def test_custom_expr():
    class MyExpr(ir.Expr):
        pass

    class MyExprNode(ir.Node):

        input_type = [
            rules.string(name='foo'),
            rules.number(name='bar'),
        ]

        def output_type(self):
            return MyExpr

    op = MyExprNode(['Hello!', 42.3])
    expr = op.to_expr()
    graph = viz.to_graph(expr)
    assert str(hash(repr(op))) in graph.source
Beispiel #16
0
def test_custom_expr_with_not_implemented_type():
    class MyExpr(ir.Expr):
        def type(self):
            raise NotImplementedError

        def schema(self):
            raise NotImplementedError

    class MyExprNode(ops.Node):
        foo = Arg(rlz.string)
        bar = Arg(rlz.numeric)

        def output_type(self):
            return MyExpr

    op = MyExprNode('Hello!', 42.3)
    expr = op.to_expr()
    graph = viz.to_graph(expr)
    assert key(expr) in graph.source
Beispiel #17
0
def test_custom_expr_with_not_implemented_type():
    class MyExpr(ir.Expr):
        def type(self):
            raise NotImplementedError

        def schema(self):
            raise NotImplementedError

    class MyExprNode(ops.Node):
        foo = Arg(rlz.string)
        bar = Arg(rlz.numeric)

        def output_type(self):
            return MyExpr

    op = MyExprNode('Hello!', 42.3)
    expr = op.to_expr()
    graph = viz.to_graph(expr)
    assert key(expr) in graph.source
Beispiel #18
0
def test_custom_expr_with_not_implemented_type():
    class MyExpr(ir.Expr):
        def type(self):
            raise NotImplementedError

        def schema(self):
            raise NotImplementedError

    class MyExprNode(ir.Node):

        input_type = [
            rules.string(name='foo'),
            rules.number(name='bar'),
        ]

        def output_type(self):
            return MyExpr

    op = MyExprNode(['Hello!', 42.3])
    expr = op.to_expr()
    graph = viz.to_graph(expr)
    assert str(hash(repr(op))) in graph.source
Beispiel #19
0
    def visualize(self, format='png'):
        """Visualize an expression in the browser as a PNG image.

        Parameters
        ----------
        format : str, optional
            Defaults to ``'png'``. Some additional formats are
            ``'jpeg'`` and ``'svg'``. These are specified by the ``graphviz``
            Python library.

        Notes
        -----
        This method opens a web browser tab showing the image of the expression
        graph created by the code in :module:`ibis.expr.visualize`.

        Raises
        ------
        ImportError
            If ``graphviz`` is not installed.
        """
        import ibis.expr.visualize as viz
        path = viz.draw(viz.to_graph(self), format=format)
        webbrowser.open('file://{}'.format(os.path.abspath(path)))
Beispiel #20
0
    def visualize(self, format: str = 'svg') -> None:
        """Visualize an expression in the browser as an SVG image.

        Parameters
        ----------
        format
            Image output format. These are specified by the ``graphviz`` Python
            library.

        Notes
        -----
        This method opens a web browser tab showing the image of the expression
        graph created by the code in [ibis.expr.visualize][].

        Raises
        ------
        ImportError
            If ``graphviz`` is not installed.
        """
        import ibis.expr.visualize as viz

        path = viz.draw(viz.to_graph(self), format=format)
        webbrowser.open(f'file://{os.path.abspath(path)}')
Beispiel #21
0
    def visualize(self, format='svg'):
        """Visualize an expression in the browser as an SVG image.

        Parameters
        ----------
        format : str, optional
            Defaults to ``'svg'``. Some additional formats are
            ``'jpeg'`` and ``'png'``. These are specified by the ``graphviz``
            Python library.

        Notes
        -----
        This method opens a web browser tab showing the image of the expression
        graph created by the code in :module:`ibis.expr.visualize`.

        Raises
        ------
        ImportError
            If ``graphviz`` is not installed.
        """
        import ibis.expr.visualize as viz

        path = viz.draw(viz.to_graph(self), format=format)
        webbrowser.open('file://{}'.format(os.path.abspath(path)))
Beispiel #22
0
def test_exprs(table, expr_func):
    expr = expr_func(table)
    graph = viz.to_graph(expr)
    assert str(hash(table.op())) in graph.source
    assert str(hash(expr.op())) in graph.source
Beispiel #23
0
def test_exprs(table, expr_func):
    expr = expr_func(table)
    graph = viz.to_graph(expr)
    assert key(table, 'table') in graph.source
    assert key(expr) in graph.source
Beispiel #24
0
def test_exprs(table, expr_func):
    expr = expr_func(table)
    graph = viz.to_graph(expr)
    assert key(table, 'table') in graph.source
    assert key(expr) in graph.source
Beispiel #25
0
def test_exprs(t, expr_func):
    expr = expr_func(t)
    graph = viz.to_graph(expr)
    assert str(hash(repr(t.op()))) in graph.source
    assert str(hash(repr(expr.op()))) in graph.source