diff --git a/.vscode/settings.json b/.vscode/settings.json index f13ada3a..3be2b8f7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,11 @@ { "python.analysis.extraPaths": [ "./python-wrapper/src" - ] + ], + "python.testing.pytestArgs": [ + "python-wrapper/tests/", + "--include-neo4j-and-gds" + ], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true } diff --git a/changelog.md b/changelog.md index 5f4ee7e5..c0996e41 100644 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,7 @@ ## Bug fixes * Fixed a bug with `from_gds` where graphs with different relationship types would fail if they had different properties. +* Fixed a bug with `from_gds` where the additional property would be skipped if its also defined as the size property. ## Improvements diff --git a/python-wrapper/.vscode/settings.json b/python-wrapper/.vscode/settings.json new file mode 100644 index 00000000..00cd182b --- /dev/null +++ b/python-wrapper/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "python.testing.pytestArgs": [ + "tests", + "--include-neo4j-and-gds" + ], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true +} diff --git a/python-wrapper/src/neo4j_viz/gds.py b/python-wrapper/src/neo4j_viz/gds.py index e9d68a72..1600d62d 100644 --- a/python-wrapper/src/neo4j_viz/gds.py +++ b/python-wrapper/src/neo4j_viz/gds.py @@ -148,7 +148,10 @@ def from_gds( if size_property is not None: if "size" in all_actual_node_properties and size_property != "size": node_props_df.rename(columns={"size": "__size"}, inplace=True) - node_props_df.rename(columns={size_property: "size"}, inplace=True) + if size_property not in additional_node_properties: + node_props_df.rename(columns={size_property: "size"}, inplace=True) + else: + node_props_df["size"] = node_props_df[size_property] for lbl, df in node_dfs.items(): if "labels" in all_actual_node_properties: diff --git a/python-wrapper/tests/test_gds.py b/python-wrapper/tests/test_gds.py index 528b8742..3de38225 100644 --- a/python-wrapper/tests/test_gds.py +++ b/python-wrapper/tests/test_gds.py @@ -196,14 +196,28 @@ def test_from_gds_mocked(mocker: MockerFixture) -> None: G = Graph() # type: ignore[call-arg] VG = from_gds( - gds, G, size_property="score", additional_node_properties=["component"], node_radius_min_max=(3.14, 1337) + gds, + G, + size_property="score", + additional_node_properties=["component", "score"], + node_radius_min_max=(3.14, 1337), ) assert len(VG.nodes) == 3 assert sorted(VG.nodes, key=lambda x: x.id) == [ - 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))), + Node( + id=0, + caption="['A']", + size=float(1337), + properties=dict(labels=["A"], component=float(1), score=float(1337)), + ), + Node(id=1, caption="['C']", size=float(42), properties=dict(labels=["C"], component=float(4), score=float(42))), + Node( + id=2, + caption="['A', 'B']", + size=float(3.14), + properties=dict(labels=["A", "B"], component=float(2), score=float(3.14)), + ), ] assert len(VG.relationships) == 3