Skip to content

Warn users about duplicate nodes in generator function input#6237

Merged
jarrodmillman merged 1 commit intonetworkx:mainfrom
dschult:nodes_or_number
Dec 2, 2022
Merged

Warn users about duplicate nodes in generator function input#6237
jarrodmillman merged 1 commit intonetworkx:mainfrom
dschult:nodes_or_number

Conversation

@dschult
Copy link
Copy Markdown
Member

@dschult dschult commented Nov 25, 2022

As we discussed last summer, some surprising results can occur if you input duplicate nodes in functions that use the nodes_or_number decorator. We decided to leave them in the code (some people might rely on them and they don't seem to be a problem for users).

For example: nx.complete_graph([1, 1]) returns a graph with a self-loop. nx.complete_graph([1, 2, 2, 3, 3, 3]) is the usual complete_graph on 3 nodes with selfloops added for node 2 and 3.

This PR adds a warning to the doc_strings for these functions just so the users have a hint that duplicate nodes in the list of nodes can cause unusual results.

@dschult dschult added this to the networkx-3.0 milestone Nov 25, 2022
Copy link
Copy Markdown
Member

@MridulS MridulS left a comment

Choose a reason for hiding this comment

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

LGTM

@jarrodmillman jarrodmillman merged commit 0a3c25c into networkx:main Dec 2, 2022
MridulS pushed a commit to MridulS/networkx that referenced this pull request Feb 4, 2023
cvanelteren pushed a commit to cvanelteren/networkx that referenced this pull request Apr 22, 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