Skip to content

Commit c01c10f

Browse files
authored
Merge pull request #183 from neo4j/rel-captions-gds
Show relationship types as default caption with `from_gds`
2 parents 3f589b7 + a5152bd commit c01c10f

File tree

4 files changed

+93
-72
lines changed

4 files changed

+93
-72
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
## Breaking changes
55

6+
* Relationship types are now added as the default caption on relationships when fetched using `from_gds`
7+
68

79
## New features
810

examples/gds-example.ipynb

Lines changed: 60 additions & 60 deletions
Large diffs are not rendered by default.

python-wrapper/src/neo4j_viz/gds.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def from_gds(
5656
If the properties are named as the fields of the `Node` class, they will be included as top level fields of the
5757
created `Node` objects. Otherwise, they will be included in the `properties` dictionary.
5858
Additionally, a new "labels" node property will be added, containing the node labels of the node.
59+
Similarly for relationships, a new "relationshipType" property will be added.
5960
6061
Parameters
6162
----------
@@ -146,6 +147,9 @@ def from_gds(
146147
if "caption" not in actual_node_properties:
147148
node_df["caption"] = node_df["labels"].astype(str)
148149

150+
if "caption" not in rel_df.columns:
151+
rel_df["caption"] = rel_df["relationshipType"]
152+
149153
try:
150154
return _from_dfs(node_df, rel_df, node_radius_min_max=node_radius_min_max, rename_properties={"__size": "size"})
151155
except ValueError as e:

python-wrapper/tests/test_gds.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,22 @@ def test_from_gds_integration_size(gds: Any) -> None:
5454
assert len(VG.relationships) == 3
5555
vg_rels = sorted(
5656
[
57-
(e.source, e.target, e.properties["relationshipType"], e.properties["cost"], e.properties["weight"])
57+
(
58+
e.source,
59+
e.target,
60+
e.caption,
61+
e.properties["relationshipType"],
62+
e.properties["cost"],
63+
e.properties["weight"],
64+
)
5865
for e in VG.relationships
5966
],
6067
key=lambda x: x[0],
6168
)
6269
assert vg_rels == [
63-
(0, 1, "REL", 1.0, 0.5),
64-
(1, 2, "REL2", 2.0, 1.5),
65-
(2, 0, "REL", 3.0, 2.5),
70+
(0, 1, "REL", "REL", 1.0, 0.5),
71+
(1, 2, "REL2", "REL2", 2.0, 1.5),
72+
(2, 0, "REL", "REL", 3.0, 2.5),
6673
]
6774

6875

@@ -108,15 +115,22 @@ def test_from_gds_integration_all_properties(gds: Any) -> None:
108115
assert len(VG.relationships) == 3
109116
vg_rels = sorted(
110117
[
111-
(e.source, e.target, e.properties["relationshipType"], e.properties["cost"], e.properties["weight"])
118+
(
119+
e.source,
120+
e.target,
121+
e.caption,
122+
e.properties["relationshipType"],
123+
e.properties["cost"],
124+
e.properties["weight"],
125+
)
112126
for e in VG.relationships
113127
],
114128
key=lambda x: x[0],
115129
)
116130
assert vg_rels == [
117-
(0, 1, "REL", 1.0, 0.5),
118-
(1, 2, "REL2", 2.0, 1.5),
119-
(2, 0, "REL", 3.0, 2.5),
131+
(0, 1, "REL", "REL", 1.0, 0.5),
132+
(1, 2, "REL2", "REL2", 2.0, 1.5),
133+
(2, 0, "REL", "REL", 3.0, 2.5),
120134
]
121135

122136

@@ -191,12 +205,13 @@ def test_from_gds_mocked(mocker: MockerFixture) -> None:
191205

192206
assert len(VG.relationships) == 3
193207
vg_rels = sorted(
194-
[(e.source, e.target, e.properties["relationshipType"]) for e in VG.relationships], key=lambda x: x[0]
208+
[(e.source, e.target, e.caption, e.properties["relationshipType"]) for e in VG.relationships],
209+
key=lambda x: x[0],
195210
)
196211
assert vg_rels == [
197-
(0, 1, "REL"),
198-
(1, 2, "REL2"),
199-
(2, 0, "REL"),
212+
(0, 1, "REL", "REL"),
213+
(1, 2, "REL2", "REL2"),
214+
(2, 0, "REL", "REL"),
200215
]
201216

202217

0 commit comments

Comments
 (0)