Repository navigation
Proposal: Add density to nx.describe defaults. - #8569
Merged
Merged
Conversation
dschult
reviewed
Mar 16, 2026
| else: | ||
| info["Number of connected components"] = nx.number_connected_components(G) | ||
| # Add density after number of components | ||
| info["Density"] = nx.density(G) |
Member
There was a problem hiding this comment.
We already have the number of edges (m) and number of nodes (n), so the density is a simple formula of those m/(n * (n - 1)). But we'd have to change the formula for directed case. And we should only do this if performance is at all a concern for the describe method -- which it probably isn't. But I wanted to bring it up.
Contributor
Author
There was a problem hiding this comment.
I had been thinking the same exact thing :) - I landed on minimizing the changes to describe instead of implementing the formula from scratch using the already-extracted m and n values. Happy to change tacks if others feel strongly!
amcandio
approved these changes
Mar 18, 2026
mcbosch
pushed a commit
to mcbosch/networkx
that referenced
this pull request
Apr 7, 2026
Add density to nx.describe defaults.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I propose to add
nx.densityto the list of default properties reported innx.describe. Of course, it's already possible to get the density by explicitly passing it in via the property hooks. I think it's worth being included as a default property though: it's relatively cheap to compute and provides valuable information. For example, if you were a user considering converting to an adjacency matrix, you might look at the density to quickly decide whether a sparse or dense representation made more sense.Anyways - this is purely subjective; happy to close if a lighter
describeoutput is preferred!