Skip to content

maint: use nx.circulant_graph to generate Harary graphs - #8189

Merged
MridulS merged 9 commits into
networkx:mainfrom
Peiffap:maint/harary
Sep 10, 2025
Merged

MridulS merged 9 commits into
networkx:mainfrom
Peiffap:maint/harary

Conversation

@Peiffap

@Peiffap Peiffap commented Aug 8, 2025

Copy link
Copy Markdown
Member

This PR does a few related things:

  • Batch edge addition in nx.circulant_graph.
  • Clean up docstrings for the Harary graph generators.
  • Use nx.circulant_graph in the Harary graph generators + batch edge additions where possible.

Comment thread networkx/generators/classic.py Resolved

@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.

This is a nice bit of cleanup/code reuse, LGTM. Thanks @Peiffap !

Comment thread networkx/generators/harary_graph.py Resolved
Comment thread networkx/generators/harary_graph.py Resolved
@nx._dispatchable(graphs=None, returns_graph=True)
def hnm_harary_graph(n, m, create_using=None):
"""Returns the Harary graph with given numbers of nodes and edges.
r"""Return the Harary graph with given numbers of nodes and edges.

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.

Can you remind me why we need to change this doc_string to raw (with the r in front)?
Is it because we are using latex?

Also, why are we changing Returns to Return? I thought we were moving toward using the gammar Returns on all the doc_strings. Seems like we switch back and forth over the years. Wish we just didn't bother. :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, the raw docstring makes the LaTeX backslash commands render nicely–it's either that or having to escape the backslashes, which makes the docstring harder to read.

The change from Returns to Return is simply to comply with PEP 257, more specifically this bullet:

The docstring is a phrase ending in a period. It prescribes the function or method’s effect as a command (“Do this”, “Return that”), not as a description; e.g. don’t write “Returns the pathname …”.

PEP 257 is the convention linked to in the numpydoc style guide, which we follow (as do NumPy, SciPy, and the scikits). I'm happy to back out the change if you feel strongly, though. :)

@MridulS MridulS added this to the 3.6 milestone Sep 10, 2025
@MridulS
MridulS merged commit 4a20c80 into networkx:main Sep 10, 2025
@Peiffap
Peiffap deleted the maint/harary branch September 10, 2025 19:44
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.

5 participants