Skip to content

Add edges keyword/deprecate link keyword arguments in JSON input-output - #7565

Merged
dschult merged 6 commits into
networkx:mainfrom
bakhtos:feature-add-edges-keyword
Sep 6, 2024
Merged

dschult merged 6 commits into
networkx:mainfrom
bakhtos:feature-add-edges-keyword

Conversation

@bakhtos

@bakhtos bakhtos commented Jul 16, 2024

Copy link
Copy Markdown
Contributor

Following the discussion in #7532, this PR does the following:

  • New keyword argument edges is introduced to JSON reading/writing functions
  • Previous keyword argument link is deprecated
  • Functions raise ValueError if both are provided
  • Functions raise DeprecationWarning if link is provided

In the second commit, the actual default value for edges is set to "edges" instead of "links".
I am not sure if the idea was to chage it now or maintain backwards compatibility of scripts that might use default values.

@rossbar rossbar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and pushed up a few changes to get the tests passing etc. I left the logic for how the old/new kwargs are handled untouched as I think it's a sensible path forward.

In practice, this does change behavior... the defaults for node_link_data and node_link_graph now produce/expect attributes named "edges" instead of "links". The behavior change is most clearly illustrated in the test in c519175, which had to be modified to get these changes passing.

I'm okay with this breakage. In principle this will affect users who are using these functions to dump serialized graph data to disk with networkx <3.5, then trying to load them with networkx >=3.5. Even then, the behavior of reading the "old" files would still be recoverable by adding edges="links" when calling node_link_graph. This should be documented in the release notes, but I'm willing to add the breakage now rather than having to do two separate deprecation cycles (one for removing the link arg, and another for changing the default value of edges from "links" -> "edges").

All that's to say: +1 from me for this course of action! Thanks @bakhtos !

@dschult dschult added this to the 3.4 milestone Sep 6, 2024

@dschult dschult left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rossbar for checking through the deprecation implications, pushing up the doctest changes and t he test changes. :) Thanks @bakhtos for the PR!

@dschult
dschult merged commit 24d3fe7 into networkx:main Sep 6, 2024
rossbar added a commit to Peiffap/networkx that referenced this pull request Sep 6, 2024
…t-output (networkx#7565)

* deprecate `link` kwarg

* change default value to `edges`

* Update docstring deprecation warnings.

* Update doctests.

* Always warn when link is used, add comments for future removal.

* Modify test to capture default behavior change.

---------

Co-authored-by: Ross Barnowski <[email protected]>
rossbar added a commit to rossbar/nx-guides that referenced this pull request Sep 7, 2024
MridulS pushed a commit to networkx/nx-guides that referenced this pull request Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants