Repository navigation
ENH: add directed kwarg to edges_equal - #8192
Conversation
972b317 to
451d94b
Compare
451d94b to
bd6da3f
Compare
f2a8378 to
5761dfd
Compare
5761dfd to
ccde6f0
Compare
rossbar
left a comment
There was a problem hiding this comment.
Generally LGTM, thanks for sorting through the tests to find the instances where directed= was called for! The only one I was surprised by was pajek, which I thought didn't involve directed graphs but I may have read the tests wrong.
| Edge data must match if included. | ||
| The order of the edges is not relevant. | ||
| Equality here means equal as Python objects. Edge data must match | ||
| if included. The order of the edges is not relevant. |
There was a problem hiding this comment.
"order of the edges" is a bit ambiguous in the context... before it was true because both the order of the edge tuples (i.e. (u, v) or (v, u)) and the ordering of the tuples in edges1 or edges2 was irrelevant. Now the former depends on directed. I think the wording may need an additional update to capture the new distinction. Alternatively perhaps we could just remove the sentence and rely on the extensive examples to make clear exactly what is meant.
There was a problem hiding this comment.
I've added some (hopefully) clearer wording. Also happy to just get rid of these sentences and rely on the examples as you've suggested—whatever you decide is best!
| H = nx.read_pajek(fh) | ||
| assert nodes_equal(list(G), list(H)) | ||
| assert edges_equal(list(G.edges()), list(H.edges())) | ||
| assert edges_equal(G.edges(), H.edges(), directed=True) |
There was a problem hiding this comment.
I'm ambivalent about this - AFAICT neither G nor H are actually directed graphs, so the fact that the edge tuples are in the same order after a round trip is really just an implementation detail and not something that needs to be enforced. I'm inclined to leave the directed= out of the pajek tests.
There was a problem hiding this comment.
I went over it again. Everywhere self.G or self.data is used, it should use directed comparisons IMO, as these are directed (self.data has an *arcs marker, which means the graph is directed). Similarly, when the pajek file has a *Matrix marker, the resulting graph defaults to nx.DiGraph.
The unicode test you've commented on seems to be undirected though, so I've removed the directed=True here.
Co-authored-by: Ross Barnowski <[email protected]>
dschult
left a comment
There was a problem hiding this comment.
This looks good!
One change seems like a whitespace change, but I can't tell if maybe there is something else going on there. Otherwise this is ready.
| G.edges(), | ||
| [("A", "B"), ("A", "C"), ("B", "D"), ("C", "B"), ("C", "D")], |
There was a problem hiding this comment.
Is there a change here? Looks like maybe whitespace or clarity of separating G.edges from rest -- but later in test_line.py you leave a longer line with the same structure. Probably nothing important, but I wondered if there is more than whitespace going on here?
There was a problem hiding this comment.
Nothing more than whitespace as far as I can tell...
I think I remember what happened here; I started out with this file and tried to follow the "use edgelists, not lists of edges" pattern wherever edges_equal is used by always relying on the output of a Graph.edges call instead of manually declared lists (for the reasons detailed in the added doc examples)...
But that quickly became a lot of churn and I figured it would already be tedious to review this, so I went back and undid those changes at some point—manually.
My best guess is that I went back to this one, undid the change to a Graph.edges() call, noticed the line length was too long (I believe this file doesn't get linted for some reason? Otherwise I expect ruff should have caught this) and accidentally added this whitespace change.
I think that probably counts as "nothing important." :)
|
Do you want me to undo the whitespace change or is this one good to go? It has two approving reviews from maintainers! |
|
The linters are happy with the whitespace. I press merge. |
Fixes #8137.
This PR adds a
directedkwarg toedges_equalto indicate edgelists should be treated as coming from directed graphs.