Skip to content

MAINT Parameters validation for graph.single_source_shortest_path_length #26091

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

Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions sklearn/tests/test_public_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ def _check_function_param_validation(
"sklearn.tree.export_text",
"sklearn.tree.plot_tree",
"sklearn.utils.gen_batches",
"sklearn.utils.graph.single_source_shortest_path_length",
"sklearn.utils.resample",
]

Expand Down
11 changes: 10 additions & 1 deletion sklearn/utils/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,26 @@
from scipy import sparse

from ..metrics.pairwise import pairwise_distances
from ._param_validation import Integral, Interval, validate_params


###############################################################################
# Path and connected component analysis.
# Code adapted from networkx
@validate_params(
{
"graph": ["array-like", "sparse matrix"],
"source": [Interval(Integral, 0, None, closed="left")],
"cutoff": [Interval(Integral, 0, None, closed="left"), None],
},
prefer_skip_nested_validation=True,
)
def single_source_shortest_path_length(graph, source, *, cutoff=None):
"""Return the length of the shortest path from source to all reachable nodes.

Parameters
----------
graph : {sparse matrix, ndarray} of shape (n_nodes, n_nodes)
graph : {array-like, sparse matrix} of shape (n_nodes, n_nodes)
Adjacency matrix of the graph. Sparse matrix of format LIL is
preferred.

Expand Down