Skip to content

Track vertex and edge order and multiedge key to/from networkx#408

Closed
iosonofabio wants to merge 3 commits intoigraph:masterfrom
iosonofabio:nx_edgekey
Closed

Track vertex and edge order and multiedge key to/from networkx#408
iosonofabio wants to merge 3 commits intoigraph:masterfrom
iosonofabio:nx_edgekey

Conversation

@iosonofabio
Copy link
Copy Markdown
Member

@iosonofabio iosonofabio commented Jun 1, 2021

Improve conversions to/from networkx by using hidden vertex/edge attributes:

  • _nx_name was already there: it stores the hashable used to identify the vertex in networkx after converting to igraph
  • _nx_multiedge_key keeps track of networkx's edge key, which is used to distinguish multiedges
  • _igraph_index is now set when exporting to networkx to remember the order of vertices/edges in igraph (networkx does not have a strictly enforced order)

The first two attributes are checked on the way back from igraph into networkx to set proper vertex names and edge keys, respectively. The last attribute is used on the way back from networkx to igraph to sort edges according to their original order, or whatever comes closest to that.

Of course, manual manipulations of these attributes by the users can mess up the bookkeeping. That's ok I think, they know what they're getting themselves into since the attribute names start with _ which in Python is lingo for "don't touch!".

An interesting case is if e.g. the user exports an igraph graph to networkx, thins it out by deleting a few edges, and then converts back. Then the order of edges is maintained except the missing edges are skipped, of course.

@szhorvat @ntamas would be great if you could take a look and let me know your thoughts. I've had to adapt CI tests a little, which highlighted some bugs that are now fixed.

edit: I found one more bug. ig -> nx -> delete a vertex -> ig will probably error out. Fixed now.

edit2: There must be a bug when ig -> nx -> add vertices/edges -> ig because the newly added objects cannot have an _igraph_index. They should be defaulted to a (random?) increasing _igraph_index I guess, but that might or might not be deterministic since they were generated in the context of a nondeterministic library...

@stale
Copy link
Copy Markdown

stale bot commented Jul 31, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 31, 2021
@ntamas ntamas added todo Triaged for implementation in some unspecified future version and removed stale labels Jul 31, 2021
iosonofabio added a commit to iosonofabio/python-igraph that referenced this pull request Sep 16, 2021
ntamas added a commit that referenced this pull request Sep 28, 2021
…orkx) (#434)

* First pass, poor docs

* Forgot classmethod decorator

* Some polishing and one more input constructor

* Graph constructor from pandas adjacency matrix

* Move adjacency constructors to module

* Move more constructors to dedicated module

* Clean up namespace at the end

* Small constructor modules

* IO module

* fix: remove licenses from igraph.io, it is enough to have it in __init__.py

* refactor: prefix names of internal functions in igraph.io with an underscore

* refactor: moved _first to igraph.utils

* style: blackened igraph.io source

* Export to dict of sequences

* Recover and refine lost PR on use_vids

* Match export graph functions for dict/list/tuple types

* Include PR #408 in this one

* Docstrings and documentation

* Bugfix on dict-dict

* Implement most of Vincent's suggestions

* Running local tests helps... sigh

* style: nitpicking, probably ready to merge

Co-authored-by: Tamas Nepusz <ntamas@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

todo Triaged for implementation in some unspecified future version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants