Skip to content

Commit a52ba8a

Browse files
committed
Fix bug if size_prop is part of additional_properties
1 parent 57d20f0 commit a52ba8a

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
## Bug fixes
1111

1212
* Fixed a bug with `from_gds` where graphs with different relationship types would fail if they had different properties.
13+
* Fixed a bug with `from_gds` where the additional property would be skipped if its also defined as the size property.
1314

1415

1516
## Improvements

python-wrapper/src/neo4j_viz/gds.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ def from_gds(
148148
if size_property is not None:
149149
if "size" in all_actual_node_properties and size_property != "size":
150150
node_props_df.rename(columns={"size": "__size"}, inplace=True)
151-
node_props_df.rename(columns={size_property: "size"}, inplace=True)
151+
if size_property not in additional_node_properties:
152+
node_props_df.rename(columns={size_property: "size"}, inplace=True)
153+
else:
154+
node_props_df["size"] = node_props_df[size_property]
152155

153156
for lbl, df in node_dfs.items():
154157
if "labels" in all_actual_node_properties:

python-wrapper/tests/test_gds.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ def test_from_gds_integration_all_properties(gds: Any) -> None:
134134
(2, 0, "REL", "REL", 3.0, 2.5),
135135
]
136136

137-
138137
def test_from_gds_mocked(mocker: MockerFixture) -> None:
139138
from graphdatascience import Graph, GraphDataScience
140139

@@ -196,14 +195,14 @@ def test_from_gds_mocked(mocker: MockerFixture) -> None:
196195
G = Graph() # type: ignore[call-arg]
197196

198197
VG = from_gds(
199-
gds, G, size_property="score", additional_node_properties=["component"], node_radius_min_max=(3.14, 1337)
198+
gds, G, size_property="score", additional_node_properties=["component", "score"], node_radius_min_max=(3.14, 1337)
200199
)
201200

202201
assert len(VG.nodes) == 3
203202
assert sorted(VG.nodes, key=lambda x: x.id) == [
204-
Node(id=0, caption="['A']", size=float(1337), properties=dict(labels=["A"], component=float(1))),
205-
Node(id=1, caption="['C']", size=float(42), properties=dict(labels=["C"], component=float(4))),
206-
Node(id=2, caption="['A', 'B']", size=float(3.14), properties=dict(labels=["A", "B"], component=float(2))),
203+
Node(id=0, caption="['A']", size=float(1337), properties=dict(labels=["A"], component=float(1), score=float(1337))),
204+
Node(id=1, caption="['C']", size=float(42), properties=dict(labels=["C"], component=float(4), score=float(42))),
205+
Node(id=2, caption="['A', 'B']", size=float(3.14), properties=dict(labels=["A", "B"], component=float(2), score=float(3.14))),
207206
]
208207

209208
assert len(VG.relationships) == 3

0 commit comments

Comments
 (0)