From cf8e3649b91ecd5ed4459ca627f6b1e233d979d0 Mon Sep 17 00:00:00 2001 From: Semyon Moroz Date: Fri, 30 May 2025 14:37:40 +0000 Subject: [PATCH] Bump networkx to 3.5 (#14196) --- stubs/networkx/@tests/stubtest_allowlist.txt | 3 - stubs/networkx/METADATA.toml | 2 +- .../algorithms/approximation/__init__.pyi | 1 + .../algorithms/approximation/density.pyi | 15 +++++ .../algorithms/approximation/treewidth.pyi | 2 +- .../algorithms/bipartite/__init__.pyi | 1 + .../algorithms/bipartite/link_analysis.pyi | 20 ++++++ .../algorithms/community/__init__.pyi | 2 + .../networkx/algorithms/community/leiden.pyi | 18 ++++++ .../networkx/algorithms/community/local.pyi | 15 +++++ .../networkx/algorithms/d_separation.pyi | 6 +- .../networkx/algorithms/distance_measures.pyi | 23 ++++--- .../networkx/algorithms/dominating.pyi | 8 ++- .../algorithms/isomorphism/isomorph.pyi | 30 +++++---- .../isomorphism/tree_isomorphism.pyi | 4 -- .../algorithms/minors/contraction.pyi | 13 +++- .../networkx/algorithms/planarity.pyi | 1 + .../networkx/algorithms/similarity.pyi | 4 +- .../networkx/algorithms/threshold.pyi | 9 +-- .../networkx/algorithms/tournament.pyi | 12 +++- stubs/networkx/networkx/algorithms/triads.pyi | 7 +-- stubs/networkx/networkx/classes/function.pyi | 34 ++++++++-- stubs/networkx/networkx/drawing/layout.pyi | 62 +++++++++++++----- stubs/networkx/networkx/drawing/nx_pylab.pyi | 63 ++++++++++++++----- .../generators/nonisomorphic_trees.pyi | 2 +- .../networkx/linalg/laplacianmatrix.pyi | 3 - stubs/networkx/networkx/utils/backends.pyi | 5 +- 27 files changed, 273 insertions(+), 92 deletions(-) create mode 100644 stubs/networkx/networkx/algorithms/approximation/density.pyi create mode 100644 stubs/networkx/networkx/algorithms/bipartite/link_analysis.pyi create mode 100644 stubs/networkx/networkx/algorithms/community/leiden.pyi create mode 100644 stubs/networkx/networkx/algorithms/community/local.pyi diff --git a/stubs/networkx/@tests/stubtest_allowlist.txt b/stubs/networkx/@tests/stubtest_allowlist.txt index 42dc072b1..750b9fd96 100644 --- a/stubs/networkx/@tests/stubtest_allowlist.txt +++ b/stubs/networkx/@tests/stubtest_allowlist.txt @@ -16,9 +16,6 @@ networkx\.(algorithms\.)?(centrality\.)?(current_flow_closeness\.)?information_c networkx\.(generators\.)?(random_graphs\.)?binomial_graph networkx\.(generators\.)?(random_graphs\.)?erdos_renyi_graph networkx\.(algorithms\.(minors\.(contraction\.)?)?)?identified_nodes -networkx\.algorithms\.isomorphism\.isomorph\.faster_graph_could_be_isomorphic -networkx\.algorithms\.isomorphism\.isomorph\.fast_graph_could_be_isomorphic -networkx\.algorithms\.isomorphism\.isomorph\.graph_could_be_isomorphic networkx\.algorithms\.flow\.maxflow\.default_flow_func networkx\.algorithms\.[a-z_\.]+\.default_flow_func networkx\.(algorithms\.(centrality\.(load\.)?)?)?load_centrality diff --git a/stubs/networkx/METADATA.toml b/stubs/networkx/METADATA.toml index 387904a34..99c93ff41 100644 --- a/stubs/networkx/METADATA.toml +++ b/stubs/networkx/METADATA.toml @@ -1,4 +1,4 @@ -version = "3.4.2" +version = "3.5" upstream_repository = "https://github.com/networkx/networkx" # requires a version of numpy with a `py.typed` file requires = ["numpy>=1.20"] diff --git a/stubs/networkx/networkx/algorithms/approximation/__init__.pyi b/stubs/networkx/networkx/algorithms/approximation/__init__.pyi index b355e7f39..c80fffaef 100644 --- a/stubs/networkx/networkx/algorithms/approximation/__init__.pyi +++ b/stubs/networkx/networkx/algorithms/approximation/__init__.pyi @@ -1,6 +1,7 @@ from networkx.algorithms.approximation.clique import * from networkx.algorithms.approximation.clustering_coefficient import * from networkx.algorithms.approximation.connectivity import * +from networkx.algorithms.approximation.density import * from networkx.algorithms.approximation.distance_measures import * from networkx.algorithms.approximation.dominating_set import * from networkx.algorithms.approximation.kcomponents import * diff --git a/stubs/networkx/networkx/algorithms/approximation/density.pyi b/stubs/networkx/networkx/algorithms/approximation/density.pyi new file mode 100644 index 000000000..b5cd3cb16 --- /dev/null +++ b/stubs/networkx/networkx/algorithms/approximation/density.pyi @@ -0,0 +1,15 @@ +from collections.abc import Callable, Hashable +from typing import Literal +from typing_extensions import TypeAlias + +from networkx.classes.graph import Graph, _Node +from networkx.utils.backends import _dispatchable + +_Algorithm: TypeAlias = Literal["greedy++", "fista"] + +__all__ = ["densest_subgraph"] + +ALGORITHMS: dict[_Algorithm, Callable[[Graph[Hashable], int], tuple[float, set[int]]]] + +@_dispatchable +def densest_subgraph(G: Graph[_Node], iterations: int = 1, *, method: _Algorithm = "fista") -> tuple[float, set[int]]: ... diff --git a/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi b/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi index 02b275350..00f95e3eb 100644 --- a/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi +++ b/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi @@ -16,6 +16,6 @@ class MinDegreeHeuristic: def __init__(self, graph) -> None: ... def best_node(self, graph): ... -def min_fill_in_heuristic(graph) -> Incomplete | None: ... +def min_fill_in_heuristic(graph_dict) -> Incomplete | None: ... @_dispatchable def treewidth_decomp(G: Graph[_Node], heuristic=...) -> tuple[int, Graph[_Node]]: ... diff --git a/stubs/networkx/networkx/algorithms/bipartite/__init__.pyi b/stubs/networkx/networkx/algorithms/bipartite/__init__.pyi index 0df90e4f1..7b9c7b3c0 100644 --- a/stubs/networkx/networkx/algorithms/bipartite/__init__.pyi +++ b/stubs/networkx/networkx/algorithms/bipartite/__init__.pyi @@ -5,6 +5,7 @@ from networkx.algorithms.bipartite.covering import * from networkx.algorithms.bipartite.edgelist import * from networkx.algorithms.bipartite.extendability import * from networkx.algorithms.bipartite.generators import * +from networkx.algorithms.bipartite.link_analysis import * from networkx.algorithms.bipartite.matching import * from networkx.algorithms.bipartite.matrix import * from networkx.algorithms.bipartite.projection import * diff --git a/stubs/networkx/networkx/algorithms/bipartite/link_analysis.pyi b/stubs/networkx/networkx/algorithms/bipartite/link_analysis.pyi new file mode 100644 index 000000000..b68618699 --- /dev/null +++ b/stubs/networkx/networkx/algorithms/bipartite/link_analysis.pyi @@ -0,0 +1,20 @@ +from collections.abc import Iterable + +from networkx.classes.graph import Graph, _Node +from networkx.utils.backends import _dispatchable + +__all__ = ["birank"] + +@_dispatchable +def birank( + G: Graph[_Node], + nodes: Iterable[_Node], + *, + alpha: float | None = None, + beta: float | None = None, + top_personalization: dict[str, int] | None = None, + bottom_personalization: dict[str, int] | None = None, + max_iter: int = 100, + tol: float = 1.0e-6, + weight: str | None = "weight", +) -> dict[_Node, float]: ... diff --git a/stubs/networkx/networkx/algorithms/community/__init__.pyi b/stubs/networkx/networkx/algorithms/community/__init__.pyi index fd1d0c644..2ac869a36 100644 --- a/stubs/networkx/networkx/algorithms/community/__init__.pyi +++ b/stubs/networkx/networkx/algorithms/community/__init__.pyi @@ -5,6 +5,8 @@ from networkx.algorithms.community.divisive import * from networkx.algorithms.community.kclique import * from networkx.algorithms.community.kernighan_lin import * from networkx.algorithms.community.label_propagation import * +from networkx.algorithms.community.leiden import * +from networkx.algorithms.community.local import * from networkx.algorithms.community.louvain import * from networkx.algorithms.community.lukes import * from networkx.algorithms.community.modularity_max import * diff --git a/stubs/networkx/networkx/algorithms/community/leiden.pyi b/stubs/networkx/networkx/algorithms/community/leiden.pyi new file mode 100644 index 000000000..6c6d88e39 --- /dev/null +++ b/stubs/networkx/networkx/algorithms/community/leiden.pyi @@ -0,0 +1,18 @@ +from networkx.classes.graph import Graph, _Node +from networkx.utils.backends import _dispatchable +from numpy.random import RandomState + +__all__ = ["leiden_communities", "leiden_partitions"] + +@_dispatchable +def leiden_communities( + G: Graph[_Node], + weight: str | None = "weight", + resolution: float = 1, + max_level: int | None = None, + seed: int | RandomState | None = None, +): ... +@_dispatchable +def leiden_partitions( + G: Graph[_Node], weight: str | None = "weight", resolution: float = 1, seed: int | RandomState | None = None +): ... diff --git a/stubs/networkx/networkx/algorithms/community/local.pyi b/stubs/networkx/networkx/algorithms/community/local.pyi new file mode 100644 index 000000000..4825f9645 --- /dev/null +++ b/stubs/networkx/networkx/algorithms/community/local.pyi @@ -0,0 +1,15 @@ +from collections.abc import Callable, Hashable +from typing import Literal +from typing_extensions import TypeAlias + +from networkx.classes.graph import Graph, _Node + +__all__ = ["greedy_source_expansion"] + +_Algorithm: TypeAlias = Literal["clauset"] + +ALGORITHMS: dict[_Algorithm, Callable[[Graph[Hashable], Hashable, int | None], set[Hashable]]] + +def greedy_source_expansion( + G: Graph[_Node], *, source: _Node, cutoff: int | None = None, method: _Algorithm = "clauset" +) -> set[_Node | None]: ... diff --git a/stubs/networkx/networkx/algorithms/d_separation.pyi b/stubs/networkx/networkx/algorithms/d_separation.pyi index b3de331d8..0abd1f396 100644 --- a/stubs/networkx/networkx/algorithms/d_separation.pyi +++ b/stubs/networkx/networkx/algorithms/d_separation.pyi @@ -4,17 +4,13 @@ from networkx.classes.digraph import DiGraph from networkx.classes.graph import _Node from networkx.utils.backends import _dispatchable -__all__ = ["is_d_separator", "is_minimal_d_separator", "find_minimal_d_separator", "d_separated", "minimal_d_separator"] +__all__ = ["is_d_separator", "is_minimal_d_separator", "find_minimal_d_separator"] @_dispatchable def is_d_separator(G: DiGraph[_Node], x: _Node | set[_Node], y: _Node | set[_Node], z: _Node | set[_Node]) -> bool: ... @_dispatchable def find_minimal_d_separator(G, x, y, *, included=None, restricted=None) -> set[Incomplete] | None: ... @_dispatchable -def d_separated(G, x, y, z): ... -@_dispatchable -def minimal_d_separator(G, u, v): ... -@_dispatchable def is_minimal_d_separator( G: DiGraph[_Node], x: _Node | set[_Node], diff --git a/stubs/networkx/networkx/algorithms/distance_measures.pyi b/stubs/networkx/networkx/algorithms/distance_measures.pyi index a74483194..26f5a618f 100644 --- a/stubs/networkx/networkx/algorithms/distance_measures.pyi +++ b/stubs/networkx/networkx/algorithms/distance_measures.pyi @@ -1,6 +1,11 @@ +from collections.abc import Callable +from typing_extensions import TypeAlias + from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable +_WeightFunction: TypeAlias = Callable[..., int] + __all__ = [ "eccentricity", "diameter", @@ -15,22 +20,22 @@ __all__ = [ ] @_dispatchable -def eccentricity(G: Graph[_Node], v: _Node | None = None, sp=None, weight: str | None = None): ... +def eccentricity(G: Graph[_Node], v: _Node | None = None, sp=None, weight: str | _WeightFunction | None = None): ... @_dispatchable -def diameter(G: Graph[_Node], e=None, usebounds=False, weight: str | None = None): ... +def diameter(G: Graph[_Node], e=None, usebounds: bool = False, weight: str | _WeightFunction | None = None): ... @_dispatchable -def harmonic_diameter(G, sp=None) -> float: ... +def harmonic_diameter(G, sp=None, *, weight: str | _WeightFunction | None = None) -> float: ... @_dispatchable -def periphery(G: Graph[_Node], e=None, usebounds=False, weight: str | None = None): ... +def periphery(G: Graph[_Node], e=None, usebounds: bool = False, weight: str | _WeightFunction | None = None): ... @_dispatchable -def radius(G: Graph[_Node], e=None, usebounds=False, weight: str | None = None): ... +def radius(G: Graph[_Node], e=None, usebounds: bool = False, weight: str | _WeightFunction | None = None): ... @_dispatchable -def center(G: Graph[_Node], e=None, usebounds=False, weight: str | None = None): ... +def center(G: Graph[_Node], e=None, usebounds: bool = False, weight: str | _WeightFunction | None = None): ... @_dispatchable -def barycenter(G, weight: str | None = None, attr=None, sp=None): ... +def barycenter(G, weight: str | _WeightFunction | None = None, attr=None, sp=None): ... @_dispatchable def resistance_distance(G: Graph[_Node], nodeA=None, nodeB=None, weight: str | None = None, invert_weight: bool = True): ... @_dispatchable -def effective_graph_resistance(G, weight=None, invert_weight=True) -> float: ... +def effective_graph_resistance(G, weight: str | None = None, invert_weight: bool = True) -> float: ... @_dispatchable -def kemeny_constant(G, *, weight=None) -> float: ... +def kemeny_constant(G, *, weight: str | None = None) -> float: ... diff --git a/stubs/networkx/networkx/algorithms/dominating.pyi b/stubs/networkx/networkx/algorithms/dominating.pyi index 4b3983e58..6a3eb9a4f 100644 --- a/stubs/networkx/networkx/algorithms/dominating.pyi +++ b/stubs/networkx/networkx/algorithms/dominating.pyi @@ -3,9 +3,13 @@ from collections.abc import Iterable from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable -__all__ = ["dominating_set", "is_dominating_set"] +__all__ = ["dominating_set", "is_dominating_set", "connected_dominating_set", "is_connected_dominating_set"] @_dispatchable -def dominating_set(G: Graph[_Node], start_with: _Node | None = None): ... +def dominating_set(G: Graph[_Node], start_with: _Node | None = None) -> set[_Node]: ... @_dispatchable def is_dominating_set(G: Graph[_Node], nbunch: Iterable[_Node]) -> bool: ... +@_dispatchable +def connected_dominating_set(G: Graph[_Node]) -> set[_Node]: ... +@_dispatchable +def is_connected_dominating_set(G: Graph[_Node], nbunch: Iterable[_Node]) -> bool: ... diff --git a/stubs/networkx/networkx/algorithms/isomorphism/isomorph.pyi b/stubs/networkx/networkx/algorithms/isomorphism/isomorph.pyi index 369615e1b..ebfbdf83d 100644 --- a/stubs/networkx/networkx/algorithms/isomorphism/isomorph.pyi +++ b/stubs/networkx/networkx/algorithms/isomorphism/isomorph.pyi @@ -1,5 +1,6 @@ from _typeshed import Incomplete from collections.abc import Callable +from typing_extensions import deprecated from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable @@ -7,24 +8,27 @@ from networkx.utils.backends import _dispatchable __all__ = ["could_be_isomorphic", "fast_could_be_isomorphic", "faster_could_be_isomorphic", "is_isomorphic"] @_dispatchable -def could_be_isomorphic(G1: Graph[_Node], G2: Graph[_Node]): ... - -graph_could_be_isomorphic = could_be_isomorphic - +def could_be_isomorphic(G1: Graph[_Node], G2: Graph[_Node], *, properties: str = "dtc") -> bool: ... +@deprecated("`graph_could_be_isomorphic` is a deprecated alias for `could_be_isomorphic`. Use `could_be_isomorphic` instead.") +def graph_could_be_isomorphic(G1: Graph[_Node], G2: Graph[_Node]) -> bool: ... @_dispatchable -def fast_could_be_isomorphic(G1: Graph[_Node], G2: Graph[_Node]): ... - -fast_graph_could_be_isomorphic = fast_could_be_isomorphic - +def fast_could_be_isomorphic(G1: Graph[_Node], G2: Graph[_Node]) -> bool: ... +@deprecated( + "`fast_graph_could_be_isomorphic` is a deprecated alias for `fast_could_be_isomorphic`. " + "Use `fast_could_be_isomorphic` instead." +) +def fast_graph_could_be_isomorphic(G1: Graph[_Node], G2: Graph[_Node]) -> bool: ... @_dispatchable -def faster_could_be_isomorphic(G1: Graph[_Node], G2: Graph[_Node]): ... - -faster_graph_could_be_isomorphic = faster_could_be_isomorphic - +def faster_could_be_isomorphic(G1: Graph[_Node], G2: Graph[_Node]) -> bool: ... +@deprecated( + "`faster_graph_could_be_isomorphic` is a deprecated alias for `faster_could_be_isomorphic`. " + "Use `faster_could_be_isomorphic` instead." +) +def faster_graph_could_be_isomorphic(G1: Graph[_Node], G2: Graph[_Node]) -> bool: ... @_dispatchable def is_isomorphic( G1: Graph[_Node], G2: Graph[_Node], node_match: Callable[..., Incomplete] | None = None, edge_match: Callable[..., Incomplete] | None = None, -): ... +) -> bool: ... diff --git a/stubs/networkx/networkx/algorithms/isomorphism/tree_isomorphism.pyi b/stubs/networkx/networkx/algorithms/isomorphism/tree_isomorphism.pyi index ce5938149..7a193aa7f 100644 --- a/stubs/networkx/networkx/algorithms/isomorphism/tree_isomorphism.pyi +++ b/stubs/networkx/networkx/algorithms/isomorphism/tree_isomorphism.pyi @@ -6,10 +6,6 @@ __all__ = ["rooted_tree_isomorphism", "tree_isomorphism"] @_dispatchable def root_trees(t1, root1, t2, root2): ... @_dispatchable -def assign_levels(G: Graph[_Node], root): ... -def group_by_levels(levels): ... -def generate_isomorphism(v, w, M, ordered_children): ... -@_dispatchable def rooted_tree_isomorphism(t1, root1, t2, root2): ... @_dispatchable def tree_isomorphism(t1: Graph[_Node], t2: Graph[_Node]): ... diff --git a/stubs/networkx/networkx/algorithms/minors/contraction.pyi b/stubs/networkx/networkx/algorithms/minors/contraction.pyi index 200e9f2fc..71106f406 100644 --- a/stubs/networkx/networkx/algorithms/minors/contraction.pyi +++ b/stubs/networkx/networkx/algorithms/minors/contraction.pyi @@ -20,9 +20,18 @@ def quotient_graph( create_using: Graph[_Node] | None = None, ): ... @_dispatchable -def contracted_nodes(G: Graph[_Node], u, v, self_loops: bool = True, copy: bool = True): ... +def contracted_nodes( + G: Graph[_Node], u, v, self_loops: bool = True, copy: bool = True, *, store_contraction_as: str | None = "contraction" +): ... identified_nodes = contracted_nodes @_dispatchable -def contracted_edge(G: Graph[_Node], edge: tuple[Incomplete], self_loops: bool = True, copy: bool = True): ... +def contracted_edge( + G: Graph[_Node], + edge: tuple[Incomplete], + self_loops: bool = True, + copy: bool = True, + *, + store_contraction_as: str | None = "contraction", +): ... diff --git a/stubs/networkx/networkx/algorithms/planarity.pyi b/stubs/networkx/networkx/algorithms/planarity.pyi index 946d24741..f444db487 100644 --- a/stubs/networkx/networkx/algorithms/planarity.pyi +++ b/stubs/networkx/networkx/algorithms/planarity.pyi @@ -81,3 +81,4 @@ class PlanarEmbedding(DiGraph[_Node]): def traverse_face( self, v: _Node, w: _Node, mark_half_edges: MutableSet[tuple[_Node, _Node]] | None = None ) -> list[_Node]: ... + def to_undirected(self, reciprocal: bool = False, as_view: bool = False) -> Graph[_Node]: ... # type: ignore[override] diff --git a/stubs/networkx/networkx/algorithms/similarity.pyi b/stubs/networkx/networkx/algorithms/similarity.pyi index 822a9e46d..d50ded128 100644 --- a/stubs/networkx/networkx/algorithms/similarity.pyi +++ b/stubs/networkx/networkx/algorithms/similarity.pyi @@ -104,4 +104,6 @@ def generate_random_paths( index_map: SupportsGetItem[Incomplete, Incomplete] | None = None, weight: str | None = "weight", seed: int | RandomState | None = None, -) -> Generator[Incomplete, None, None]: ... + *, + source: _Node | None = None, +) -> Generator[list[Incomplete]]: ... diff --git a/stubs/networkx/networkx/algorithms/threshold.pyi b/stubs/networkx/networkx/algorithms/threshold.pyi index d5a0361e2..73471f8f8 100644 --- a/stubs/networkx/networkx/algorithms/threshold.pyi +++ b/stubs/networkx/networkx/algorithms/threshold.pyi @@ -2,6 +2,7 @@ from collections.abc import Sequence from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable +from numpy.random import RandomState __all__ = ["is_threshold_graph", "find_threshold_graph"] @@ -33,7 +34,7 @@ def betweenness_sequence(creation_sequence, normalized=True): ... def eigenvectors(creation_sequence): ... def spectral_projection(u, eigenpairs): ... def eigenvalues(creation_sequence): ... -def random_threshold_sequence(n, p, seed=None): ... -def right_d_threshold_sequence(n, m): ... -def left_d_threshold_sequence(n, m): ... -def swap_d(cs, p_split=1.0, p_combine=1.0, seed=None): ... +def random_threshold_sequence(n, p, seed: int | RandomState | None = None): ... +def right_d_threshold_sequence(n: int, m: int) -> list[str]: ... +def left_d_threshold_sequence(n: int, m: int) -> list[str]: ... +def swap_d(cs, p_split=1.0, p_combine=1.0, seed: int | RandomState | None = None): ... diff --git a/stubs/networkx/networkx/algorithms/tournament.pyi b/stubs/networkx/networkx/algorithms/tournament.pyi index f2de11bbc..5b6046f5c 100644 --- a/stubs/networkx/networkx/algorithms/tournament.pyi +++ b/stubs/networkx/networkx/algorithms/tournament.pyi @@ -2,7 +2,15 @@ from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable from numpy.random import RandomState -__all__ = ["hamiltonian_path", "is_reachable", "is_strongly_connected", "is_tournament", "random_tournament", "score_sequence"] +__all__ = [ + "hamiltonian_path", + "is_reachable", + "is_strongly_connected", + "is_tournament", + "random_tournament", + "score_sequence", + "tournament_matrix", +] @_dispatchable def is_tournament(G: Graph[_Node]) -> bool: ... @@ -11,6 +19,8 @@ def hamiltonian_path(G: Graph[_Node]): ... @_dispatchable def random_tournament(n: int, seed: int | RandomState | None = None): ... @_dispatchable +def tournament_matrix(G: Graph[_Node]): ... +@_dispatchable def score_sequence(G: Graph[_Node]): ... @_dispatchable def is_reachable(G: Graph[_Node], s: _Node, t: _Node) -> bool: ... diff --git a/stubs/networkx/networkx/algorithms/triads.pyi b/stubs/networkx/networkx/algorithms/triads.pyi index 23da6821c..f155a93de 100644 --- a/stubs/networkx/networkx/algorithms/triads.pyi +++ b/stubs/networkx/networkx/algorithms/triads.pyi @@ -5,9 +5,8 @@ from typing import Final from networkx.classes.digraph import DiGraph from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable -from numpy.random import RandomState -__all__ = ["triadic_census", "is_triad", "all_triplets", "all_triads", "triads_by_type", "triad_type", "random_triad"] +__all__ = ["triadic_census", "is_triad", "all_triads", "triads_by_type", "triad_type"] TRICODES: Final[tuple[int, ...]] TRIAD_NAMES: Final[tuple[str, ...]] @@ -18,12 +17,8 @@ def triadic_census(G: DiGraph[_Node], nodelist: Collection[_Node] | None = None) @_dispatchable def is_triad(G: Graph[_Node]) -> bool: ... @_dispatchable -def all_triplets(G: DiGraph[_Node]): ... -@_dispatchable def all_triads(G: DiGraph[_Node]) -> Generator[Incomplete, None, None]: ... @_dispatchable def triads_by_type(G: DiGraph[_Node]): ... @_dispatchable def triad_type(G: DiGraph[_Node]): ... -@_dispatchable -def random_triad(G: DiGraph[_Node], seed: int | RandomState | None = None): ... diff --git a/stubs/networkx/networkx/classes/function.pyi b/stubs/networkx/networkx/classes/function.pyi index 1eb41e0a4..a200536cf 100644 --- a/stubs/networkx/networkx/classes/function.pyi +++ b/stubs/networkx/networkx/classes/function.pyi @@ -81,30 +81,55 @@ def create_empty_copy(G, with_data: bool = True): ... # incomplete: Can "Any scalar value" be enforced? @overload -def set_node_attributes(G: Graph[Hashable], values: SupportsItems[_Node, Unused], name: str) -> None: ... +def set_node_attributes( + G: Graph[Hashable], + values: SupportsItems[_Node, Unused], + name: str, + *, + backend=None, # @_dispatchable adds these arguments, but we can't use this decorator with @overload + **backend_kwargs, +) -> None: ... @overload def set_node_attributes( G: Graph[_Node], values: SupportsItems[_Node, SupportsKeysAndGetItem[Incomplete, Incomplete] | Iterable[tuple[Incomplete, Incomplete]]], name: None = None, + *, + backend=None, + **backend_kwargs, ) -> None: ... +@_dispatchable def get_node_attributes(G: Graph[_Node], name: str, default=None) -> dict[_Node, Incomplete]: ... +@_dispatchable def remove_node_attributes(G, *attr_names, nbunch=None) -> None: ... @overload -def set_edge_attributes(G: Graph[_Node], values: SupportsItems[tuple[_Node, _Node], Incomplete], name: str) -> None: ... +def set_edge_attributes( + G: Graph[_Node], + values: SupportsItems[tuple[_Node, _Node], Incomplete], + name: str, + *, + backend=None, # @_dispatchable adds these arguments, but we can't use this decorator with @overload + **backend_kwargs, +) -> None: ... @overload -def set_edge_attributes(G: MultiGraph[_Node], values: dict[tuple[_Node, _Node, Incomplete], Incomplete], name: str) -> None: ... +def set_edge_attributes( + G: MultiGraph[_Node], values: dict[tuple[_Node, _Node, Incomplete], Incomplete], name: str, *, backend=None, **backend_kwargs +) -> None: ... @overload -def set_edge_attributes(G: Graph[Hashable], values, name: None = None) -> None: ... +def set_edge_attributes(G: Graph[Hashable], values, name: None = None, *, backend=None, **backend_kwargs) -> None: ... +@_dispatchable def get_edge_attributes(G: Graph[_Node], name: str, default=None) -> dict[tuple[_Node, _Node], Incomplete]: ... +@_dispatchable def remove_edge_attributes(G, *attr_names, ebunch=None) -> None: ... def all_neighbors(graph: Graph[_Node], node: _Node) -> Iterator[_Node]: ... def non_neighbors(graph: Graph[_Node], node: _Node) -> Generator[_Node, None, None]: ... def non_edges(graph: Graph[_Node]) -> Generator[tuple[_Node, _Node], None, None]: ... def common_neighbors(G: Graph[_Node], u: _Node, v: _Node) -> Generator[_Node, None, None]: ... +@_dispatchable def is_weighted(G: Graph[_Node], edge: tuple[_Node, _Node] | None = None, weight: str = "weight") -> bool: ... @_dispatchable def is_negatively_weighted(G: Graph[_Node], edge: tuple[_Node, _Node] | None = None, weight: str = "weight") -> bool: ... +@_dispatchable def is_empty(G: Graph[Hashable]) -> bool: ... def nodes_with_selfloops(G: Graph[_Node]) -> Generator[_Node, None, None]: ... @overload @@ -135,6 +160,7 @@ def selfloop_edges( def selfloop_edges( G: Graph[_Node], data: str, keys: Literal[True], default: _U | None = None ) -> Generator[tuple[_Node, _Node, int, _U], None, None]: ... +@_dispatchable def number_of_selfloops(G: Graph[Hashable]) -> int: ... def is_path(G: Graph[_Node], path: Iterable[Incomplete]) -> bool: ... def path_weight(G, path, weight) -> int: ... diff --git a/stubs/networkx/networkx/drawing/layout.pyi b/stubs/networkx/networkx/drawing/layout.pyi index 56bafec5d..d25734345 100644 --- a/stubs/networkx/networkx/drawing/layout.pyi +++ b/stubs/networkx/networkx/drawing/layout.pyi @@ -1,6 +1,7 @@ from _typeshed import Incomplete -import numpy +from networkx.utils.backends import _dispatchable +from numpy.random import RandomState __all__ = [ "bipartite_layout", @@ -21,10 +22,18 @@ __all__ = [ "arf_layout", ] -def random_layout(G, center=None, dim: int = 2, seed=None): ... -def circular_layout(G, scale: float = 1, center=None, dim: int = 2): ... -def shell_layout(G, nlist=None, rotate=None, scale: float = 1, center=None, dim: int = 2): ... -def bipartite_layout(G, nodes, align: str = "vertical", scale: float = 1, center=None, aspect_ratio: float = ...): ... +def random_layout(G, center=None, dim: int = 2, seed: int | RandomState | None = None, store_pos_as: str | None = None): ... +def circular_layout(G, scale: float = 1, center=None, dim: int = 2, store_pos_as: str | None = None): ... +def shell_layout(G, nlist=None, rotate=None, scale: float = 1, center=None, dim: int = 2, store_pos_as: str | None = None): ... +def bipartite_layout( + G, + nodes=None, + align: str = "vertical", + scale: float = 1, + center=None, + aspect_ratio: float = ..., + store_pos_as: str | None = None, +): ... def spring_layout( G, k=None, @@ -36,16 +45,32 @@ def spring_layout( scale: float = 1, center=None, dim: int = 2, - seed=None, + seed: int | RandomState | None = None, + store_pos_as: str | None = None, + *, + method: str = "auto", + gravity: float = 1.0, ): ... fruchterman_reingold_layout = spring_layout -def kamada_kawai_layout(G, dist=None, pos=None, weight: str = "weight", scale: float = 1, center=None, dim: int = 2): ... -def spectral_layout(G, weight: str = "weight", scale: float = 1, center=None, dim: int = 2): ... -def planar_layout(G, scale: float = 1, center=None, dim: int = 2): ... -def spiral_layout(G, scale: float = 1, center=None, dim: int = 2, resolution: float = 0.35, equidistant: bool = False): ... -def multipartite_layout(G, subset_key: str = "subset", align: str = "vertical", scale: float = 1, center=None): ... +def kamada_kawai_layout( + G, dist=None, pos=None, weight: str = "weight", scale: float = 1, center=None, dim: int = 2, store_pos_as: str | None = None +): ... +def spectral_layout(G, weight: str = "weight", scale: float = 1, center=None, dim: int = 2, store_pos_as: str | None = None): ... +def planar_layout(G, scale: float = 1, center=None, dim: int = 2, store_pos_as: str | None = None): ... +def spiral_layout( + G, + scale: float = 1, + center=None, + dim: int = 2, + resolution: float = 0.35, + equidistant: bool = False, + store_pos_as: str | None = None, +): ... +def multipartite_layout( + G, subset_key: str = "subset", align: str = "vertical", scale: float = 1, center=None, store_pos_as: str | None = None +): ... def arf_layout( G, pos=None, @@ -55,8 +80,10 @@ def arf_layout( dt: float = 0.001, max_iter: int = 1000, *, - seed: int | numpy.random.RandomState | None = None, + seed: int | RandomState | None = None, + store_pos_as: str | None = None, ): ... +@_dispatchable def forceatlas2_layout( G, pos=None, @@ -64,7 +91,7 @@ def forceatlas2_layout( max_iter=100, jitter_tolerance=1.0, scaling_ratio=2.0, - gravity=1.0, + gravity: float = 1.0, distributed_action=False, strong_gravity=False, node_mass=None, @@ -72,9 +99,12 @@ def forceatlas2_layout( weight=None, dissuade_hubs=False, linlog=False, - seed=None, - dim=2, + seed: int | RandomState | None = None, + dim: int = 2, + store_pos_as: str | None = None, ) -> dict[Incomplete, Incomplete]: ... def rescale_layout(pos, scale: float = 1): ... def rescale_layout_dict(pos, scale: float = 1): ... -def bfs_layout(G, start, *, align="vertical", scale=1, center=None) -> dict[Incomplete, Incomplete]: ... +def bfs_layout( + G, start, *, align="vertical", scale=1, center=None, store_pos_as: str | None = None +) -> dict[Incomplete, Incomplete]: ... diff --git a/stubs/networkx/networkx/drawing/nx_pylab.pyi b/stubs/networkx/networkx/drawing/nx_pylab.pyi index c2730d1b5..57b2af84a 100644 --- a/stubs/networkx/networkx/drawing/nx_pylab.pyi +++ b/stubs/networkx/networkx/drawing/nx_pylab.pyi @@ -1,13 +1,18 @@ from _typeshed import Incomplete from collections.abc import Collection, Iterable, Sequence +from networkx.classes.graph import Graph, _Node + __all__ = [ + "display", + "apply_matplotlib_colors", "draw", "draw_networkx", "draw_networkx_nodes", "draw_networkx_edges", "draw_networkx_labels", "draw_networkx_edge_labels", + "draw_bipartite", "draw_circular", "draw_kamada_kawai", "draw_random", @@ -18,10 +23,39 @@ __all__ = [ "draw_forceatlas2", ] -def draw(G, pos=None, ax=None, **kwds) -> None: ... -def draw_networkx(G, pos=None, arrows=None, with_labels: bool = True, **kwds) -> None: ... +def apply_matplotlib_colors( + G: Graph[_Node], src_attr: str, dest_attr: str, map, vmin: float | None = None, vmax: float | None = None, nodes: bool = True +) -> None: ... +def display( + G: Graph[_Node], + canvas=None, + *, + pos=..., + node_visible: str | bool = ..., + node_color: str = ..., + node_size: str | float = ..., + node_label: str | bool = ..., + node_shape: str = ..., + node_alpha: str = ..., + node_border_width: str = ..., + node_border_color: str = ..., + edge_visible: str | bool = ..., + edge_width: str | int = ..., + edge_color=..., + edge_label: str = ..., + edge_style: str = ..., + edge_alpha: str | float = ..., + arrowstyle: str = ..., + arrowsize: str | int = ..., + edge_curvature: str = ..., + edge_source_margin: str | int = ..., + edge_target_margin: str | int = ..., + hide_ticks: bool = True, +): ... +def draw(G: Graph[_Node], pos=None, ax=None, **kwds) -> None: ... +def draw_networkx(G: Graph[_Node], pos=None, arrows=None, with_labels: bool = True, **kwds) -> None: ... def draw_networkx_nodes( - G, + G: Graph[_Node], pos, nodelist: Collection[Incomplete] | None = None, node_size: Incomplete | int = 300, @@ -39,7 +73,7 @@ def draw_networkx_nodes( hide_ticks: bool = True, ): ... def draw_networkx_edges( - G, + G: Graph[_Node], pos, edgelist=None, width: float = 1.0, @@ -63,7 +97,7 @@ def draw_networkx_edges( hide_ticks: bool = True, ): ... def draw_networkx_labels( - G, + G: Graph[_Node], pos, labels=None, font_size: int = 12, @@ -79,7 +113,7 @@ def draw_networkx_labels( hide_ticks: bool = True, ): ... def draw_networkx_edge_labels( - G, + G: Graph[_Node], pos, edge_labels=None, label_pos: float = 0.5, @@ -99,14 +133,15 @@ def draw_networkx_edge_labels( connectionstyle: str = "arc3", hide_ticks: bool = True, ): ... -def draw_circular(G, **kwargs) -> None: ... -def draw_kamada_kawai(G, **kwargs) -> None: ... -def draw_random(G, **kwargs) -> None: ... -def draw_spectral(G, **kwargs) -> None: ... -def draw_spring(G, **kwargs) -> None: ... -def draw_shell(G, nlist=None, **kwargs) -> None: ... -def draw_planar(G, **kwargs) -> None: ... -def draw_forceatlas2(G, **kwargs) -> None: ... +def draw_bipartite(G: Graph[_Node], **kwargs): ... +def draw_circular(G: Graph[_Node], **kwargs) -> None: ... +def draw_kamada_kawai(G: Graph[_Node], **kwargs) -> None: ... +def draw_random(G: Graph[_Node], **kwargs) -> None: ... +def draw_spectral(G: Graph[_Node], **kwargs) -> None: ... +def draw_spring(G: Graph[_Node], **kwargs) -> None: ... +def draw_shell(G: Graph[_Node], nlist=None, **kwargs) -> None: ... +def draw_planar(G: Graph[_Node], **kwargs) -> None: ... +def draw_forceatlas2(G: Graph[_Node], **kwargs) -> None: ... def apply_alpha( colors, alpha: float | Iterable[float], elem_list, cmap=None, vmin: float | None = None, vmax: float | None = None ): ... diff --git a/stubs/networkx/networkx/generators/nonisomorphic_trees.pyi b/stubs/networkx/networkx/generators/nonisomorphic_trees.pyi index bf4ee819b..281382b32 100644 --- a/stubs/networkx/networkx/generators/nonisomorphic_trees.pyi +++ b/stubs/networkx/networkx/generators/nonisomorphic_trees.pyi @@ -6,6 +6,6 @@ from networkx.utils.backends import _dispatchable __all__ = ["nonisomorphic_trees", "number_of_nonisomorphic_trees"] @_dispatchable -def nonisomorphic_trees(order, create: str = "graph") -> Generator[Incomplete, None, None]: ... +def nonisomorphic_trees(order) -> Generator[list[Incomplete]]: ... @_dispatchable def number_of_nonisomorphic_trees(order): ... diff --git a/stubs/networkx/networkx/linalg/laplacianmatrix.pyi b/stubs/networkx/networkx/linalg/laplacianmatrix.pyi index 26eccdf28..c8f14ba08 100644 --- a/stubs/networkx/networkx/linalg/laplacianmatrix.pyi +++ b/stubs/networkx/networkx/linalg/laplacianmatrix.pyi @@ -6,7 +6,6 @@ from networkx.utils.backends import _dispatchable __all__ = [ "laplacian_matrix", "normalized_laplacian_matrix", - "total_spanning_tree_weight", "directed_laplacian_matrix", "directed_combinatorial_laplacian_matrix", ] @@ -16,8 +15,6 @@ def laplacian_matrix(G, nodelist: Collection[Incomplete] | None = None, weight: @_dispatchable def normalized_laplacian_matrix(G, nodelist: Collection[Incomplete] | None = None, weight: str = "weight"): ... @_dispatchable -def total_spanning_tree_weight(G, weight=None): ... -@_dispatchable def directed_laplacian_matrix( G, nodelist: Collection[Incomplete] | None = None, weight: str = "weight", walk_type=None, alpha: float = 0.95 ): ... diff --git a/stubs/networkx/networkx/utils/backends.pyi b/stubs/networkx/networkx/utils/backends.pyi index b0a280ab9..b28cdf418 100644 --- a/stubs/networkx/networkx/utils/backends.pyi +++ b/stubs/networkx/networkx/utils/backends.pyi @@ -1,11 +1,12 @@ from _typeshed import Incomplete from collections.abc import Callable, Mapping -from typing import Any, Generic, TypeVar, overload +from typing import Any, Final, Generic, TypeVar, overload from typing_extensions import ParamSpec, Self _P = ParamSpec("_P") _R = TypeVar("_R") __all__ = ["_dispatchable"] +FAILED_TO_CONVERT: Final[str] class _dispatchable(Generic[_P, _R]): __defaults__: Incomplete @@ -41,6 +42,7 @@ class _dispatchable(Generic[_P, _R]): preserve_all_attrs: bool = False, mutates_input: bool = False, returns_graph: bool = False, + implemented_by_nx: bool = True, ) -> Self: ... @property def __doc__(self): ... @@ -60,5 +62,4 @@ class _dispatchable(Generic[_P, _R]): # def __call__(self, *args: _P.args, backend: None = None, **kwargs: _P.kwargs) -> _R: ... # @overload # def __call__(self, *args: _P.args, backend: str, **kwargs: _P.kwargs, **backend_kwargs: Any) -> _R: ... - def __reduce__(self): ...