Skip to content

Commit

Permalink
Merge pull request #120 from JoOkuma/wrong-frame-attribute
Browse files Browse the repository at this point in the history
Improving error message when wrong frame is provided
  • Loading branch information
cmalinmayor authored Sep 26, 2024
2 parents 4d14bd6 + d445bc1 commit ba6e4f5
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions motile/track_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,22 @@ def add_from_nx_graph(self, nx_graph: networkx.DiGraph) -> None:
or edges do already exist, the values set in the given ``nx_graph``
will be updating the previously set values.
"""
nodes_count = 0
# add all regular nodes (all but ones representing hyperedges)
for node, data in nx_graph.nodes.items():
if self.frame_attribute in data:
if node not in self.nodes:
self.nodes[node] = data
else:
self.nodes[node] |= data
nodes_count += 1

# graph without nodes, it's very likely this was not intentional
if nodes_count == 0:
raise KeyError(
f"No nodes with `frame_attribute` '{self.frame_attribute}' found in "
"the `nx_graph`.\nIt's likely the wrong `frame_attribute` was set."
)

# add all edges and hyperedges
for (u, v), data in nx_graph.edges.items():
Expand Down

0 comments on commit ba6e4f5

Please sign in to comment.