Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

## Bug fixes

* fixed a bug in `from_neo4j`, where by default the node size would always be set if a `size` property was set on the node.
Comment thread
FlorentinD marked this conversation as resolved.
Outdated


## Improvements

Expand Down
4 changes: 2 additions & 2 deletions python-wrapper/src/neo4j_viz/neo4j.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def from_neo4j(
else:
raise ValueError(f"Invalid input type `{type(data)}`. Expected `neo4j.Graph`, `neo4j.Result` or `neo4j.Driver`")

all_node_field_aliases = Node.all_validation_aliases()
all_rel_field_aliases = Relationship.all_validation_aliases()
all_node_field_aliases = Node.all_validation_aliases(exempted_fields=["size", "caption"])
all_rel_field_aliases = Relationship.all_validation_aliases(exempted_fields=["caption"])

try:
nodes = [
Expand Down
57 changes: 57 additions & 0 deletions python-wrapper/tests/test_neo4j.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,63 @@ def test_from_neo4j_graph_basic(neo4j_session: Session) -> None:
]


@pytest.mark.requires_neo4j_and_gds
def test_from_neo4j_graph_default_size(neo4j_session: Session) -> None:
# set a non parsable size property, by default it should not be picked up
neo4j_session.run("MATCH (n) SET n.size = 'banana' SET n.real_caption = 'my_caption' SET n.real_size = 4")

graph = neo4j_session.run("MATCH (a:_CI_A|_CI_B)-[r]->(b) RETURN a, b, r ORDER BY a").graph()

VG = from_neo4j(graph, size_property="real_size", node_caption="real_caption", node_radius_min_max=None)

sorted_nodes: list[neo4j.graph.Node] = sorted(graph.nodes, key=lambda x: dict(x.items())["name"])
node_ids: list[str] = [node.element_id for node in sorted_nodes]

expected_nodes = [
Node(
id=node_ids[0],
caption="my_caption",
size=4,
properties=dict(
labels=["_CI_A"],
name="Alice",
size="banana",
real_size=4,
real_caption="my_caption",
height=20,
id=42,
_id=1337,
caption="hello",
),
),
Node(
id=node_ids[1],
caption="my_caption",
size=4,
properties=dict(
labels=["_CI_A", "_CI_B"],
name="Bob",
size="banana",
real_size=4,
real_caption="my_caption",
height=10,
id=84,
__labels=[1, 2],
),
),
]

assert len(VG.nodes) == 2
assert sorted(VG.nodes, key=lambda x: x.properties["name"]) == expected_nodes

assert len(VG.relationships) == 2
vg_rels = sorted([(e.source, e.target, e.caption) for e in VG.relationships], key=lambda x: x[2] if x[2] else "foo")
assert vg_rels == [
(node_ids[0], node_ids[1], "KNOWS"),
(node_ids[1], node_ids[0], "RELATED"),
]


@pytest.mark.requires_neo4j_and_gds
def test_from_neo4j_result(neo4j_session: Session) -> None:
result = neo4j_session.run("MATCH (a:_CI_A|_CI_B)-[r]->(b) RETURN a, b, r ORDER BY a")
Expand Down