Skip to content

Revert breaking change to node_link_* link defaults - #7652

Merged
dschult merged 8 commits into
networkx:mainfrom
rossbar:node-link-warning
Sep 29, 2024
Merged

dschult merged 8 commits into
networkx:mainfrom
rossbar:node-link-warning

Conversation

@rossbar

@rossbar rossbar commented Sep 26, 2024

Copy link
Copy Markdown
Contributor

Follow-up to #7565

One of the changes in #7565 was to change the default value for the edges (cf. link) parameter from "links" to the more networkx-y "edges". At the time of the discussion, this was recognized as a breaking change, but the consensus (including my own opinion) was that it was better to get all of the changes in now rather than have multiple deprecation cycles.

However, this change did lead to a break downstream in nx-guides, which can be interpreted as a proxy for how disruptive any change might be in user-code. Essentially, changing the default without warning will affect any user attempting to read saved graphs saved in node_link format with the default edge values. Given this, I do now think a deprecation cycle is a good idea - not only does it avoid breakage in all existing code that relies on default values, but there's also a way to provide users with a "fixable" warning; i.e. a recommended change that will make the code more explicit and be forward-compatible. Here's a quick example of what this proposal looks like:

>>> G = nx.Graph([(1, 2)])
>>> data = nx.node_link_data(G)  # Relying on default value for `link` raises a FutureWarning
The default value will be `edges="edges" in NetworkX 3.6.

To make this warning go away, explicitly set the edges kwarg, e.g.:

  nx.node_link_data(G, edges="links") to preserve current behavior, or
  nx.node_link_data(G, edges="edges") for forward compatibility.

>>> data = nx.node_link_data(G, edges="edges")  # Explicitly specifying `edges` silences the warning 

The downside here is that this warning is a lot more noisy than the DeprecationWarning, as it is emitted whenever the function is called with the default value for link. However, I think this noisiness is just a consequence of changing a default in the API - in other words I don't see a good way around it. We can either raise a noisy warning (with a proposed fix that will make the warning go away) or we just break user code.

The only other alternative I could think of was to continue with the current plan (i.e. don't warn) and add special-casing logic for certain values of edges/links to raise specific exceptions that clearly state what the issue is (right now, users get a generic KeyError). IMO though, if you're going to raise special exceptions for the same special cases, you might as well warn instead and give users an opportunity to avoid the exception.

@dschult

dschult commented Sep 27, 2024

Copy link
Copy Markdown
Member

I like the noisy-warning-with-fix approach.
Thanks @rossbar !

@dschult
dschult merged commit 4eea2d6 into networkx:main Sep 29, 2024
@jarrodmillman jarrodmillman added this to the 3.4 milestone Sep 29, 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