Graph.write_graphml does not store tuple attributes in python-igraph 0.6
Bug #918138 reported by
Dominik Landtwing
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
igraph |
Triaged
|
Medium
|
Tamás Nepusz |
Bug Description
Tuple graph, vertex and edge attributes are not stored when exported to GraphML (I don't know about other formats) in python-igraph 0.6 (0.5 works fine).
See the attachment for a minimal example.
Changed in igraph: | |
status: | New → Confirmed |
assignee: | nobody → Tamás Nepusz (ntamas) |
importance: | Undecided → Medium |
Changed in igraph: | |
status: | Confirmed → Triaged |
Changed in igraph: | |
milestone: | none → 0.6 |
Changed in igraph: | |
milestone: | 0.6 → 0.6.1 |
To post a comment you must log in.
Okay, so this is actually a result of trying to bring the GraphML exporter closer to the GraphML specification. According to the GraphML Primer ( http:// graphml. graphdrawing. org/primer/ graphml- primer. html#Attributes ), "[t]he type of the GraphML-Attribute can be either boolean, int, long, float, double, or string". Since tuples are neither of these, igraph simply ignores tuple vertex/edge attributes.
More precisely:
- If all the attribute values for a given attribute are strings or None, igraph assumes that the GraphML type of the attribute will be "string".
- If all the attribute values for a given attribute are numeric or None, igraph assumes that the GraphML type of the attribute will be "double".
- In all other cases, igraph ignores the attribute.
Before igraph 0.6, the rules were as follows:
- If all the attribute values for a given attribute were numeric or None, igraph assumed that the GraphML type of the attribute will be "double".
- In all other cases, igraph assumed the attribute values to be strings but wrapped the values in a str(...) call to ensure that they are actually strings. Tuples were then stored as strings and loaded back as strings, which was confusing for some of the users.
The solution is probably to pickle the attribute values for non-numeric and non-string attributes before saving the GraphML file and unpickle them after loading (since pickled attribute values can simply be stored as strings). Alternatively, one could use the "repr" function to store the attributes and the "eval" function to load them back, which would not work for all Python data types but would provide a human-readable representation of tuples (unlike pickling). Would this solution suit you?