when attempting to visualize a graph component that has zero edges or zero nodes using wmg.visualise.nx_draw_with_pos_and_attr, the system crashes with an IndexError.
This frequently occurs in practice when plotting subgraphs returned by filter_graph() or split_graph_by_edge_attribute() if a particular split happens to have nodes but no edges (or vice versa).
import networkx as nx
import weather_model_graphs as wmg
G = nx.DiGraph()
G.add_node(0, pos=[1.0, 2.0], type='mesh')
# crashes with IndexError instead of silently skipping edge coloring
wmg.visualise.nx_draw_with_pos_and_attr(G, edge_color_attr='len')
IndexError: list index out of range
... at _get_graph_attr_values(g, attr_name, component="edges")
features = list(g.edges(data=True))[0][2].keys()
when attempting to visualize a graph component that has zero edges or zero nodes using
wmg.visualise.nx_draw_with_pos_and_attr, the system crashes with anIndexError.This frequently occurs in practice when plotting subgraphs returned by
filter_graph()orsplit_graph_by_edge_attribute()if a particular split happens to have nodes but no edges (or vice versa).IndexError: list index out of range
... at _get_graph_attr_values(g, attr_name, component="edges")
features = list(g.edges(data=True))[0][2].keys()