Skip to content

Commit 32d375d

Browse files
author
Release Manager
committed
sagemathgh-36073: Stop sorting Graph vertices and edges by default Following sagemath#22349 and sagemath#27408, we finally set parameter `sort` to `False` by default for methods `vertices` and `edges`, and remove the corresponding deprecation warnings. ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - sagemath#12345: short description why this is a dependency - sagemath#34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: sagemath#36073 Reported by: David Coudert Reviewer(s): Matthias Köppe
2 parents 1e6cd50 + c8670bd commit 32d375d

File tree

5 files changed

+19
-60
lines changed

5 files changed

+19
-60
lines changed

src/sage/geometry/polyhedron/base4.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def vertex_facet_graph(self, labels=True):
9595
sage: P = polytopes.cube()
9696
sage: G = P.vertex_facet_graph(); G
9797
Digraph on 14 vertices
98-
sage: G.vertices(key = lambda v: str(v))
98+
sage: G.vertices(sort=True, key=lambda v: str(v))
9999
[A vertex at (-1, -1, -1),
100100
A vertex at (-1, -1, 1),
101101
A vertex at (-1, 1, -1),

src/sage/graphs/digraph.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3679,7 +3679,8 @@ def flow_polytope(self, edges=None, ends=None, backend=None):
36793679
36803680
Using a different order for the edges of the graph::
36813681
3682-
sage: fl = G.flow_polytope(edges=G.edges(key=lambda x: x[0] - x[1])); fl # needs sage.geometry.polyhedron
3682+
sage: ordered_edges = G.edges(sort=True, key=lambda x: x[0] - x[1])
3683+
sage: fl = G.flow_polytope(edges=ordered_edges); fl # needs sage.geometry.polyhedron
36833684
A 1-dimensional polyhedron in QQ^4 defined as the convex hull of 2 vertices
36843685
sage: fl.vertices() # needs sage.geometry.polyhedron
36853686
(A vertex at (0, 1, 1, 0), A vertex at (1, 0, 0, 1))

src/sage/graphs/generic_graph.py

+10-44
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,6 @@
439439
from sage.misc.decorators import options
440440
from sage.misc.cachefunc import cached_method
441441
from sage.misc.prandom import random
442-
from sage.misc.superseded import deprecation
443442
from sage.misc.lazy_import import lazy_import, LazyImport
444443

445444
from sage.rings.integer_ring import ZZ
@@ -11364,19 +11363,15 @@ def neighbor_iterator(self, vertex, closed=False):
1136411363
for u in self._backend.iterator_nbrs(vertex):
1136511364
yield u
1136611365

11367-
def vertices(self, sort=None, key=None, degree=None, vertex_property=None):
11366+
def vertices(self, sort=False, key=None, degree=None, vertex_property=None):
1136811367
r"""
1136911368
Return a list of the vertices.
1137011369

1137111370
INPUT:
1137211371

11373-
- ``sort`` -- boolean (default: ``None``); if ``True``, vertices are
11374-
sorted according to the default ordering
11375-
11376-
As of :trac:`22349`, this argument must be explicitly
11377-
specified (unless a ``key`` is given); otherwise a warning
11378-
is printed and ``sort=True`` is used. The default will
11379-
eventually be changed to ``False``.
11372+
- ``sort`` -- boolean (default: ``False``); whether to sort vertices
11373+
according the ordering specified with parameter ``key``. If ``False``
11374+
(default), vertices are not sorted.
1138011375

1138111376
- ``key`` -- a function (default: ``None``); a function that takes a
1138211377
vertex as its one argument and returns a value that can be used for
@@ -11464,20 +11459,7 @@ def vertices(self, sort=None, key=None, degree=None, vertex_property=None):
1146411459
Traceback (most recent call last):
1146511460
...
1146611461
ValueError: sort keyword is False, yet a key function is given
11467-
11468-
Deprecation warning for ``sort=None`` (:trac:`22349`)::
11469-
11470-
sage: G = graphs.HouseGraph()
11471-
sage: G.vertices()
11472-
doctest:...: DeprecationWarning: parameter 'sort' will be set to False by default in the future
11473-
See https://github.com/sagemath/sage/issues/22349 for details.
11474-
[0, 1, 2, 3, 4]
1147511462
"""
11476-
if sort is None:
11477-
if key is None:
11478-
deprecation(22349, "parameter 'sort' will be set to False by default in the future")
11479-
sort = True
11480-
1148111463
if (not sort) and key:
1148211464
raise ValueError('sort keyword is False, yet a key function is given')
1148311465

@@ -12403,7 +12385,7 @@ def has_edge(self, u, v=None, label=None):
1240312385
label = None
1240412386
return self._backend.has_edge(u, v, label)
1240512387

12406-
def edges(self, vertices=None, labels=True, sort=None, key=None,
12388+
def edges(self, vertices=None, labels=True, sort=False, key=None,
1240712389
ignore_direction=False, sort_vertices=True):
1240812390
r"""
1240912391
Return a :class:`~EdgesView` of edges.
@@ -12427,13 +12409,10 @@ def edges(self, vertices=None, labels=True, sort=None, key=None,
1242712409
- ``labels`` -- boolean (default: ``True``); if ``False``, each edge is
1242812410
simply a pair ``(u, v)`` of vertices
1242912411

12430-
- ``sort`` -- boolean (default: ``None``); if ``True``, edges are sorted
12431-
according to the default ordering
12432-
12433-
As of :trac:`22349`, this argument must be explicitly
12434-
specified (unless a ``key`` is given); otherwise a warning
12435-
is printed and ``sort=True`` is used. The default will
12436-
eventually be changed to ``False``.
12412+
- ``sort`` -- boolean (default: ``False``); whether to sort edges
12413+
according the ordering specified with parameter ``key``. If ``False``
12414+
(default), edges are not sorted. This is the fastest and less memory
12415+
consuming method for iterating over edges.
1243712416

1243812417
- ``key`` -- a function (default: ``None``); a function that takes an
1243912418
edge (a pair or a triple, according to the ``labels`` keyword) as its
@@ -12529,7 +12508,7 @@ def edges(self, vertices=None, labels=True, sort=None, key=None,
1252912508
....: G.set_edge_label(e[0], e[1], chr(ord('A') + e[0] + 5 * e[1]))
1253012509
sage: G.edges(sort=True)
1253112510
[(0, 1, 'F'), (0, 4, 'U'), (1, 2, 'L'), (2, 3, 'R'), (3, 4, 'X')]
12532-
sage: G.edges(key=lambda x: x[2])
12511+
sage: G.edges(sort=True, key=lambda x: x[2])
1253312512
[(0, 1, 'F'), (1, 2, 'L'), (2, 3, 'R'), (0, 4, 'U'), (3, 4, 'X')]
1253412513

1253512514
We can restrict considered edges to those incident to a given set::
@@ -12580,20 +12559,7 @@ def edges(self, vertices=None, labels=True, sort=None, key=None,
1258012559
sage: G.edge_label(0, 1)[0] += 1
1258112560
sage: G.edges(sort=True)
1258212561
[(0, 1, [8]), (0, 2, [7])]
12583-
12584-
Deprecation warning for ``sort=None`` (:trac:`27408`)::
12585-
12586-
sage: G = graphs.HouseGraph()
12587-
sage: G.edges(sort=None)
12588-
doctest:...: DeprecationWarning: parameter 'sort' will be set to False by default in the future
12589-
See https://github.com/sagemath/sage/issues/27408 for details.
12590-
[(0, 1, None), (0, 2, None), (1, 3, None), (2, 3, None), (2, 4, None), (3, 4, None)]
1259112562
"""
12592-
if sort is None:
12593-
if key is None:
12594-
deprecation(27408, "parameter 'sort' will be set to False by default in the future")
12595-
sort = True
12596-
1259712563
if vertices is not None and vertices in self:
1259812564
vertices = [vertices]
1259912565

src/sage/graphs/views.pyx

+5-13
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,10 @@ cdef class EdgesView:
6464
- ``ignore_direction`` -- boolean (default: ``False``); only applies to
6565
directed graphs. If ``True``, searches across edges in either direction.
6666
67-
- ``sort`` -- boolean (default: ``None``); whether to sort edges
68-
69-
- if ``None``, sort edges according to the default ordering and give a
70-
deprecation warning as sorting will be set to ``False`` by default in
71-
the future
72-
73-
- if ``True``, edges are sorted according the ordering specified with
74-
parameter ``key``
75-
76-
- if ``False``, edges are not sorted. This is the fastest and less memory
77-
consuming method for iterating over edges. This will become the default
78-
behavior in the future.
67+
- ``sort`` -- boolean (default: ``False``); whether to sort edges according
68+
the ordering specified with parameter ``key``. If ``False`` (default),
69+
edges are not sorted. This is the fastest and less memory consuming method
70+
for iterating over edges.
7971
8072
- ``key`` -- a function (default: ``None``); a function that takes an edge
8173
(a pair or a triple, according to the ``labels`` keyword) as its one
@@ -350,7 +342,7 @@ cdef class EdgesView:
350342

351343
def __init__(self, G, vertices=None, vertices2=None, labels=True,
352344
ignore_direction=False,
353-
sort=None, key=None, sort_vertices=True):
345+
sort=False, key=None, sort_vertices=True):
354346
"""
355347
Construction of this :class:`EdgesView`.
356348

src/sage/manifolds/subset.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ def subset_digraph(self, loops=False, quotient=False, open_covers=False, points=
901901
sage: U = M.open_subset('U'); V = M.open_subset('V'); W = M.open_subset('W')
902902
sage: D = M.subset_digraph(); D
903903
Digraph on 4 vertices
904-
sage: D.edges(key=lambda e: (e[0]._name, e[1]._name))
904+
sage: D.edges(sort=True, key=lambda e: (e[0]._name, e[1]._name))
905905
[(Set {U} of open subsets of the 3-dimensional differentiable manifold M,
906906
Set {M} of open subsets of the 3-dimensional differentiable manifold M,
907907
None),

0 commit comments

Comments
 (0)