Skip to content

Commit 5f21818

Browse files
author
Release Manager
committed
gh-40098: remove deprecation in `connected_components` With issue #35889 and PR #35891 we have deprecate sorting by default in connected component methods for graphs. This PR removes the deprecation and sets the default value of parameter `sort` to `False`. Hence, the vertices of a connected component are no longer sorted by default. We let unchanged the behavior of method `connected_components` of returning the list of connected components sorted by non-increasing size. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [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. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #40098 Reported by: David Coudert Reviewer(s): Dima Pasechnik
2 parents c4b239f + e0bcb57 commit 5f21818

File tree

1 file changed

+5
-40
lines changed

1 file changed

+5
-40
lines changed

src/sage/graphs/connectivity.pyx

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ Methods
7373
# https://www.gnu.org/licenses/
7474
# ****************************************************************************
7575

76-
from sage.misc.superseded import deprecation
7776
from sage.sets.disjoint_set cimport DisjointSet
7877

7978

@@ -159,7 +158,7 @@ def is_connected(G, forbidden_vertices=None):
159158
return n == G.num_verts()
160159

161160

162-
def connected_components(G, sort=None, key=None, forbidden_vertices=None):
161+
def connected_components(G, sort=False, key=None, forbidden_vertices=None):
163162
"""
164163
Return the list of connected components.
165164
@@ -170,13 +169,9 @@ def connected_components(G, sort=None, key=None, forbidden_vertices=None):
170169
171170
- ``G`` -- the input graph
172171
173-
- ``sort`` -- boolean (default: ``None``); if ``True``, vertices inside each
172+
- ``sort`` -- boolean (default: ``False``); if ``True``, vertices inside each
174173
component are sorted according to the default ordering
175174
176-
As of :issue:`35889`, this argument must be explicitly specified (unless a
177-
``key`` is given); otherwise a warning is printed and ``sort=True`` is
178-
used. The default will eventually be changed to ``False``.
179-
180175
- ``key`` -- a function (default: ``None``); a function that takes a
181176
vertex as its one argument and returns a value that can be used for
182177
comparisons in the sorting algorithm (we must have ``sort=True``)
@@ -224,24 +219,11 @@ def connected_components(G, sort=None, key=None, forbidden_vertices=None):
224219
Traceback (most recent call last):
225220
...
226221
ValueError: sort keyword is False, yet a key function is given
227-
228-
Deprecation warning for ``sort=None`` (:issue:`35889`)::
229-
230-
sage: G = graphs.HouseGraph()
231-
sage: G.connected_components()
232-
doctest:...: DeprecationWarning: parameter 'sort' will be set to False by default in the future
233-
See https://github.com/sagemath/sage/issues/35889 for details.
234-
[[0, 1, 2, 3, 4]]
235222
"""
236223
from sage.graphs.generic_graph import GenericGraph
237224
if not isinstance(G, GenericGraph):
238225
raise TypeError("the input must be a Sage graph")
239226

240-
if sort is None:
241-
if key is None:
242-
deprecation(35889, "parameter 'sort' will be set to False by default in the future")
243-
sort = True
244-
245227
if (not sort) and key:
246228
raise ValueError('sort keyword is False, yet a key function is given')
247229

@@ -340,7 +322,7 @@ def connected_components_subgraphs(G, forbidden_vertices=None):
340322
forbidden_vertices=forbidden_vertices)]
341323

342324

343-
def connected_component_containing_vertex(G, vertex, sort=None, key=None,
325+
def connected_component_containing_vertex(G, vertex, sort=False, key=None,
344326
forbidden_vertices=None):
345327
"""
346328
Return a list of the vertices connected to vertex.
@@ -351,13 +333,9 @@ def connected_component_containing_vertex(G, vertex, sort=None, key=None,
351333
352334
- ``vertex`` -- the vertex to search for
353335
354-
- ``sort`` -- boolean (default: ``None``); if ``True``, vertices inside the
336+
- ``sort`` -- boolean (default: ``False``); if ``True``, vertices inside the
355337
component are sorted according to the default ordering
356338
357-
As of :issue:`35889`, this argument must be explicitly specified (unless a
358-
``key`` is given); otherwise a warning is printed and ``sort=True`` is
359-
used. The default will eventually be changed to ``False``.
360-
361339
- ``key`` -- a function (default: ``None``); a function that takes a
362340
vertex as its one argument and returns a value that can be used for
363341
comparisons in the sorting algorithm (we must have ``sort=True``)
@@ -408,24 +386,11 @@ def connected_component_containing_vertex(G, vertex, sort=None, key=None,
408386
Traceback (most recent call last):
409387
...
410388
ValueError: sort keyword is False, yet a key function is given
411-
412-
Deprecation warning for ``sort=None`` (:issue:`35889`)::
413-
414-
sage: G = graphs.HouseGraph()
415-
sage: G.connected_component_containing_vertex(1)
416-
doctest:...: DeprecationWarning: parameter 'sort' will be set to False by default in the future
417-
See https://github.com/sagemath/sage/issues/35889 for details.
418-
[0, 1, 2, 3, 4]
419389
"""
420390
from sage.graphs.generic_graph import GenericGraph
421391
if not isinstance(G, GenericGraph):
422392
raise TypeError("the input must be a Sage graph")
423393

424-
if sort is None:
425-
if key is None:
426-
deprecation(35889, "parameter 'sort' will be set to False by default in the future")
427-
sort = True
428-
429394
if (not sort) and key:
430395
raise ValueError('sort keyword is False, yet a key function is given')
431396

@@ -1122,7 +1087,7 @@ def is_vertex_cut(G, cut, weak=False):
11221087
11231088
sage: from sage.graphs.connectivity import is_vertex_cut
11241089
sage: G = graphs.CycleGraph(4) * 2
1125-
sage: G.connected_components()
1090+
sage: G.connected_components(sort=True)
11261091
[[0, 1, 2, 3], [4, 5, 6, 7]]
11271092
sage: is_vertex_cut(G, [0, 2])
11281093
True

0 commit comments

Comments
 (0)