-
-
Notifications
You must be signed in to change notification settings - Fork 541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GenericGraph.adjacency_matrix: using sort=True when getting vertices #35245
GenericGraph.adjacency_matrix: using sort=True when getting vertices #35245
Conversation
Documentation preview for this PR is ready! 🎉 |
This PR is not similar to PR #35168 but to issue #29277. This is a consequence of the choice of Python 3 to raise an error when trying to sort a list of elements of different types (it was possible with Python 2). I disagree with the solution you propose. Indeed, you get an adjacency matrix, but you don't know the mapping between the vertices and the rows / columns of the matrix. When you have vertices of different types, the solution is to give as input an ordering of the vertices: sage: G = Graph()
sage: G.add_vertices([14, 'test', 50])
sage: G.add_edge(14, 'test')
sage: G.adjacency_matrix(vertices=[14, 'test', 50])
[0 1 0]
[1 0 0]
[0 0 0]
sage: G.adjacency_matrix(vertices=['test', 50, 14])
[0 0 1]
[0 0 0]
[1 0 0] Currently, all methods calling If you want to modify something, you can :
|
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## develop #35245 +/- ##
===========================================
+ Coverage 88.57% 88.58% +0.01%
===========================================
Files 2140 2140
Lines 397273 397415 +142
===========================================
+ Hits 351891 352067 +176
+ Misses 45382 45348 -34
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Indeed the method would be useless if we do not known the mapping 🤦 I commited the changes you suggested: a better error message in the exception, some explanation in the docstring and two tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and don't add a useless space between TypeError
and (
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
📚 Description
As illustrated by the following code, the method
adjacency_matrix
of the GenericGraph class failed when vertices where not sortable.I fixed the problem by using
sort=False
instead ofsort=True
in the line that get the list of vertices.I did not open an issue for this bug, but it is similar to #35168 (fixed by PR #35170)
NOTE
I started to write a test to cover the changes but all others test are broken by this small commit. Indeed the adjacency matrix obtained with the new code can have a different row/column order. I am not sure what is the correct way to handle this situation
📝 Checklist
⌛ Dependencies