Skip to content

Show relationship types as default caption with from_gds #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

## Breaking changes

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


## New features

Expand Down
120 changes: 60 additions & 60 deletions examples/gds-example.ipynb

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions python-wrapper/src/neo4j_viz/gds.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def from_gds(
If the properties are named as the fields of the `Node` class, they will be included as top level fields of the
created `Node` objects. Otherwise, they will be included in the `properties` dictionary.
Additionally, a new "labels" node property will be added, containing the node labels of the node.
Similarly for relationships, a new "relationshipType" property will be added.

Parameters
----------
Expand Down Expand Up @@ -146,6 +147,9 @@ def from_gds(
if "caption" not in actual_node_properties:
node_df["caption"] = node_df["labels"].astype(str)

if "caption" not in rel_df.columns:
rel_df["caption"] = rel_df["relationshipType"]

try:
return _from_dfs(node_df, rel_df, node_radius_min_max=node_radius_min_max, rename_properties={"__size": "size"})
except ValueError as e:
Expand Down
39 changes: 27 additions & 12 deletions python-wrapper/tests/test_gds.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,22 @@ def test_from_gds_integration_size(gds: Any) -> None:
assert len(VG.relationships) == 3
vg_rels = sorted(
[
(e.source, e.target, e.properties["relationshipType"], e.properties["cost"], e.properties["weight"])
(
e.source,
e.target,
e.caption,
e.properties["relationshipType"],
e.properties["cost"],
e.properties["weight"],
)
for e in VG.relationships
],
key=lambda x: x[0],
)
assert vg_rels == [
(0, 1, "REL", 1.0, 0.5),
(1, 2, "REL2", 2.0, 1.5),
(2, 0, "REL", 3.0, 2.5),
(0, 1, "REL", "REL", 1.0, 0.5),
(1, 2, "REL2", "REL2", 2.0, 1.5),
(2, 0, "REL", "REL", 3.0, 2.5),
]


Expand Down Expand Up @@ -108,15 +115,22 @@ def test_from_gds_integration_all_properties(gds: Any) -> None:
assert len(VG.relationships) == 3
vg_rels = sorted(
[
(e.source, e.target, e.properties["relationshipType"], e.properties["cost"], e.properties["weight"])
(
e.source,
e.target,
e.caption,
e.properties["relationshipType"],
e.properties["cost"],
e.properties["weight"],
)
for e in VG.relationships
],
key=lambda x: x[0],
)
assert vg_rels == [
(0, 1, "REL", 1.0, 0.5),
(1, 2, "REL2", 2.0, 1.5),
(2, 0, "REL", 3.0, 2.5),
(0, 1, "REL", "REL", 1.0, 0.5),
(1, 2, "REL2", "REL2", 2.0, 1.5),
(2, 0, "REL", "REL", 3.0, 2.5),
]


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

assert len(VG.relationships) == 3
vg_rels = sorted(
[(e.source, e.target, e.properties["relationshipType"]) for e in VG.relationships], key=lambda x: x[0]
[(e.source, e.target, e.caption, e.properties["relationshipType"]) for e in VG.relationships],
key=lambda x: x[0],
)
assert vg_rels == [
(0, 1, "REL"),
(1, 2, "REL2"),
(2, 0, "REL"),
(0, 1, "REL", "REL"),
(1, 2, "REL2", "REL2"),
(2, 0, "REL", "REL"),
]


Expand Down