Skip to content

Bug: list index out of range (IndexError) when visualising an empty subgraph #130

@sudhansu-24

Description

@sudhansu-24

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions