diff --git a/python/nx-cugraph/lint.yaml b/python/nx-cugraph/lint.yaml index 0d4f0b59413..5a4773168b6 100644 --- a/python/nx-cugraph/lint.yaml +++ b/python/nx-cugraph/lint.yaml @@ -50,7 +50,7 @@ repos: - id: black # - id: black-jupyter - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.13 + rev: v0.1.14 hooks: - id: ruff args: [--fix-only, --show-fixes] # --unsafe-fixes] @@ -62,7 +62,7 @@ repos: additional_dependencies: &flake8_dependencies # These versions need updated manually - flake8==7.0.0 - - flake8-bugbear==23.12.2 + - flake8-bugbear==24.1.17 - flake8-simplify==0.21.0 - repo: https://github.com/asottile/yesqa rev: v1.5.0 @@ -77,7 +77,7 @@ repos: additional_dependencies: [tomli] files: ^(nx_cugraph|docs)/ - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.13 + rev: v0.1.14 hooks: - id: ruff - repo: https://github.com/pre-commit/pre-commit-hooks diff --git a/python/nx-cugraph/nx_cugraph/algorithms/bipartite/basic.py b/python/nx-cugraph/nx_cugraph/algorithms/bipartite/basic.py index d0e9a5c7f1b..46c6b54075b 100644 --- a/python/nx-cugraph/nx_cugraph/algorithms/bipartite/basic.py +++ b/python/nx-cugraph/nx_cugraph/algorithms/bipartite/basic.py @@ -21,7 +21,7 @@ ] -@networkx_algorithm(plc="triangle_count", version_added="24.02") +@networkx_algorithm(version_added="24.02", _plc="triangle_count") def is_bipartite(G): G = _to_graph(G) # Counting triangles may not be the fastest way to do this, but it is simple. diff --git a/python/nx-cugraph/nx_cugraph/algorithms/centrality/betweenness.py b/python/nx-cugraph/nx_cugraph/algorithms/centrality/betweenness.py index ba2b3d9c895..f6bb142cded 100644 --- a/python/nx-cugraph/nx_cugraph/algorithms/centrality/betweenness.py +++ b/python/nx-cugraph/nx_cugraph/algorithms/centrality/betweenness.py @@ -21,8 +21,8 @@ @networkx_algorithm( is_incomplete=True, # weight not supported is_different=True, # RNG with seed is different - plc="betweenness_centrality", version_added="23.10", + _plc="betweenness_centrality", ) def betweenness_centrality( G, k=None, normalized=True, weight=None, endpoints=False, seed=None @@ -54,8 +54,8 @@ def _(G, k=None, normalized=True, weight=None, endpoints=False, seed=None): @networkx_algorithm( is_incomplete=True, # weight not supported is_different=True, # RNG with seed is different - plc="edge_betweenness_centrality", version_added="23.10", + _plc="edge_betweenness_centrality", ) def edge_betweenness_centrality(G, k=None, normalized=True, weight=None, seed=None): """`weight` parameter is not yet supported, and RNG with seed may be different.""" diff --git a/python/nx-cugraph/nx_cugraph/algorithms/centrality/eigenvector.py b/python/nx-cugraph/nx_cugraph/algorithms/centrality/eigenvector.py index 9e615955a8b..65a8633667a 100644 --- a/python/nx-cugraph/nx_cugraph/algorithms/centrality/eigenvector.py +++ b/python/nx-cugraph/nx_cugraph/algorithms/centrality/eigenvector.py @@ -29,8 +29,8 @@ @networkx_algorithm( extra_params=_dtype_param, is_incomplete=True, # nstart not supported - plc="eigenvector_centrality", version_added="23.12", + _plc="eigenvector_centrality", ) def eigenvector_centrality( G, max_iter=100, tol=1.0e-6, nstart=None, weight=None, *, dtype=None diff --git a/python/nx-cugraph/nx_cugraph/algorithms/centrality/katz.py b/python/nx-cugraph/nx_cugraph/algorithms/centrality/katz.py index a2fb950c1aa..4a0684f72ee 100644 --- a/python/nx-cugraph/nx_cugraph/algorithms/centrality/katz.py +++ b/python/nx-cugraph/nx_cugraph/algorithms/centrality/katz.py @@ -29,8 +29,8 @@ @networkx_algorithm( extra_params=_dtype_param, is_incomplete=True, # nstart and normalized=False not supported - plc="katz_centrality", version_added="23.12", + _plc="katz_centrality", ) def katz_centrality( G, diff --git a/python/nx-cugraph/nx_cugraph/algorithms/cluster.py b/python/nx-cugraph/nx_cugraph/algorithms/cluster.py index 951c358ff26..a458e6c04db 100644 --- a/python/nx-cugraph/nx_cugraph/algorithms/cluster.py +++ b/python/nx-cugraph/nx_cugraph/algorithms/cluster.py @@ -45,7 +45,7 @@ def _triangles(G, nodes, symmetrize=None): @not_implemented_for("directed") -@networkx_algorithm(plc="triangle_count", version_added="24.02") +@networkx_algorithm(version_added="24.02", _plc="triangle_count") def triangles(G, nodes=None): G = _to_undirected_graph(G) node_ids, triangles, is_single_node = _triangles(G, nodes) @@ -57,9 +57,13 @@ def triangles(G, nodes=None): @not_implemented_for("directed") -@networkx_algorithm(is_incomplete=True, plc="triangle_count", version_added="24.02") +@networkx_algorithm(is_incomplete=True, version_added="24.02", _plc="triangle_count") def clustering(G, nodes=None, weight=None): """Directed graphs and `weight` parameter are not yet supported.""" + if weight is not None: + raise NotImplementedError( + "Weighted implementation of clustering not currently supported" + ) G = _to_undirected_graph(G) node_ids, triangles, is_single_node = _triangles(G, nodes) if len(G) == 0: @@ -83,9 +87,13 @@ def _(G, nodes=None, weight=None): @not_implemented_for("directed") -@networkx_algorithm(is_incomplete=True, plc="triangle_count", version_added="24.02") +@networkx_algorithm(is_incomplete=True, version_added="24.02", _plc="triangle_count") def average_clustering(G, nodes=None, weight=None, count_zeros=True): """Directed graphs and `weight` parameter are not yet supported.""" + if weight is not None: + raise NotImplementedError( + "Weighted implementation of average_clustering not currently supported" + ) G = _to_undirected_graph(G) node_ids, triangles, is_single_node = _triangles(G, nodes) if len(G) == 0: @@ -110,7 +118,7 @@ def _(G, nodes=None, weight=None, count_zeros=True): @not_implemented_for("directed") -@networkx_algorithm(is_incomplete=True, plc="triangle_count", version_added="24.02") +@networkx_algorithm(is_incomplete=True, version_added="24.02", _plc="triangle_count") def transitivity(G): """Directed graphs are not yet supported.""" G = _to_undirected_graph(G) diff --git a/python/nx-cugraph/nx_cugraph/algorithms/community/louvain.py b/python/nx-cugraph/nx_cugraph/algorithms/community/louvain.py index 413ff9ca5e3..f58f1000fc4 100644 --- a/python/nx-cugraph/nx_cugraph/algorithms/community/louvain.py +++ b/python/nx-cugraph/nx_cugraph/algorithms/community/louvain.py @@ -36,8 +36,8 @@ }, is_incomplete=True, # seed not supported; self-loops not supported is_different=True, # RNG different - plc="louvain", version_added="23.10", + _plc="louvain", ) def louvain_communities( G, diff --git a/python/nx-cugraph/nx_cugraph/algorithms/components/connected.py b/python/nx-cugraph/nx_cugraph/algorithms/components/connected.py index cdb9f54f6c4..24955e3eac8 100644 --- a/python/nx-cugraph/nx_cugraph/algorithms/components/connected.py +++ b/python/nx-cugraph/nx_cugraph/algorithms/components/connected.py @@ -26,7 +26,7 @@ @not_implemented_for("directed") -@networkx_algorithm(plc="weakly_connected_components", version_added="23.12") +@networkx_algorithm(version_added="23.12", _plc="weakly_connected_components") def number_connected_components(G): G = _to_undirected_graph(G) return _number_connected_components(G) @@ -50,14 +50,11 @@ def _number_connected_components(G, symmetrize=None): @number_connected_components._can_run def _(G): # NetworkX <= 3.2.1 does not check directedness for us - try: - return not G.is_directed() - except Exception: - return False + return not G.is_directed() @not_implemented_for("directed") -@networkx_algorithm(plc="weakly_connected_components", version_added="23.12") +@networkx_algorithm(version_added="23.12", _plc="weakly_connected_components") def connected_components(G): G = _to_undirected_graph(G) return _connected_components(G) @@ -80,7 +77,7 @@ def _connected_components(G, symmetrize=None): @not_implemented_for("directed") -@networkx_algorithm(plc="weakly_connected_components", version_added="23.12") +@networkx_algorithm(version_added="23.12", _plc="weakly_connected_components") def is_connected(G): G = _to_undirected_graph(G) return _is_connected(G) @@ -106,7 +103,7 @@ def _is_connected(G, symmetrize=None): @not_implemented_for("directed") -@networkx_algorithm(plc="weakly_connected_components", version_added="23.12") +@networkx_algorithm(version_added="23.12", _plc="weakly_connected_components") def node_connected_component(G, n): # We could also do plain BFS from n G = _to_undirected_graph(G) diff --git a/python/nx-cugraph/nx_cugraph/algorithms/components/strongly_connected.py b/python/nx-cugraph/nx_cugraph/algorithms/components/strongly_connected.py index 8fdf99ed5ea..d1713129703 100644 --- a/python/nx-cugraph/nx_cugraph/algorithms/components/strongly_connected.py +++ b/python/nx-cugraph/nx_cugraph/algorithms/components/strongly_connected.py @@ -51,7 +51,7 @@ def _strongly_connected_components(G): @not_implemented_for("undirected") -@networkx_algorithm(version_added="24.02", plc="strongly_connected_components") +@networkx_algorithm(version_added="24.02", _plc="strongly_connected_components") def strongly_connected_components(G): G = _to_directed_graph(G) if G.src_indices.size == 0: @@ -62,7 +62,7 @@ def strongly_connected_components(G): @not_implemented_for("undirected") -@networkx_algorithm(version_added="24.02", plc="strongly_connected_components") +@networkx_algorithm(version_added="24.02", _plc="strongly_connected_components") def number_strongly_connected_components(G): G = _to_directed_graph(G) if G.src_indices.size == 0: @@ -72,7 +72,7 @@ def number_strongly_connected_components(G): @not_implemented_for("undirected") -@networkx_algorithm(version_added="24.02", plc="strongly_connected_components") +@networkx_algorithm(version_added="24.02", _plc="strongly_connected_components") def is_strongly_connected(G): G = _to_directed_graph(G) if len(G) == 0: diff --git a/python/nx-cugraph/nx_cugraph/algorithms/components/weakly_connected.py b/python/nx-cugraph/nx_cugraph/algorithms/components/weakly_connected.py index 5b797b39118..e42acdd3d84 100644 --- a/python/nx-cugraph/nx_cugraph/algorithms/components/weakly_connected.py +++ b/python/nx-cugraph/nx_cugraph/algorithms/components/weakly_connected.py @@ -27,21 +27,21 @@ @not_implemented_for("undirected") -@networkx_algorithm(plc="weakly_connected_components", version_added="24.02") +@networkx_algorithm(version_added="24.02", _plc="weakly_connected_components") def weakly_connected_components(G): G = _to_directed_graph(G) return _connected_components(G, symmetrize="union") @not_implemented_for("undirected") -@networkx_algorithm(plc="weakly_connected_components", version_added="24.02") +@networkx_algorithm(version_added="24.02", _plc="weakly_connected_components") def number_weakly_connected_components(G): G = _to_directed_graph(G) return _number_connected_components(G, symmetrize="union") @not_implemented_for("undirected") -@networkx_algorithm(plc="weakly_connected_components", version_added="24.02") +@networkx_algorithm(version_added="24.02", _plc="weakly_connected_components") def is_weakly_connected(G): G = _to_directed_graph(G) return _is_connected(G, symmetrize="union") diff --git a/python/nx-cugraph/nx_cugraph/algorithms/core.py b/python/nx-cugraph/nx_cugraph/algorithms/core.py index f323cdf6004..71f61abf45b 100644 --- a/python/nx-cugraph/nx_cugraph/algorithms/core.py +++ b/python/nx-cugraph/nx_cugraph/algorithms/core.py @@ -28,7 +28,7 @@ @not_implemented_for("directed") @not_implemented_for("multigraph") -@networkx_algorithm(is_incomplete=True, plc="core_number", version_added="24.02") +@networkx_algorithm(is_incomplete=True, version_added="24.02", _plc="core_number") def core_number(G): """Directed graphs are not yet supported.""" G = _to_undirected_graph(G) @@ -55,7 +55,7 @@ def _(G): @not_implemented_for("directed") @not_implemented_for("multigraph") -@networkx_algorithm(is_incomplete=True, plc="k_truss_subgraph", version_added="23.12") +@networkx_algorithm(is_incomplete=True, version_added="23.12", _plc="k_truss_subgraph") def k_truss(G, k): """ Currently raises `NotImplementedError` for graphs with more than one connected diff --git a/python/nx-cugraph/nx_cugraph/algorithms/dag.py b/python/nx-cugraph/nx_cugraph/algorithms/dag.py index ad5b7594aa1..64be0a58105 100644 --- a/python/nx-cugraph/nx_cugraph/algorithms/dag.py +++ b/python/nx-cugraph/nx_cugraph/algorithms/dag.py @@ -45,11 +45,11 @@ def _ancestors_and_descendants(G, source, *, is_ancestors): return G._nodearray_to_set(node_ids[mask]) -@networkx_algorithm(plc="bfs", version_added="24.02") +@networkx_algorithm(version_added="24.02", _plc="bfs") def descendants(G, source): return _ancestors_and_descendants(G, source, is_ancestors=False) -@networkx_algorithm(plc="bfs", version_added="24.02") +@networkx_algorithm(version_added="24.02", _plc="bfs") def ancestors(G, source): return _ancestors_and_descendants(G, source, is_ancestors=True) diff --git a/python/nx-cugraph/nx_cugraph/algorithms/link_analysis/hits_alg.py b/python/nx-cugraph/nx_cugraph/algorithms/link_analysis/hits_alg.py index caa01327a56..9e723624a3b 100644 --- a/python/nx-cugraph/nx_cugraph/algorithms/link_analysis/hits_alg.py +++ b/python/nx-cugraph/nx_cugraph/algorithms/link_analysis/hits_alg.py @@ -33,8 +33,8 @@ ), **_dtype_param, }, - plc="hits", version_added="23.12", + _plc="hits", ) def hits( G, diff --git a/python/nx-cugraph/nx_cugraph/algorithms/link_analysis/pagerank_alg.py b/python/nx-cugraph/nx_cugraph/algorithms/link_analysis/pagerank_alg.py index d45d019c1b7..55fcc3e520a 100644 --- a/python/nx-cugraph/nx_cugraph/algorithms/link_analysis/pagerank_alg.py +++ b/python/nx-cugraph/nx_cugraph/algorithms/link_analysis/pagerank_alg.py @@ -29,8 +29,8 @@ @networkx_algorithm( extra_params=_dtype_param, is_incomplete=True, # dangling not supported - plc={"pagerank", "personalized_pagerank"}, version_added="23.12", + _plc={"pagerank", "personalized_pagerank"}, ) def pagerank( G, diff --git a/python/nx-cugraph/nx_cugraph/algorithms/shortest_paths/unweighted.py b/python/nx-cugraph/nx_cugraph/algorithms/shortest_paths/unweighted.py index b1032a8236b..2012495953e 100644 --- a/python/nx-cugraph/nx_cugraph/algorithms/shortest_paths/unweighted.py +++ b/python/nx-cugraph/nx_cugraph/algorithms/shortest_paths/unweighted.py @@ -21,12 +21,12 @@ __all__ = ["single_source_shortest_path_length", "single_target_shortest_path_length"] -@networkx_algorithm(plc="bfs", version_added="23.12") +@networkx_algorithm(version_added="23.12", _plc="bfs") def single_source_shortest_path_length(G, source, cutoff=None): return _single_shortest_path_length(G, source, cutoff, "Source") -@networkx_algorithm(plc="bfs", version_added="23.12") +@networkx_algorithm(version_added="23.12", _plc="bfs") def single_target_shortest_path_length(G, target, cutoff=None): return _single_shortest_path_length(G, target, cutoff, "Target") diff --git a/python/nx-cugraph/nx_cugraph/algorithms/traversal/breadth_first_search.py b/python/nx-cugraph/nx_cugraph/algorithms/traversal/breadth_first_search.py index aa671bbb7d4..ef1c011363a 100644 --- a/python/nx-cugraph/nx_cugraph/algorithms/traversal/breadth_first_search.py +++ b/python/nx-cugraph/nx_cugraph/algorithms/traversal/breadth_first_search.py @@ -57,9 +57,17 @@ def _bfs(G, source, *, depth_limit=None, reverse=False): return distances[mask], predecessors[mask], node_ids[mask] -@networkx_algorithm(is_incomplete=True, plc="bfs", version_added="24.02") +@networkx_algorithm(is_incomplete=True, version_added="24.02", _plc="bfs") def generic_bfs_edges(G, source, neighbors=None, depth_limit=None, sort_neighbors=None): """`neighbors` and `sort_neighbors` parameters are not yet supported.""" + if neighbors is not None: + raise NotImplementedError( + "neighbors argument in generic_bfs_edges is not currently supported" + ) + if sort_neighbors is not None: + raise NotImplementedError( + "sort_neighbors argument in generic_bfs_edges is not currently supported" + ) return bfs_edges(source, depth_limit=depth_limit) @@ -68,9 +76,13 @@ def _(G, source, neighbors=None, depth_limit=None, sort_neighbors=None): return neighbors is None and sort_neighbors is None -@networkx_algorithm(is_incomplete=True, plc="bfs", version_added="24.02") +@networkx_algorithm(is_incomplete=True, version_added="24.02", _plc="bfs") def bfs_edges(G, source, reverse=False, depth_limit=None, sort_neighbors=None): """`sort_neighbors` parameter is not yet supported.""" + if sort_neighbors is not None: + raise NotImplementedError( + "sort_neighbors argument in bfs_edges is not currently supported" + ) G = _check_G_and_source(G, source) if depth_limit is not None and depth_limit < 1: return @@ -95,9 +107,13 @@ def _(G, source, reverse=False, depth_limit=None, sort_neighbors=None): return sort_neighbors is None -@networkx_algorithm(is_incomplete=True, plc="bfs", version_added="24.02") +@networkx_algorithm(is_incomplete=True, version_added="24.02", _plc="bfs") def bfs_tree(G, source, reverse=False, depth_limit=None, sort_neighbors=None): """`sort_neighbors` parameter is not yet supported.""" + if sort_neighbors is not None: + raise NotImplementedError( + "sort_neighbors argument in bfs_tree is not currently supported" + ) G = _check_G_and_source(G, source) if depth_limit is not None and depth_limit < 1: return nxcg.DiGraph.from_coo( @@ -149,9 +165,13 @@ def _(G, source, reverse=False, depth_limit=None, sort_neighbors=None): return sort_neighbors is None -@networkx_algorithm(is_incomplete=True, plc="bfs", version_added="24.02") +@networkx_algorithm(is_incomplete=True, version_added="24.02", _plc="bfs") def bfs_successors(G, source, depth_limit=None, sort_neighbors=None): """`sort_neighbors` parameter is not yet supported.""" + if sort_neighbors is not None: + raise NotImplementedError( + "sort_neighbors argument in bfs_successors is not currently supported" + ) G = _check_G_and_source(G, source) if depth_limit is not None and depth_limit < 1: yield (source, []) @@ -173,7 +193,7 @@ def _(G, source, depth_limit=None, sort_neighbors=None): return sort_neighbors is None -@networkx_algorithm(plc="bfs", version_added="24.02") +@networkx_algorithm(version_added="24.02", _plc="bfs") def bfs_layers(G, sources): G = _to_graph(G) if sources in G: @@ -201,9 +221,13 @@ def bfs_layers(G, sources): return (G._nodearray_to_list(groups[key]) for key in range(len(groups))) -@networkx_algorithm(is_incomplete=True, plc="bfs", version_added="24.02") +@networkx_algorithm(is_incomplete=True, version_added="24.02", _plc="bfs") def bfs_predecessors(G, source, depth_limit=None, sort_neighbors=None): """`sort_neighbors` parameter is not yet supported.""" + if sort_neighbors is not None: + raise NotImplementedError( + "sort_neighbors argument in bfs_predecessors is not currently supported" + ) G = _check_G_and_source(G, source) if depth_limit is not None and depth_limit < 1: return @@ -227,7 +251,7 @@ def _(G, source, depth_limit=None, sort_neighbors=None): return sort_neighbors is None -@networkx_algorithm(plc="bfs", version_added="24.02") +@networkx_algorithm(version_added="24.02", _plc="bfs") def descendants_at_distance(G, source, distance): G = _check_G_and_source(G, source) if distance is None or distance < 0: diff --git a/python/nx-cugraph/nx_cugraph/algorithms/tree/recognition.py b/python/nx-cugraph/nx_cugraph/algorithms/tree/recognition.py index 0b82f079d43..74f57b5ea5a 100644 --- a/python/nx-cugraph/nx_cugraph/algorithms/tree/recognition.py +++ b/python/nx-cugraph/nx_cugraph/algorithms/tree/recognition.py @@ -21,20 +21,20 @@ @not_implemented_for("undirected") -@networkx_algorithm(plc="weakly_connected_components", version_added="24.02") +@networkx_algorithm(version_added="24.02", _plc="weakly_connected_components") def is_arborescence(G): G = _to_directed_graph(G) return is_tree(G) and int(G._in_degrees_array().max()) <= 1 @not_implemented_for("undirected") -@networkx_algorithm(plc="weakly_connected_components", version_added="24.02") +@networkx_algorithm(version_added="24.02", _plc="weakly_connected_components") def is_branching(G): G = _to_directed_graph(G) return is_forest(G) and int(G._in_degrees_array().max()) <= 1 -@networkx_algorithm(plc="weakly_connected_components", version_added="24.02") +@networkx_algorithm(version_added="24.02", _plc="weakly_connected_components") def is_forest(G): G = _to_graph(G) if len(G) == 0: @@ -60,7 +60,7 @@ def is_forest(G): return True -@networkx_algorithm(plc="weakly_connected_components", version_added="24.02") +@networkx_algorithm(version_added="24.02", _plc="weakly_connected_components") def is_tree(G): G = _to_graph(G) if len(G) == 0: diff --git a/python/nx-cugraph/nx_cugraph/utils/decorators.py b/python/nx-cugraph/nx_cugraph/utils/decorators.py index d09a9e9617a..011ebfd6ef7 100644 --- a/python/nx-cugraph/nx_cugraph/utils/decorators.py +++ b/python/nx-cugraph/nx_cugraph/utils/decorators.py @@ -59,7 +59,7 @@ def __new__( version_added: str, # Required is_incomplete: bool = False, # See self.extra_doc for details if True is_different: bool = False, # See self.extra_doc for details if True - plc: str | set[str] | None = None, # Hidden from user, may be removed someday + _plc: str | set[str] | None = None, # Hidden from user, may be removed someday ): if func is None: return partial( @@ -67,10 +67,10 @@ def __new__( name=name, extra_params=extra_params, nodes_or_number=nodes_or_number, - plc=plc, version_added=version_added, is_incomplete=is_incomplete, is_different=is_different, + _plc=_plc, ) instance = object.__new__(cls) if nodes_or_number is not None and nx.__version__[:3] > "3.2": @@ -89,12 +89,14 @@ def __new__( f"extra_params must be dict, str, or None; got {type(extra_params)}" ) instance.extra_params = extra_params - if plc is None or isinstance(plc, set): - instance._plc_names = plc - elif isinstance(plc, str): - instance._plc_names = {plc} + if _plc is None or isinstance(_plc, set): + instance._plc_names = _plc + elif isinstance(_plc, str): + instance._plc_names = {_plc} else: - raise TypeError(f"plc argument must be str, set, or None; got {type(plc)}") + raise TypeError( + f"_plc argument must be str, set, or None; got {type(_plc)}" + ) instance.version_added = version_added instance.is_incomplete = is_incomplete instance.is_different = is_different