def relabel_gexf_graph(G):
 try:
  mapping = [(u, G.node[u]['label']) for u in G]
 except KeyError:
  raise nx.NetworkXError('Failed to relabel nodes: missing node labels found. Use relabel=False.')
 (x, y) = zip(*mapping)
 if (len(set(y)) != len(G)):
  raise nx.NetworkXError('Failed to relabel nodes: duplicate node labels found. Use relabel=False.')
 mapping = dict(mapping)
 H = nx.relabel_nodes(G, mapping)
 for n in G:
  m = mapping[n]
  H.node[m]['id'] = n
  H.node[m].pop('label')
  if ('pid' in H.node[m]):
   H.node[m]['pid'] = mapping[G.node[n]['pid']]
  if ('parents' in H.node[m]):
   H.node[m]['parents'] = [mapping[p] for p in G.node[n]['parents']]
 return H

def relabel_gexf_graph ( G ) : try : mapping = [ ( u , G . node [ u ] [ 'label' ] ) for u in G ] except KeyError : raise nx . NetworkXError ( 'Failed to relabel nodes: missing node labels found. Use relabel=False.' ) ( x , y ) = zip ( * mapping ) if ( len ( set ( y ) ) != len ( G ) ) : raise nx . NetworkXError ( 'Failed to relabel nodes: duplicate node labels found. Use relabel=False.' ) mapping = dict ( mapping ) H = nx . relabel_nodes ( G , mapping ) for n in G : m = mapping [ n ] H . node [ m ] [ 'id' ] = n H . node [ m ] . pop ( 'label' ) if ( 'pid' in H . node [ m ] ) : H . node [ m ] [ 'pid' ] = mapping [ G . node [ n ] [ 'pid' ] ] if ( 'parents' in H . node [ m ] ) : H . node [ m ] [ 'parents' ] = [ mapping [ p ] for p in G . node [ n ] [ 'parents' ] ] return H
relabel graph using "label" node keyword for node label .