Graph.write_graphml does not store tuple attributes in python-igraph 0.6

Bug #918138 reported by Dominik Landtwing
6
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.

Revision history for this message
Dominik Landtwing (d-landtwing) wrote :
summary: - Graph.write_graphml does not store tuple attributes in python-igraph 1.6
+ Graph.write_graphml does not store tuple attributes in python-igraph 0.6
description: updated
description: updated
Tamás Nepusz (ntamas)
Changed in igraph:
status: New → Confirmed
assignee: nobody → Tamás Nepusz (ntamas)
importance: Undecided → Medium
Revision history for this message
Tamás Nepusz (ntamas) wrote :

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?

Revision history for this message
Dominik Landtwing (d-landtwing) wrote :

Thanks for your explanations and suggestions.

I think both solutions are fine and both have their advantages and drawbacks. I'm okay with any solution that works. I'd even be okay with the current implementation except that I would expect a warning log message when attributes are ignored.

The only reason for submitting this bug report was that the behaviour changed from 0.5 to 0.6 and it was not immediately obvious (to me as a developer) what went wrong and where it did. I think in those cases it would be helpful to give feedback to developers via exceptions or warnings or similar.

Tamás Nepusz (ntamas)
Changed in igraph:
status: Confirmed → Triaged
Tamás Nepusz (ntamas)
Changed in igraph:
milestone: none → 0.6
Tamás Nepusz (ntamas)
Changed in igraph:
milestone: 0.6 → 0.6.1
Revision history for this message
Tamás Nepusz (ntamas) wrote :

Postponed till 0.7 because it requires API changes in the attribute handler interface.

Changed in igraph:
milestone: 0.6.4 → 0.7
Revision history for this message
Gábor Csárdi (gabor.csardi) wrote : Continue on github

The development of igraph has moved to github, so please do not comment on this bug here. You are of course welcome to comment on github, here:
https://github.com/igraph/igraph/issues/221

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.