Repository navigation
Fix write_gexf timeformat for dynamic Graphs - #7914
Conversation
When using write_gexf on a Graph containing start/end attributes, the Graph timeformat parameter was not set, breaking compatibility with the gexf standard. This ensures that the timeformat parameter is set in the .gexf <graph> tag.
There was a problem hiding this comment.
The diff is a little hairy, but AFAICT the proposal is basically just to delete the top-level if that checks whether the mode is "static" - this seems reasonable to me, especially since AIUI the start/end/timeformat attrs are only relevant when mode="dynamic".
We'd have to take a deeper look at other parts of the code to see where/whether the mode is set. If there's a minimal example of the buggy behavior, it'd be great to add that as a test!
|
I wasn't in the right environment to publish a minimal example but here it is: import networkx
if __name__ == '__main__':
G = networkx.MultiGraph(mode='dynamic')
G.add_node('U')
G.nodes['U']['start'] = 1
networkx.write_gexf(G,'/tmp/example.gexf')
G = networkx.read_gexf('/tmp/example.gexf')Specifying the Graph mode as 'dynamic' is what causes the buggy behavior. diff /tmp/example.gexf /tmp/example_dynamic_graph_attr.gexf
6c6
< <graph defaultedgetype="undirected" mode="dynamic" name="" timeformat="long">
---
> <graph defaultedgetype="undirected" mode="dynamic" name="">Removing the check fixes that and infers whether the Graph is static or dynamic if a start or end attribute is present. |
|
Thanks @lmeNaN for the example - that makes sense then. Let's go ahead and turn that into a test and I think this is good to go! |
When using write_gexf on a Graph containing start/end attributes, the Graph timeformat parameter was not set, breaking compatibility with the gexf draft. This ensures that the timeformat parameter is set in the .gexf tag.
Before this fix, the .gexf file obtained when using write_gexf on a dynamic graph would not contain a timeformat attribute in the graph tag. This made read_gexf unable to parse the Graph.
After this fix, the timeformat argument for the graph tag is saved on line 6 of the gexf file, ensuring that a dynamic Graph exported through write_gexf can then be loaded again through read_gexf.