Graph([(0,'a')]).vertices() raises exception

74 views
Skip to first unread message

Georgi Guninski

unread,
Jul 13, 2022, 7:17:29 AM7/13/22
to sage-...@googlegroups.com
hi sage developers :)
long time no see.

i think the migration python2 to python3 regressed a lot
of Graph() stuff related to ordering the vertices.

Here is test case from sagecell:

===
g1=Graph([(0,'a')])
g2=g1.copy()
g2.relabel()
g2.vertices()
g1.vertices()

TypeError: '<' not supported between instances of 'int' and 'str'
===

Dima Pasechnik

unread,
Jul 13, 2022, 7:59:45 AM7/13/22
to sage-devel


On Wed, 13 Jul 2022, 08:17 Georgi Guninski, <ggun...@gmail.com> wrote:
hi sage developers :)
long time no see.

i think the migration python2 to python3 regressed a lot
of Graph() stuff related to ordering the vertices.

yes, indeed. I don't think much can be done here; i.e., fix your old code.



Here is test case from sagecell:

===
g1=Graph([(0,'a')])
g2=g1.copy()
g2.relabel()
g2.vertices()
g1.vertices()

TypeError: '<' not supported between instances of 'int' and 'str'
===

--
You received this message because you are subscribed to the Google Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/CAGUWgD-KgJS9CnNCJPun0TcQjbi6Y2RBS8JLYpca%3D1oPjLpi4w%40mail.gmail.com.

John H Palmieri

unread,
Jul 13, 2022, 2:45:55 PM7/13/22
to sage-devel
"Fix your old code" could just mean using `vertices(sort=False)`. See also https://trac.sagemath.org/ticket/22349.

Georgi Guninski

unread,
Aug 19, 2022, 12:05:23 PM8/19/22
to sage-...@googlegroups.com
On Wed, Jul 13, 2022 at 5:46 PM John H Palmieri <jhpalm...@gmail.com> wrote:
>
> "Fix your old code" could just mean using `vertices(sort=False)`. See also https://trac.sagemath.org/ticket/22349.
>

fixing the sort() appears easy:

>>> li=['a',0]
>>> li.sort(key=hash);li
[0, 'a']

John H Palmieri

unread,
Aug 20, 2022, 3:27:45 AM8/20/22
to sage-devel
I see the following in the most recent (beta) release of Sage:

sage: g1=Graph([(0,'a')])
sage: g1.vertices()
<ipython-input-2-8314ec1f36bb>:1: DeprecationWarning: parameter 'sort' will be set to False by default in the future
See http://trac.sagemath.org/22349 for details.
  g1.vertices()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [2], in <cell line: 1>()
----> 1 g1.vertices()

File ~/Desktop/Sage/git/sage/src/sage/graphs/generic_graph.py:11196, in GenericGraph.vertices(self, sort, key, degree, vertex_property)
  11193     raise ValueError('sort keyword is False, yet a key function is given')
  11195 if sort:
> 11196     return sorted(self.vertex_iterator(degree=degree, vertex_property=vertex_property), key=key)
  11197 return list(self.vertex_iterator(degree=degree, vertex_property=vertex_property))


TypeError: '<' not supported between instances of 'int' and 'str'


You could instead use `g1.vertices(sort=False)` or as you suggested,  `g1.vertices(key=hash)`, but `g1.vertices()` with no extra arguments is going to produce an error.

Travis Scrimshaw

unread,
Aug 22, 2022, 3:07:48 AM8/22/22
to sage-devel
I think it is a very bad idea to have default sorting based upon hashing. This could make a lot of output appear seemingly random (despite having a natural order), nor there is no way to deal consistently with hash collisions. This would cause far more problems than it would solve when working with incomparable objects.

Best,
Travis
Reply all
Reply to author
Forward
0 new messages