DeprecationWarning on sagecell in Graph([(0,1)]).vertices()

58 views
Skip to first unread message

Georgi Guninski

unread,
Jun 24, 2023, 9:20:39 AM6/24/23
to sage-...@googlegroups.com
https://sagecell.sagemath.org/

Graph([(0,1)]).vertices()

/tmp/ipykernel_1853928/1298164553.py:1: DeprecationWarning: parameter
'sort' will be set to False by default in the future
See https://github.com/sagemath/sage/issues/22349 for details.
Graph([(Integer(0),Integer(1))]).vertices()

[0, 1]

kcrisman

unread,
Jun 26, 2023, 9:40:30 AM6/26/23
to sage-devel
The docstring clarifies:


G = Graph([(0,1)])
G.vertices?

As of https://github.com/sagemath/sage/issues/22349, this argument must be explicitly specified (unless a "key" is given); otherwise a warning is printed and "sort=True" is used. The default will eventually be changed to "False". 

Interestingly, the example Harald cross-referenced at https://github.com/sagemathinc/cocalc/issues/6750 does not give this warning in the cell server.

Georgi Guninski

unread,
Jun 26, 2023, 10:30:20 AM6/26/23
to sage-...@googlegroups.com
On Mon, Jun 26, 2023 at 4:40 PM kcrisman <kcri...@gmail.com> wrote:

> As of https://github.com/sagemath/sage/issues/22349, this argument must be explicitly specified (unless a "key" is given); otherwise a warning is printed and "sort=True" is used. The default will eventually be changed to "False".
>

I think this sucks.
Don't see any warning on version 9.6.

Nils Bruin

unread,
Jun 26, 2023, 1:09:30 PM6/26/23
to sage-devel
On Monday, 26 June 2023 at 16:30:20 UTC+2 Georgi Guninski wrote:
> As of https://github.com/sagemath/sage/issues/22349, this argument must be explicitly specified (unless a "key" is given); otherwise a warning is printed and "sort=True" is used. The default will eventually be changed to "False".

I think this sucks.
 
Pay attention to the instructions: by explicitly specifying "sort = ..." you can avoid the warning. Doing so protects your code against the eventual change from default "True" to "False". It's correcting an earlier design error (vertices may not even be sortable, so defaulting to doing that can really be a problem).

Georgi Guninski

unread,
Jun 27, 2023, 1:00:25 AM6/27/23
to sage-...@googlegroups.com
Thanks.

In my code, this backwards incompatibility breaks over
150 calls to Graph.vertices() and I suspect
I am not the only one.

I think the root of the problem is the change from python2
to python3. In python2 |["A",1].sort()| works fine, while
it doesn't work in python3.

My recommendation is to reverse engineer python2.sort() and
use it as a custom function for sorting heterogeneous vertices.
In this scenario, the code won't be more broken than it was
in python2.

John H Palmieri

unread,
Jun 27, 2023, 1:47:57 AM6/27/23
to sage-devel
Just do a global search-and-replace: change ".vertices()" to ".vertices(sort=True, key=id)" or ".vertices(sort=True, key=str)".

This is not a new change; the deprecation warning has been in place almost a year, and there was discussion leading up to it. See https://github.com/sagemath/sage/issues/22349, in particular. I don't think that Sage developers are going to revert back to sorting by default, especially since sorting arbitrary objects can be problematic.

(Actually, looking back on old sage-devel posts, you asked about essentially this issue (incomparable objects in Python 3 and using them to label vertices in graphs) back in July '22: https://groups.google.com/g/sage-devel/c/zc1UlSJse34/m/aHsfFnCKAAAJ. So not only is it not new in general, it's not new to you, either.)

Georgi Guninski

unread,
Jun 27, 2023, 2:48:39 AM6/27/23
to sage-...@googlegroups.com
On Tue, Jun 27, 2023 at 8:48 AM John H Palmieri <jhpalm...@gmail.com> wrote:
>
> Just do a global search-and-replace: change ".vertices()" to ".vertices(sort=True, key=id)" or ".vertices(sort=True, key=str)".
>

Thanks for this.

You are right that I knew about the problems with sort(),
and sage 9.6 is OK for me currently.

I noticed the warning when I shared permanent link to
sagecell and it gave several warnings to the audience.
Reply all
Reply to author
Forward
0 new messages