Skip to content

Commit

Permalink
fix(graphviz): show proper field attributes of accessed relations and…
Browse files Browse the repository at this point in the history
… do not display join link property accesses (#8521)
  • Loading branch information
cpcloud authored Mar 22, 2024
1 parent 133a1f1 commit 69d6c73
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/how-to/visualization/graphs.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ graph](https://en.wikipedia.org/wiki/Directed_graph) using
To get started, make sure you've installed the necessary dependencies.

```sh
$ pip install 'ibis-framework[duckdb,examples,graphviz]'
$ pip install 'ibis-framework[duckdb,examples,visualization]'
```

::: {.callout-note collapse="true"}
Expand Down
3 changes: 1 addition & 2 deletions ibis/expr/tests/test_visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ def test_filter():
t = ibis.table([("a", "int64"), ("b", "string"), ("c", "int32")])
expr = t.filter((t.a == 1) & (t.b == "x"))
graph = viz.to_graph(expr, label_edges=True)
assert "predicates[0]" in graph.source
assert "predicates[1]" in graph.source
assert "Filter" in graph.source


def test_html_escape(monkeypatch):
Expand Down
28 changes: 19 additions & 9 deletions ibis/expr/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,26 @@ def to_graph(
if not label_edges:
label = None
else:
for name, arg in zip(v.argnames, v.args):
if isinstance(arg, tuple) and u in arg:
index = arg.index(u)
name = f"{name}[{index}]"
break
elif arg == u:
break
if isinstance(v, ops.Relation):
if (name := getattr(u, "name", None)) in v.fields:
name = f"fields[{name!r}]"
else:
name = None
else:
name = None
label = f"<.{name}>"
for name, arg in zip(v.argnames, v.args):
if isinstance(arg, tuple) and u in arg:
index = arg.index(u)
name = f"{name}[{index}]"
break
elif arg == u:
break
else:
name = None

if name is not None:
label = f"<.{name}>"
else:
label = None

g.edge(
uhash,
Expand Down

0 comments on commit 69d6c73

Please sign in to comment.