8000 remove deprecation in `connected_components` by dcoudert · Pull Request #40098 · sagemath/sage · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

remove deprecation in connected_components #40098

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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 5 additions & 40 deletions src/sage/graphs/connectivity.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ Methods
# https://www.gnu.org/licenses/
# ****************************************************************************

from sage.misc.superseded import deprecation
from sage.sets.disjoint_set cimport DisjointSet


Expand Down Expand Up @@ -158,7 +157,7 @@ def is_connected(G, forbidden_vertices=None):
return n == G.num_verts()


def connected_components(G, sort=None, key=None, forbidden_vertices=None):
def connected_components(G, sort=False, key=None, forbidden_vertices=None):
"""
Return the list of connected components.

Expand All @@ -169,13 +168,9 @@ def connected_components(G, sort=None, key=None, forbidden_vertices=None):

- ``G`` -- the input graph

- ``sort`` -- boolean (default: ``None``); if ``True``, vertices inside each
- ``sort`` -- boolean (default: ``False``); if ``True``, vertices inside each
component are sorted according to the default ordering

As of :issue:`35889`, 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``.

- ``key`` -- a function (default: ``None``); a function that takes a
vertex as its one argument and returns a value that can be used for
comparisons in the sorting algorithm (we must have ``sort=True``)
Expand Down Expand Up @@ -223,24 +218,11 @@ def connected_components(G, sort=None, key=None, forbidden_vertices=None):
Traceback (most recent call last):
...
ValueError: sort keyword is False, yet a key function is given

Deprecation warning for ``sort=None`` (:issue:`35889`)::

sage: G = graphs.HouseGraph()
sage: G.connected_components()
doctest:...: DeprecationWarning: parameter 'sort' will be set to False by default in the future
See https://github.com/sagemath/sage/issues/35889 for details.
[[0, 1, 2, 3, 4]]
"""
from sage.graphs.generic_graph import GenericGraph
if not isinstance(G, GenericGraph):
raise TypeError("the input must be a Sage graph")

if sort is None:
if key is None:
deprecation(35889, "parameter 'sort' will be set to False by default in the future")
sort = True

if (not sort) and key:
raise ValueError('sort keyword is False, yet a key function is given')

Expand Down Expand Up @@ -339,7 +321,7 @@ def connected_components_subgraphs(G, forbidden_vertices=None):
forbidden_vertices=forbidden_vertices)]


def connected_component_containing_vertex(G, vertex, sort=None, key=None,
def connected_component_containing_vertex(G, vertex, sort=False, key=None,
forbidden_vertices=None):
"""
Return a list of the vertices connected to vertex.
Expand All @@ -350,13 +332,9 @@ def connected_component_containing_vertex(G, vertex, sort=None, key=None,

- ``vertex`` -- the vertex to search for

- ``sort`` -- boolean (default: ``None``); if ``True``, vertices inside the
- ``sort`` -- boolean (default: ``False``); if ``True``, vertices inside the
component are sorted according to the default ordering

As of :issue:`35889`, 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``.

- ``key`` -- a function (default: ``None``); a function that takes a
vertex as its one argument and returns a value that can be used for
comparisons in the sorting algorithm (we must have ``sort=True``)
Expand Down Expand Up @@ -407,24 +385,11 @@ def connected_component_containing_vertex(G, vertex, sort=None, key=None,
Traceback (most recent call last):
...
ValueError: sort keyword is False, yet a key function is given

Deprecation warning for ``sort=None`` (:issue:`35889`)::

sage: G = graphs.HouseGraph()
sage: G.connected_component_containing_vertex(1)
doctest:...: DeprecationWarning: parameter 'sort' will be set to False by default in the future
See https://github.com/sagemath/sage/issues/35889 for details.
[0, 1, 2, 3, 4]
"""
from sage.graphs.generic_graph import GenericGraph
if not isinstance(G, GenericGraph):
raise TypeError("the input must be a Sage graph")

if sort is None:
if key is None:
deprecation(35889, "parameter 'sort' will be set to False by default in the future")
sort = True

if (not sort) and key:
raise ValueError('sort keyword is False, yet a key function is given')

Expand Down Expand Up @@ -1083,7 +1048,7 @@ def is_vertex_cut(G, cut, weak=False):

sage: from sage.graphs.connectivity import is_vertex_cut
sage: G = graphs.CycleGraph(4) * 2
sage: G.connected_components()
sage: G.connected_components(sort=True)
[[0, 1, 2, 3], [4, 5, 6, 7]]
sage: is_vertex_cut(G, [0, 2])
True
Expand Down
Loading
0