8000 cln deprecations (#24478) · thomasjpfan/scikit-learn@d2c3e65 · GitHub
[go: up one dir, main page]

Skip to content

Commit d2c3e65

Browse files
authored
cln deprecations (scikit-learn#24478)
1 parent 684f04d commit d2c3e65

File tree

3 files changed

+1
-89
lines changed

3 files changed

+1
-89
lines changed

sklearn/tests/test_docstrings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"sklearn.utils.fixes.threadpool_limits",
3030
"sklearn.utils.gen_batches",
3131
"sklearn.utils.gen_even_slices",
32-
"sklearn.utils.graph.graph_shortest_path",
3332
"sklearn.utils.graph.single_source_shortest_path_length",
3433
"sklearn.utils.is_scalar_nan",
3534
"sklearn.utils.metaestimators.available_if",

sklearn/utils/graph.py

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import numpy as np
1414
from scipy import sparse
1515

16-
from .deprecation import deprecated
1716
from ..metrics.pairwise import pairwise_distances
1817

1918

@@ -71,53 +70,6 @@ def single_source_shortest_path_length(graph, source, *, cutoff=None):
7170
return seen # return all path lengths as dictionary
7271

7372

74-
@deprecated(
75-
"`graph_shortest_path` is deprecated in 1.0 (renaming of 0.25) and will "
76-
"be removed in 1.2. Use `scipy.sparse.csgraph.shortest_path` instead."
77-
)
78-
def graph_shortest_path(dist_matrix, directed=True, method="auto"):
79-
"""Shortest-path graph search on a positive directed or undirected graph.
80-
81-
Parameters
82-
----------
83-
dist_matrix : arraylike or sparse matrix, shape = (N,N)
84-
Array of positive distances.
85-
If vertex i is connected to vertex j, then dist_matrix[i,j] gives
86-
the distance between the vertices.
87-
If vertex i is not connected to vertex j, then dist_matrix[i,j] = 0
88-
89-
directed : boolean
90-
if True, then find the shortest path on a directed graph: only
91-
progress from a point to its neighbors, not the other way around.
92-
if False, then find the shortest path on an undirected graph: the
93-
algorithm can progress from a point to its neighbors and vice versa.
94-
95-
method : {'auto', 'FW', 'D'}, default='auto'
96-
method to use. Options are
97-
'auto' : attempt to choose the best method for the current problem
98-
'FW' : Floyd-Warshall algorithm. O[N^3]
99-
'D' : Dijkstra's algorithm with Fibonacci stacks. O[(k+log(N))N^2]
100-
101-
Returns
102-
-------
103-
G : np.ndarray, float, shape = [N,N]
104-
G[i,j] gives the shortest distance from point i to point j
105-
along the graph.
106-
107-
Notes
108-
-----
109-
As currently implemented, Dijkstra's algorithm does not work for
110-
graphs with direction-dependent distances when directed == False.
111-
i.e., if dist_matrix[i,j] and dist_matrix[j,i] are not equal and
112-
both are nonzero, method='D' will not necessarily yield the correct
113-
result.
114-
Also, these routines have not been tested for graphs with negative
115-
distances. Negative distances can lead to infinite cycles that must
116-
be handled by specialized algorithms.
117-
"""
118-
return sparse.csgraph.shortest_path(dist_matrix, method=method, directed=directed)
119-
120-
12173
def _fix_connected_components(
12274
X,
12375
graph,

sklearn/utils/tests/test_shortest_path.py

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
from collections import defaultdict
22

33
import numpy as np
4-
import pytest
54
from numpy.testing import assert_array_almost_equal
6-
from sklearn.utils.graph import graph_shortest_path, single_source_shortest_path_length
7-
8-
9-
# FIXME: to be removed in 1.2
10-
def test_graph_shortest_path_deprecation():
11-
dist_matrix = generate_graph(20)
12-
13-
with pytest.warns(FutureWarning, match="deprecated"):
14-
_ = graph_shortest_path(dist_matrix)
5+
from sklearn.utils.graph import single_source_shortest_path_length
156

167

178
def floyd_warshall_slow(graph, directed=False):
@@ -54,28 +45,6 @@ def generate_graph(N=20):
5445
return dist_matrix
5546

5647

57-
@pytest.mark.filterwarnings("ignore:Function graph_shortest_path is deprecated")
58-
def test_floyd_warshall():
59-
dist_matrix = generate_graph(20)
60-
61-
for directed in (True, False):
62-
graph_FW = graph_shortest_path(dist_matrix, directed, "FW")
63-
graph_py = floyd_warshall_slow(dist_matrix.copy(), directed)
64-
65-
assert_array_almost_equal(graph_FW, graph_py)
66-
67-
68-
@pytest.mark.filterwarnings("ignore:Function graph_shortest_path is deprecated")
69-
def test_dijkstra():
70-
dist_matrix = generate_graph(20)
71-
72-
for directed in (True, False):
73-
graph_D = graph_shortest_path(dist_matrix, directed, "D")
74-
graph_py = floyd_warshall_slow(dist_matrix.copy(), directed)
75-
76-
assert_array_almost_equal(graph_D, graph_py)
77-
78-
7948
def test_shortest_path():
8049
dist_matrix = generate_graph(20)
8150
# We compare path length and not costs (-> set distances to 0 or 1)
@@ -93,11 +62,3 @@ def test_shortest_path():
9362

9463
for j in range(graph_py[i].shape[0]):
9564
assert_array_almost_equal(dist_dict[j], graph_py[i, j])
96-
97-
98-
@pytest.mark.filterwarnings("ignore:Function graph_shortest_path is deprecated")
99-
def test_dijkstra_bug_fix():
100-
X = np.array([[0.0, 0.0, 4.0], [1.0, 0.0, 2.0], [0.0, 5.0, 0.0]])
101-
dist_FW = graph_shortest_path(X, directed=False, method="FW")
102-
dist_D = graph_shortest_path(X, directed=False, method="D")
103-
assert_array_almost_equal(dist_D, dist_FW)

0 commit comments

Comments
 (0)
0