Skip to content

FEAT: Add a describe method for some basic info about graphs - #8338

Merged
rossbar merged 2 commits into
networkx:mainfrom
MridulS:nx_describe
Nov 14, 2025
Merged

rossbar merged 2 commits into
networkx:mainfrom
MridulS:nx_describe

Conversation

@MridulS

@MridulS MridulS commented Nov 5, 2025

Copy link
Copy Markdown
Member

Fixes #5326

I think 3 years is the perfect time to get this done 😄

This adds a new function which computes some couple of stats as proposed in #5326, users can also hook into the describe function if they want to calculate more properties.

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

Nice!! :)
I like the ability to add your own description functions 🎉

Should this function return the info_dict? Then users can add/remove.

Or should we allow removal of some from the default report? Something like a kwarg show_hook_without_defaults=False. Or another option would be a kwarg that doesn't print and returns the info_dict. Okay! Just Stop Dan! :}

Maybe make the private helper function public?

Comment thread networkx/classes/function.py Resolved
Comment thread networkx/classes/function.py Resolved
Comment thread networkx/classes/function.py Resolved
self.DGnodes = list(range(5))
self.DGedges = [(0, 1), (0, 2), (0, 3), (1, 0), (1, 1), (1, 2)]

def test_describe_info_dict(self):

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.

@dschult dschult Nov 6, 2025 •

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.

I think the doc_string acts to test the exact format of the output.
So in this case we might not need to test by capturing stdout.
I feel like the doc_strings are an integral part of our test suite.
If others feel like stdout should be tested in both places I'm willing to back off on this.

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.

Yeah, I was also using the doctest as the test for testing the print logic.

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

LGTM, thanks @MridulS

I'm happy to merge, but we're currently in the rc phase so if we do so now it'll be in 3.6 but not the RC. I don't think that's that big of a deal, but just pointing it out!

@dschult

dschult commented Nov 8, 2025

Copy link
Copy Markdown
Member

I dont see any problem with adding a new function to the release that is not in the RC. Will that mess up anything? It will still appear in the release notes right? It won't mix up any users because it is adding something --- not changing/removing. So as long as this doesn't mess up maintenance or release processes I would say we are good to go.

@rossbar

rossbar commented Nov 14, 2025

Copy link
Copy Markdown
Contributor

Okay, this one looks ready - thanks @MridulS @amcandio and @dschult !

@rossbar
rossbar merged commit 6dbed05 into networkx:main Nov 14, 2025
@dschult dschult added this to the 3.6 milestone Nov 14, 2025
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.

nx.info() no longer informative

4 participants