pombreda / pydot

Automatically exported from code.google.com/p/pydot
MIT License
0 stars 0 forks source link

get_node_list returns empty list on graphs with more than one node! #13

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

edges=[('1','2'), ('1','3'), ('1','4'), ('3','4')] 
g=pydot.graph_from_edges(edges) 
nodes = g.get_node_list()
print len(nodes)

What is the expected output? What do you see instead?
Should see 4, get 0
Note that if you have a graph with only one node, you do get a one element list

What version of the product are you using? On what operating system?
1.0.2 on windows with python 2.5

Please provide any additional information below.

Original issue reported on code.google.com by stevenso...@gmail.com on 9 May 2008 at 9:21

GoogleCodeExporter commented 9 years ago
The method: graph_from_edges() is broken. It only updates the edge_list. It 
doesn't update the node_list. 

If you change your code to build your own nodes and edges using 
graph.add_node() and graph.add_edge() then 
everything behaves properly.

Original comment by adewale on 5 Jun 2009 at 1:53

GoogleCodeExporter commented 9 years ago
I've attached a patch, with tests, which fixes this issue. It checks that when 
building a graph using 
pydot.graph_from_edges() we add the nodes into the graph if they haven't 
already been added.

It might be a better idea to change the add_edge method so that it always adds 
the 2 nodes if they don't already 
exist. However that's a change with more side-effects and I didn't want to risk 
it in my first patch to the project.

Consequently this patch only fixes one of the convenience methods for building 
a graph. The other convenience 
methods will all still exhibit the same bug.

Original comment by adewale on 6 Jun 2009 at 1:59

Attachments:

GoogleCodeExporter commented 9 years ago
If one wants Nodes to be created they should be created before the edges, edges 
won't create Nodes.
I admit it's awkward but it was the only way of passing Graphviz's test-set. 
Edges can exist without associated nodes. If the nodes are created whenever 
edges are added the output of pydot will not agree with Graphviz's own parsing.

Original comment by ero.carr...@gmail.com on 30 Oct 2010 at 11:51