Skip to content

Allow creating subgraphs directly from sets of node indices (e.g., those returned by connected components) #1508

@hakkape

Description

@hakkape

What is the expected enhancement?

Currently, the connected components function returns a list of sets of node indices. If i then try to create a subgraph from each connected component, i get an error because a set is not a sequence. Of course, i can turn the sets into lists or similar first, but this seems unnecessary to me. I find a set a perfectly reasonable container from which to create a subgraph. So the enhancement would be to modify the subgraph function to also accept sets of node indices.

Minimum (currently not working) example:

import rustworkx as rx

# create graph with two connected components
g = rx.PyGraph()
a = g.add_node("A")
b = g.add_node("B")
c = g.add_node("C")
d = g.add_node("D")
g.add_edge(a, b, None)
g.add_edge(c, d, None)
components = rx.connected_components(g)

# create subgraphs 
subgraphs = [g.subgraph(component) for component in components]

(Technically, i would like this modification for directed graph, but it seems sensible for all types)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions