Skip to content

Commit 1081de4

Browse files
rossbarAlex-Markham
authored andcommitted
Deprecate strongly_connected_components_recursive (networkx#6957)
* Deprecate strongly_connected_components_recursive. * Add release note. * Replace buggy recursive implementation with wrapper.
1 parent d6d99f8 commit 1081de4

File tree

5 files changed

+32
-32
lines changed

5 files changed

+32
-32
lines changed

doc/developer/deprecations.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,5 @@ Version 3.4
6161
* Remove ``normalized`` kwarg from ``algorithms.s_metric``
6262
* Remove renamed function ``join()`` in ``algorithms/tree/operations.py`` and
6363
in ``doc/reference/algorithms/trees.rst``
64+
* Remove ``strongly_connected_components_recursive`` from
65+
``algorithms/components/strongly_connected.py``

doc/release/release_dev.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ Deprecations
7575
- [`#6841 <https://github.com/networkx/pull/6841>`_]
7676
Deprecate the ``normalized`` keyword of the ``s_metric`` function. Ignore
7777
value of ``normalized`` for future compatibility.
78+
- [`#6957 <https://github.com/networkx/pull/6957>`_]
79+
Deprecate ``strongly_connected_components_recursive`` function in favor of
80+
the non-recursive implmentation ``strongly_connected_components``.
7881

7982
Merged PRs
8083
----------

networkx/algorithms/components/strongly_connected.py

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ def kosaraju_strongly_connected_components(G, source=None):
178178
def strongly_connected_components_recursive(G):
179179
"""Generate nodes in strongly connected components of graph.
180180
181+
.. deprecated:: 3.2
182+
183+
This function is deprecated and will be removed in a future version of
184+
NetworkX. Use `strongly_connected_components` instead.
185+
181186
Recursive version of algorithm.
182187
183188
Parameters
@@ -236,35 +241,18 @@ def strongly_connected_components_recursive(G):
236241
Information Processing Letters 49(1): 9-14, (1994)..
237242
238243
"""
244+
import warnings
245+
246+
warnings.warn(
247+
(
248+
"\n\nstrongly_connected_components_recursive is deprecated and will be\n"
249+
"removed in the future. Use strongly_connected_components instead."
250+
),
251+
category=DeprecationWarning,
252+
stacklevel=2,
253+
)
239254

240-
def visit(v, cnt):
241-
root[v] = cnt
242-
visited[v] = cnt
243-
cnt += 1
244-
stack.append(v)
245-
for w in G[v]:
246-
if w not in visited:
247-
yield from visit(w, cnt)
248-
if w not in component:
249-
root[v] = min(root[v], root[w])
250-
if root[v] == visited[v]:
251-
component[v] = root[v]
252-
tmpc = {v} # hold nodes in this component
253-
while stack[-1] != v:
254-
w = stack.pop()
255-
component[w] = root[v]
256-
tmpc.add(w)
257-
stack.remove(v)
258-
yield tmpc
259-
260-
visited = {}
261-
component = {}
262-
root = {}
263-
cnt = 0
264-
stack = []
265-
for source in G:
266-
if source not in visited:
267-
yield from visit(source, cnt)
255+
yield from strongly_connected_components(G)
268256

269257

270258
@not_implemented_for("undirected")

networkx/algorithms/components/tests/test_strongly_connected.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ def test_tarjan(self):
6363
def test_tarjan_recursive(self):
6464
scc = nx.strongly_connected_components_recursive
6565
for G, C in self.gc:
66-
assert {frozenset(g) for g in scc(G)} == C
66+
with pytest.deprecated_call():
67+
assert {frozenset(g) for g in scc(G)} == C
6768

6869
def test_kosaraju(self):
6970
scc = nx.kosaraju_strongly_connected_components
@@ -168,7 +169,8 @@ def test_null_graph(self):
168169
G = nx.DiGraph()
169170
assert list(nx.strongly_connected_components(G)) == []
170171
assert list(nx.kosaraju_strongly_connected_components(G)) == []
171-
assert list(nx.strongly_connected_components_recursive(G)) == []
172+
with pytest.deprecated_call():
173+
assert list(nx.strongly_connected_components_recursive(G)) == []
172174
assert len(nx.condensation(G)) == 0
173175
pytest.raises(
174176
nx.NetworkXPointlessConcept, nx.is_strongly_connected, nx.DiGraph()
@@ -181,7 +183,8 @@ def test_connected_raise(self):
181183
with pytest.raises(NetworkXNotImplemented):
182184
next(nx.kosaraju_strongly_connected_components(G))
183185
with pytest.raises(NetworkXNotImplemented):
184-
next(nx.strongly_connected_components_recursive(G))
186+
with pytest.deprecated_call():
187+
next(nx.strongly_connected_components_recursive(G))
185188
pytest.raises(NetworkXNotImplemented, nx.is_strongly_connected, G)
186189
pytest.raises(
187190
nx.NetworkXPointlessConcept, nx.is_strongly_connected, nx.DiGraph()
@@ -191,7 +194,6 @@ def test_connected_raise(self):
191194
strong_cc_methods = (
192195
nx.strongly_connected_components,
193196
nx.kosaraju_strongly_connected_components,
194-
nx.strongly_connected_components_recursive,
195197
)
196198

197199
@pytest.mark.parametrize("get_components", strong_cc_methods)

networkx/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ def set_warnings():
117117
warnings.filterwarnings(
118118
"ignore", category=DeprecationWarning, message="function `join` is deprecated"
119119
)
120+
warnings.filterwarnings(
121+
"ignore",
122+
category=DeprecationWarning,
123+
message="\n\nstrongly_connected_components_recursive",
124+
)
120125

121126

122127
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)