Skip to content

Commit

Permalink
Copy node attrs and check for existance when splitting graphs (#13)
Browse files Browse the repository at this point in the history
handle missing edge attributes in splitting
  • Loading branch information
leifdenby authored May 21, 2024
1 parent bb368b6 commit 6f93794
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/weather_model_graphs/networkx_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ def split_graph_by_edge_attribute(graph, attr):
f"No subgraphs were created. Check the edge attribute '{attr}'."
)

# copy node attributes
for subgraph in subgraphs.values():
for node in subgraph.nodes:
subgraph.nodes[node].update(graph.nodes[node])

# check that at least one subgraph was created
if len(subgraphs) == 0:
raise ValueError(
f"No subgraphs were created. Check the edge attribute '{attr}'."
)

return subgraphs


Expand Down

0 comments on commit 6f93794

Please sign in to comment.