Hi,
I have some graphml files which come from graph-tool and they have properties which networkx cannot read. The properties are node positions- a list of floats- and it seems list types are not supported by networkx graphml at all (reading or writing).
This is what I get when I try to write a list type to graphml
G=nx.Graph()
G.add_node(1, pos=[1,2])
nx.write_graphml(G, '/tmp/g.xml')
networkx/readwrite/graphml.py in add_data(self, name, element_type, value, scope, default)
241 if element_type not in self.xml_type:
242 raise nx.NetworkXError('GraphML writer does not support '--> 243 '%s as data values.'%element_type)
244 key_id = self.get_key(name, self.xml_type[element_type], scope, default)
245 data_element = Element("data", key=key_id)
NetworkXError: GraphML writer does not support <type 'list'> as data values.
And the graphml file I would like read looks something like this:
<!-- property keys --> <key id="key0" for="node" attr.name="centrality" attr.type="int" />
<key id="key1" for="node" attr.name="pos" attr.type="vector_float" /> <graph id="G" edgedefault="undirected" parse.nodeids="canonical" parse.edgeids="canonical" parse.order="nodesfirst">
<!-- graph properties -->
<!-- vertices -->
<node id="n0">
<data key="key0">2</data>
<data key="key1">0x1.54206f8b25c6cp+3, 0x1.489af2ba23c76p+3</data>
</node>
So the 'pos' attribute is a 2d list of floats with type 'vector_double'.
and when I try to read this I get:
networkx/readwrite/graphml.py in find_graphml_keys(self, graph_element)
512 graphml_keys[attr_id] = {--> 514 "type":self.python_type[attr_type],
516 # check for "default" subelement of key element
graph-tool (http://projects.skewed.de/graph-tool/) seems to read/write only graphml, so the easiest solution for me would be if networkx could read/write these graphml attributes properly. I'm happy to have a look at it myself, but I would appreciate some guidance on what's the best way to go about adding this support.
thanks
-