From 52bfedcc6f414b306cd3e97e095b19aa4abddd12 Mon Sep 17 00:00:00 2001 From: Jordao Bragantini Date: Fri, 30 Aug 2024 14:24:27 -0400 Subject: [PATCH 1/2] improving error message when wrong frame is provided --- motile/track_graph.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/motile/track_graph.py b/motile/track_graph.py index 91db5fb..f341ec9 100644 --- a/motile/track_graph.py +++ b/motile/track_graph.py @@ -120,6 +120,7 @@ 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: @@ -127,6 +128,14 @@ def add_from_nx_graph(self, nx_graph: networkx.DiGraph) -> None: 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 given `nx_graph`.\n" + "It's very likely the wrong `frame_attribute` was set." + ) # add all edges and hyperedges for (u, v), data in nx_graph.edges.items(): From 221b689798ca574e0accd64209f0159c22ff0819 Mon Sep 17 00:00:00 2001 From: Jordao Bragantini Date: Fri, 30 Aug 2024 14:31:21 -0400 Subject: [PATCH 2/2] fix line length --- motile/track_graph.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/motile/track_graph.py b/motile/track_graph.py index f341ec9..228c840 100644 --- a/motile/track_graph.py +++ b/motile/track_graph.py @@ -133,8 +133,8 @@ def add_from_nx_graph(self, nx_graph: networkx.DiGraph) -> None: # 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 given `nx_graph`.\n" - "It's very likely the wrong `frame_attribute` was set." + 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