Skip to content

Commit 72cb5ac

Browse files
adamnschFlorentinD
andcommitted
Set labels as caption in from_gds
Co-Authored-By: Florentin Dörre <[email protected]>
1 parent 6cc7241 commit 72cb5ac

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
## Breaking changes
55

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

89

910
## New features

python-wrapper/src/neo4j_viz/gds.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ def from_gds(
111111

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

114+
if "caption" not in actual_node_properties:
115+
node_df["caption"] = node_df["labels"].astype(str)
116+
114117
rel_df = _rel_df(gds, G)
115118
rel_df.rename(columns={"sourceNodeId": "source", "targetNodeId": "target"}, inplace=True)
116119

python-wrapper/tests/test_gds.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

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

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

4242
assert len(VG.nodes) == 3
4343
assert sorted(VG.nodes, key=lambda x: x.id) == [
44-
Node(id=0, size=float(1337), properties=dict(labels=["A"], component=float(1), size=0.1)),
45-
Node(id=1, size=float(42), properties=dict(labels=["C"], component=float(4), size=0.2)),
46-
Node(id=2, size=float(3.14), properties=dict(labels=["A", "B"], component=float(2), size=0.3)),
44+
Node(id=0, size=float(1337), caption="['A']", properties=dict(labels=["A"], component=float(1), size=0.1)),
45+
Node(id=1, size=float(42), caption="['C']", properties=dict(labels=["C"], component=float(4), size=0.2)),
46+
Node(
47+
id=2,
48+
size=float(3.14),
49+
caption="['A', 'B']",
50+
properties=dict(labels=["A", "B"], component=float(2), size=0.3),
51+
),
4752
]
4853

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

9499
assert len(VG.nodes) == 3
95100
assert sorted(VG.nodes, key=lambda x: x.id) == [
96-
Node(id=0, size=0.1, properties=dict(labels=["A"], component=float(1), score=1337.0)),
97-
Node(id=1, size=0.2, properties=dict(labels=["C"], component=float(4), score=42.0)),
98-
Node(id=2, size=0.3, properties=dict(labels=["A", "B"], component=float(2), score=3.14)),
101+
Node(id=0, size=0.1, caption="['A']", properties=dict(labels=["A"], component=float(1), score=1337.0)),
102+
Node(id=1, size=0.2, caption="['C']", properties=dict(labels=["C"], component=float(4), score=42.0)),
103+
Node(
104+
id=2, size=0.3, caption="['A', 'B']", properties=dict(labels=["A", "B"], component=float(2), score=3.14)
105+
),
99106
]
100107

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

177184
assert len(VG.nodes) == 3
178185
assert sorted(VG.nodes, key=lambda x: x.id) == [
179-
Node(id=0, size=float(1337), properties=dict(labels=["A"], component=float(1))),
180-
Node(id=1, size=float(42), properties=dict(labels=["C"], component=float(4))),
181-
Node(id=2, size=float(3.14), properties=dict(labels=["A", "B"], component=float(2))),
186+
Node(id=0, caption="['A']", size=float(1337), properties=dict(labels=["A"], component=float(1))),
187+
Node(id=1, caption="['C']", size=float(42), properties=dict(labels=["C"], component=float(4))),
188+
Node(id=2, caption="['A', 'B']", size=float(3.14), properties=dict(labels=["A", "B"], component=float(2))),
182189
]
183190

184191
assert len(VG.relationships) == 3

0 commit comments

Comments
 (0)