Skip to content
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
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

## Breaking changes

* The `from_gds` methods now fetches all node properties of a given GDS projection by default, instead of none.
* The `from_gds` method now fetches all node properties of a given GDS projection by default, instead of none.
* The `from_gds` now adds node labels as captions for nodes.


## New features
Expand Down
135 changes: 69 additions & 66 deletions examples/gds-example.ipynb

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions python-wrapper/src/neo4j_viz/gds.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ def from_gds(

node_df = node_props_df.merge(node_labels_df, on="id")

if "caption" not in actual_node_properties:
node_df["caption"] = node_df["labels"].astype(str)

rel_df = _rel_df(gds, G)
rel_df.rename(columns={"sourceNodeId": "source", "targetNodeId": "target"}, inplace=True)

Expand Down
27 changes: 17 additions & 10 deletions python-wrapper/tests/test_gds.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


@pytest.mark.requires_neo4j_and_gds
def test_from_gds_integration(gds: Any) -> None:
def test_from_gds_integration_size(gds: Any) -> None:
from neo4j_viz.gds import from_gds

nodes = pd.DataFrame(
Expand Down Expand Up @@ -41,9 +41,14 @@ def test_from_gds_integration(gds: Any) -> None:

assert len(VG.nodes) == 3
assert sorted(VG.nodes, key=lambda x: x.id) == [
Node(id=0, size=float(1337), properties=dict(labels=["A"], component=float(1), size=0.1)),
Node(id=1, size=float(42), properties=dict(labels=["C"], component=float(4), size=0.2)),
Node(id=2, size=float(3.14), properties=dict(labels=["A", "B"], component=float(2), size=0.3)),
Node(id=0, size=float(1337), caption="['A']", properties=dict(labels=["A"], component=float(1), size=0.1)),
Node(id=1, size=float(42), caption="['C']", properties=dict(labels=["C"], component=float(4), size=0.2)),
Node(
id=2,
size=float(3.14),
caption="['A', 'B']",
properties=dict(labels=["A", "B"], component=float(2), size=0.3),
),
]

assert len(VG.relationships) == 3
Expand Down Expand Up @@ -93,9 +98,11 @@ def test_from_gds_integration_all_properties(gds: Any) -> None:

assert len(VG.nodes) == 3
assert sorted(VG.nodes, key=lambda x: x.id) == [
Node(id=0, size=0.1, properties=dict(labels=["A"], component=float(1), score=1337.0)),
Node(id=1, size=0.2, properties=dict(labels=["C"], component=float(4), score=42.0)),
Node(id=2, size=0.3, properties=dict(labels=["A", "B"], component=float(2), score=3.14)),
Node(id=0, size=0.1, caption="['A']", properties=dict(labels=["A"], component=float(1), score=1337.0)),
Node(id=1, size=0.2, caption="['C']", properties=dict(labels=["C"], component=float(4), score=42.0)),
Node(
id=2, size=0.3, caption="['A', 'B']", properties=dict(labels=["A", "B"], component=float(2), score=3.14)
),
]

assert len(VG.relationships) == 3
Expand Down Expand Up @@ -176,9 +183,9 @@ def test_from_gds_mocked(mocker: MockerFixture) -> None:

assert len(VG.nodes) == 3
assert sorted(VG.nodes, key=lambda x: x.id) == [
Node(id=0, size=float(1337), properties=dict(labels=["A"], component=float(1))),
Node(id=1, size=float(42), properties=dict(labels=["C"], component=float(4))),
Node(id=2, size=float(3.14), properties=dict(labels=["A", "B"], component=float(2))),
Node(id=0, caption="['A']", size=float(1337), properties=dict(labels=["A"], component=float(1))),
Node(id=1, caption="['C']", size=float(42), properties=dict(labels=["C"], component=float(4))),
Node(id=2, caption="['A', 'B']", size=float(3.14), properties=dict(labels=["A", "B"], component=float(2))),
]

assert len(VG.relationships) == 3
Expand Down