Repository navigation
Set length threshold in FR and use np.clip - #8145
Conversation
Peiffap
left a comment
There was a problem hiding this comment.
My 2c on whether breaking backward-compatibility is an issue basically comes down to whether you consider this a bug to be fixed. I'm personally happy to take it as a bug fix, even though the current behavior is intentional!
dschult
left a comment
There was a problem hiding this comment.
Thanks all for the helpful and interesting discussion around this seemingly minor issue. I agree with this solution -- and I don't think we need a deprecation cycle.
Of course, this PR has 2 failed tests because the images don't match exactly. Should this PR include updating the two images so the tests pass? How do we handle that?
It must!
I wasn't sure off the top of my head, but fortunately the contributor guide documents the procedure! Going through this exercise also reminded another reason why we have the It's been so long (ever?) since these tests have failed that I forgot all about this nice feature :) |
Closes #8113
I have been convinced by @HirokiHamaguchi 's and @rudyarthur 's careful analysis of the thresholding in the FR layout that it's worth considering setting the length fill value to be equal to the threshold. While the change itself in source code is quite small, bear in mind this will break backward compatibility; i.e.
spring_layoutwill no longer produce identical layouts to previous versions of NetworkX even when seeded identically. This is evidenced by the required change in the doctest.IMO given how little the layouts will change (especially for the default number of iterations) and the minor improvements for some cases (see @HirokiHamaguchi 's analysis in #8113), I'm willing to accept this breakage. That's just my opinion though - if others feel different please share your perspective!
Switching to a fill value that matches the threshold also enables another minor improvement - we can use
np.clipinstead ofnp.whereor any other mask-based approach, which is both faster and arguably more readable. I've included that change as well (and in another unrelated location wherenp.wherecould be replaced withclip).Finally, I added a code comment explaining the clipping and referencing back to #8113. It may be a bit unorthodox to link to a GH discussion in source code, but the discussion there is so rich I feel it's worth pointing to.