ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 23 Feb 2017 05:57:39 -0600to_directed() affects original graphhttps://ask.sagemath.org/question/36705/to_directed-affects-original-graph/ I've stumbled on what I think is a bug. When you create a directed graph from some original graph and then making changes on the new, this can affect the old one. I'm not sure if it should be like this and one should always copy the graph first. Here's a minimal example that for be gives an error "KeyError: 0".
G1=graphs.RandomGNP(5,0.5)
G1.plot(save_pos=True)
G2=G1.to_directed()
G2.delete_vertex(0)
G2.add_vertex(5)
G2.plot()
G1.plot()Thu, 23 Feb 2017 04:27:23 -0600https://ask.sagemath.org/question/36705/to_directed-affects-original-graph/Answer by kcrisman for <p>I've stumbled on what I think is a bug. When you create a directed graph from some original graph and then making changes on the new, this can affect the old one. I'm not sure if it should be like this and one should always copy the graph first. Here's a minimal example that for be gives an error "KeyError: 0".</p>
<pre><code>G1=graphs.RandomGNP(5,0.5)
G1.plot(save_pos=True)
G2=G1.to_directed()
G2.delete_vertex(0)
G2.add_vertex(5)
G2.plot()
G1.plot()
</code></pre>
https://ask.sagemath.org/question/36705/to_directed-affects-original-graph/?answer=36707#post-id-36707What is **REALLY** weird about this is that the plotting itself seems to cause the problem! [The documentation](http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/graph.html#sage.graphs.graph.Graph.to_directed) gives no clue that there should be side effects, so I've opened [Trac 22424](https://trac.sagemath.org/ticket/22424).
Edit: There is already (!) a patch up, which with a little luck will be ready for merging soon.Thu, 23 Feb 2017 05:57:39 -0600https://ask.sagemath.org/question/36705/to_directed-affects-original-graph/?answer=36707#post-id-36707