Skip to content

Commit 1f6151a

Browse files
authored
Merge pull request #199 from neo4j/fix-gds-size-and-additional-property
fix gds size and additional property
2 parents 8398105 + 14d62cf commit 1f6151a

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

.vscode/settings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
{
22
"python.analysis.extraPaths": [
33
"./python-wrapper/src"
4-
]
4+
],
5+
"python.testing.pytestArgs": [
6+
"python-wrapper/tests/",
7+
"--include-neo4j-and-gds"
8+
],
9+
"python.testing.unittestEnabled": false,
10+
"python.testing.pytestEnabled": true
511
}

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/.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"python.testing.pytestArgs": [
3+
"tests",
4+
"--include-neo4j-and-gds"
5+
],
6+
"python.testing.unittestEnabled": false,
7+
"python.testing.pytestEnabled": true
8+
}

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: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,28 @@ def test_from_gds_mocked(mocker: MockerFixture) -> None:
196196
G = Graph() # type: ignore[call-arg]
197197

198198
VG = from_gds(
199-
gds, G, size_property="score", additional_node_properties=["component"], node_radius_min_max=(3.14, 1337)
199+
gds,
200+
G,
201+
size_property="score",
202+
additional_node_properties=["component", "score"],
203+
node_radius_min_max=(3.14, 1337),
200204
)
201205

202206
assert len(VG.nodes) == 3
203207
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))),
208+
Node(
209+
id=0,
210+
caption="['A']",
211+
size=float(1337),
212+
properties=dict(labels=["A"], component=float(1), score=float(1337)),
213+
),
214+
Node(id=1, caption="['C']", size=float(42), properties=dict(labels=["C"], component=float(4), score=float(42))),
215+
Node(
216+
id=2,
217+
caption="['A', 'B']",
218+
size=float(3.14),
219+
properties=dict(labels=["A", "B"], component=float(2), score=float(3.14)),
220+
),
207221
]
208222

209223
assert len(VG.relationships) == 3

0 commit comments

Comments
 (0)