Skip to content

Commit e3590c8

Browse files
ChVeenglemaitrejeremiedbb
authored
MAINT Parameters validation for graph.single_source_shortest_path_length (scikit-learn#26091)
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com> Co-authored-by: Jérémie du Boisberranger <34657725+jeremiedbb@users.noreply.github.com>
1 parent 4be1089 commit e3590c8

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

sklearn/tests/test_public_functions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ def _check_function_param_validation(
282282
"sklearn.tree.export_text",
283283
"sklearn.tree.plot_tree",
284284
"sklearn.utils.gen_batches",
285+
"sklearn.utils.graph.single_source_shortest_path_length",
285286
"sklearn.utils.resample",
286287
]
287288

sklearn/utils/graph.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,26 @@
1414
from scipy import sparse
1515

1616
from ..metrics.pairwise import pairwise_distances
17+
from ._param_validation import Integral, Interval, validate_params
1718

1819

1920
###############################################################################
2021
# Path and connected component analysis.
2122
# Code adapted from networkx
23+
@validate_params(
24+
{
25+
"graph": ["array-like", "sparse matrix"],
26+
"source": [Interval(Integral, 0, None, closed="left")],
27+
"cutoff": [Interval(Integral, 0, None, closed="left"), None],
28+
},
29+
prefer_skip_nested_validation=True,
30+
)
2231
def single_source_shortest_path_length(graph, source, *, cutoff=None):
2332
"""Return the length of the shortest path from source to all reachable nodes.
2433
2534
Parameters
2635
----------
27-
graph : {sparse matrix, ndarray} of shape (n_nodes, n_nodes)
36+
graph : {array-like, sparse matrix} of shape (n_nodes, n_nodes)
2837
Adjacency matrix of the graph. Sparse matrix of format LIL is
2938
preferred.
3039

0 commit comments

Comments
 (0)