Search code examples
pythongraphnetworkxdigraphs

NetworkX MultiDiGraph -- `id` and `key` appearing in edge data attributes?


I'm iterating over edges in a NetworkX MultiDiGraph like so:

for u, v, k, d in g.edges(keys=True, data=True):
    ...

In some instances, I find id and key keys in the dictionary d, but I can't figure out when or why these are created, except that it only happens when u==v.

I have been unable to find a minimal example of what causes this. It seems strange to me that the key k would be duplicated in the attr dict d.


Solution

  • Think this has been solved, I was using nx.readwrite.json_graph.adjacency_graph() to read/write my graphs from JSON. I think it was this step that was adding the id and key values to the edge attr_dict.

    However, I don't know if this is a bug when reading from JSON, or if this is working as intended.