Repository navigation
Fix docstring example of nx.generate_random_paths(index_map=...) - #7832
Merged
Merged
Conversation
dschult
reviewed
Feb 8, 2025
dschult
left a comment
Member
There was a problem hiding this comment.
This looks good to me.
Why use a dict(enumerate(... instead of a list? Both work in this case (I think). The paths will always be indexed by contiguous ints in index_map right? So would it be better to suggest using list(?
Thanks for this!
Contributor
Author
|
Ha, yeah, I'll change to list. Good catch, my bad! |
| >>> G = nx.star_graph(3) | ||
| >>> index_map = {} | ||
| >>> random_path = nx.generate_random_paths(G, 3, index_map=index_map) | ||
| >>> random_paths = list(nx.generate_random_paths(G, 3, index_map=index_map)) |
Member
There was a problem hiding this comment.
Suggested change
| >>> random_paths = list(nx.generate_random_paths(G, 3, index_map=index_map)) | |
| >>> random_paths = list(nx.generate_random_paths(G, 3, index_map=index_map, seed=42)) |
| ... random_path[path_idx] for path_idx in index_map.get(0, []) | ||
| ... random_paths[path_idx] for path_idx in index_map.get(0, []) | ||
| ... ] | ||
|
|
Member
There was a problem hiding this comment.
Suggested change
| >>> paths_containing_node_0 | |
| [[2, 0, 1, 0, 2, 0], [2, 0, 3, 0, 3, 0], [1, 0, 3, 0, 3, 0]] | |
or we can also display all the random paths.
dschult
approved these changes
Feb 9, 2025
rossbar
approved these changes
Feb 9, 2025
rossbar
left a comment
Contributor
There was a problem hiding this comment.
Thanks @eriknw - let's get this in!
+1 for @Schefflera-Arboricola 's suggestions too, but let's move to a follow-up PR so as not to confuse the approvals!
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.
As discovered in #7817 (comment), the docstring example with using
index_mapis incorrect, because it was trying to index into a generator.This argument is a little awkward to use since this function is a generator and
index_mapwill be updated incrementally, but I believe the updated docstring example is what was intended.