Fix handling of index holes in PyDiGraph pickling #116
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit fixes an issue with pickling (and by extension deepcopy)
PyDiGraph or PyDAG objects that have holes in their node id lists.
Previously the node ids would not be preserved across pickling leading
to a compacted list instead of the original node ids. For example, if
you had a PyDiGraph with node ids
[0, 1, 3]
after pickling/deepcopy thenode ids would be
[0, 1, 2]
but otherwise identical. This commit fixesthis issue by adding a check for holes to
__setstate__
method andincrementing the node id to reproduce a 1:1 mapping with the original
node ids prior to pickling.