Repository navigation
Fix draw_networkx_nodes return type - #7685
Conversation
|
This behavior was introduced in #7570, maybe @mjschwenne can review this? |
dschult
left a comment
There was a problem hiding this comment.
It looks like the original return was commented out with the axis returned instead.
There might be a reason, or it might have been for debugging something else and not replaced.
Meanwhile the new tests are failing, but I hope it is just a missing input arg.
| # nodes | ||
| nodes = nx.draw_networkx_nodes(G) | ||
| assert isinstance(nodes, PathCollection) | ||
| # edges | ||
| edges = nx.draw_networkx_edges(dG, arrows=True) | ||
| assert isinstance(edges, list) | ||
| if len(edges) > 0: | ||
| assert isinstance(edges[0], FancyArrowPatch) | ||
| edges = nx.draw_networkx_edges(dG, arrows=False) | ||
| assert isinstance(edges, LineCollection) | ||
| edges = nx.draw_networkx_edges(dG, arrows=None) | ||
| assert isinstance(edges, LineCollection) | ||
| edges = nx.draw_networkx_edges(G, arrows=True) |
There was a problem hiding this comment.
| # nodes | |
| nodes = nx.draw_networkx_nodes(G) | |
| assert isinstance(nodes, PathCollection) | |
| # edges | |
| edges = nx.draw_networkx_edges(dG, arrows=True) | |
| assert isinstance(edges, list) | |
| if len(edges) > 0: | |
| assert isinstance(edges[0], FancyArrowPatch) | |
| edges = nx.draw_networkx_edges(dG, arrows=False) | |
| assert isinstance(edges, LineCollection) | |
| edges = nx.draw_networkx_edges(dG, arrows=None) | |
| assert isinstance(edges, LineCollection) | |
| edges = nx.draw_networkx_edges(G, arrows=True) | |
| pos = nx.spring_layout(G) | |
| # nodes | |
| nodes = nx.draw_networkx_nodes(G, pos) | |
| assert isinstance(nodes, PathCollection) | |
| # edges | |
| edges = nx.draw_networkx_edges(dG, pos, arrows=True) | |
| assert isinstance(edges, list) | |
| if len(edges) > 0: | |
| assert isinstance(edges[0], FancyArrowPatch) | |
| edges = nx.draw_networkx_edges(dG, pos, arrows=False) | |
| assert isinstance(edges, LineCollection) | |
| edges = nx.draw_networkx_edges(dG, pos, arrows=None) | |
| assert isinstance(edges, LineCollection) | |
| edges = nx.draw_networkx_edges(G, pos, arrows=True) |
|
I don't remember there being any specific reason I changed the return type on this function. I suspect that it was to help with generating images in a jupyter notebook but I'm not sure. Reverting the return type to what's promised in the doc string and what has been used historically by this function is a good idea. Technically if we wanted to keep the change (which we don't) we'd need a deprecation cycle I think that since that didn't happen the change was never met to be permanent. |
Updated the tests so that they don't fail anymore.
For more context, this came to my attention because some plotting functions in a software I maintain are built using |
mjschwenne
left a comment
There was a problem hiding this comment.
Thanks for the catch and test to make sure it doesn't happen again
dschult
left a comment
There was a problem hiding this comment.
Thanks @kbonney!!
And thanks @mjschwenne
This PR addresses #7684 by returning the collection object rather than axis object in
draw_networkx_nodes. Additional tests are added to check that the return types ofdraw_networkx_nodesanddraw_networkx_edgesreturn expected types.