Browse files

Merge pull request #302 from xrotwang/igraph

igraph py2 compatibility
  • Loading branch information...
LinguList committed Jul 1, 2017
2 parents 10b79e9 + 704e18b commit 0db88d18cc8e4ae1e13cb7e574e993e9d5dec7b6
Showing with 9 additions and 3 deletions.
  1. +9 −3 lingpy/convert/
@@ -2,7 +2,8 @@
Conversion routines for the GML format.
from __future__ import unicode_literals, print_function, division
from six import text_type
from six import text_type, PY2
from lingpy import log
from lingpy import util
@@ -24,10 +25,15 @@ def networkx2igraph(graph):
newgraph = ig.Graph(directed=graph.is_directed())
nodes = {}
for i,(node, data) in enumerate(graph.nodes(data=True)):
newgraph.add_vertex(i,Name=node, **dict([(a,b) for a,b in data.items()
if a not in ['Name','name']]))
data = {a.encode() if PY2 else a: b for a, b in data.items()}
**{a: b for a, b in data.items()
if a not in [b'Name', b'name', 'Name', 'name']})
nodes[node] = i
for node1, node2, data in graph.edges(data=True):
data = {a.encode() if PY2 else a: b for a, b in data.items()}
newgraph.add_edge(nodes[node1], nodes[node2], **data)
return newgraph

0 comments on commit 0db88d1

Please sign in to comment.