Repository: networkx/networkx

Issue:
relabel_nodes adds a graph attribute when copy=True
I would have expected the following to work:

```
import networkx as nx
graph_a = nx.DiGraph()
graph_b = nx.relabel_nodes(graph_a, {}, copy=True)
print "graph_a.graph", graph_a.graph
print "graph_b.graph", graph_b.graph
assert graph_a.graph == graph_b.graph
```

However, it does not since [_relabel_copy attempts to copy a non-existent graph attribute, 'name'](https://github.com/networkx/networkx/blob/1675a824d6cdb17c3144ef46ff52a0c2b53a11d1/networkx/relabel.py#L150).

I would have expected relabel_nodes to only change the node labels, while maintaining all graph/node/edge attributes.

Discussion:

Patch:
diff --git a/networkx/readwrite/gml.py b/networkx/readwrite/gml.py
index b6ab5e9eb..af8db1d00 100644
--- a/networkx/readwrite/gml.py
+++ b/networkx/readwrite/gml.py
@@ -435,10 +435,6 @@ def parse_gml_lines(lines, label, destringizer):
 
     if label != 'id':
         G = nx.relabel_nodes(G, mapping)
-        if 'name' in graph:
-            G.graph['name'] = graph['name']
-        else:
-            del G.graph['name']
     return G
 
 
diff --git a/networkx/relabel.py b/networkx/relabel.py
index ca069c950..8f885432c 100644
--- a/networkx/relabel.py
+++ b/networkx/relabel.py
@@ -147,7 +147,8 @@ def _relabel_inplace(G, mapping):
 
 def _relabel_copy(G, mapping):
     H = G.__class__()
-    H.name = "(%s)" % G.name
+    if G.name:
+        H.name = "(%s)" % G.name
     if G.is_multigraph():
         H.add_edges_from( (mapping.get(n1, n1),mapping.get(n2, n2),k,d.copy())
                           for (n1,n2,k,d) in G.edges(keys=True, data=True))


Test patch:
diff --git a/networkx/tests/test_relabel.py b/networkx/tests/test_relabel.py
index 682de98a0..65c29eeab 100644
--- a/networkx/tests/test_relabel.py
+++ b/networkx/tests/test_relabel.py
@@ -150,6 +150,17 @@ class TestRelabel():
         mapping={0:'aardvark'}
         G=relabel_nodes(G,mapping,copy=False)
 
+    def test_relabel_copy_name(self):
+        G=Graph()
+        H = relabel_nodes(G, {}, copy=True)
+        assert_equal(H.graph, G.graph)
+        H = relabel_nodes(G, {}, copy=False)
+        assert_equal(H.graph, G.graph)
+        G.name = "first"
+        H = relabel_nodes(G, {}, copy=True)
+        assert_equal(H.graph, G.graph)
+        H = relabel_nodes(G, {}, copy=False)
+        assert_equal(H.graph, G.graph)
 
     def test_relabel_toposort(self):
         K5=nx.complete_graph(4)