Ignore self-loops and parallel edges when reading edge list
What is the expected enhancement?
I want to read an edge list (e.g. using PyGraph.read_edge_list) and make sure that the returned graph contains no self-loops and no parallel edges. Since PyGraph.read_edge_list is static, PyGraph(multigraph=False).read_edge_list cannot work.
I'm willing to work on a PR for this. Before writing code however, I wanted to check that I didn't miss something functionality of the library. I see three ways this could be handled:
- Add flags to the
read_edge_listmethod. - Make
read_edge_listnot static and use_add_edge. This doesn't currently address self-loops, but a flag similar tomultigraphcould be added to_add_edgeand the constructor ofPyGraph. - Create new methods
remove_self_loopsandto_graph(need to find better name) that remove self-loops and parallel edges, respectively.
Personally, I don't like option 1. I'm not sure if option 1 or 2 (or both?) is best: they both provide functionality useful outside this specific use case.
Optional named arguments from Option 1 are the best solution. If I had to pick an option it would be that one, I would approve a PR if you submitted that
With that being said remove_self_loops sounds like a potentially useful method. The to_graph method should already exist?