Skip to content

Bump networkx to 3.2.1 #11336

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
merged 10 commits into from
Jan 31, 2024
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
23 changes: 23 additions & 0 deletions stubs/networkx/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# overloaded class-decorators are not properly supported in type-checkers:
# - mypy: https://github.com/python/mypy/issues/16840
# - pyright: https://github.com/microsoft/pyright/issues/7167
networkx\.(algorithms\.)?(boundary\.)?edge_boundary
networkx\.(algorithms\.)?(bridges\.)?local_bridges
networkx\.(algorithms\.)?(clique\.)?node_clique_number
networkx\.(algorithms\.)?(shortest_paths\.)?(generic\.)?shortest_path
networkx\.(convert_matrix\.)?from_numpy_array
networkx\.(convert_matrix\.)?from_pandas_adjacency
networkx\.(convert_matrix\.)?from_pandas_edgelist
networkx\.(generators\.)?(random_clustered\.)?random_clustered_graph
networkx\.(relabel\.)?relabel_nodes

# Stubtest doesn't understand aliases of class-decorated methods (possibly https://github.com/python/mypy/issues/6700 )
networkx\.(algorithms\.)?(centrality\.)?(current_flow_closeness\.)?information_centrality
networkx\.(generators\.)?(random_graphs\.)?binomial_graph
networkx\.(generators\.)?(random_graphs\.)?erdos_renyi_graph

# Stubtest says: "runtime argument "backend" has a default value of type None, which is
# incompatible with stub argument type builtins.str. This is often caused by overloads
# failing to account for explicitly passing in the default value."
# Which is true, but would require some way of concatenating `backend` to ParamSpec.kwargs
networkx\.(utils\.backends\.)?_dispatch\.__call__
23 changes: 23 additions & 0 deletions stubs/networkx/@tests/test_cases/check_dispatch_decorator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from typing_extensions import assert_type

from networkx.utils.backends import _dispatch


@_dispatch
def some_method(int_p: int, str_p: str) -> float:
return 0.0


# Wrong param / order
some_method("", 0) # type: ignore
# backend is kw-only
some_method(0, "", None) # type: ignore
# No backend means no **backend_kwargs allowed
some_method(0, "", backend_specific_kwarg="") # type: ignore
some_method(0, "", backend=None, backend_specific_kwarg="") # type: ignore

# Correct usage
assert_type(some_method(0, ""), float)
# type system doesn't allow this yet (see comment in networkx/utils/backends.pyi)
# assert_type(some_method(0, "", backend=None), float)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would require some way of concatenating backend to _P.kwargs. Which to my understanding, isn't currently possible and is a rejected idea in https://peps.python.org/pep-0612/#concatenating-keyword-parameters

assert_type(some_method(0, "", backend="custom backend", backend_specific_kwarg=""), float)
2 changes: 1 addition & 1 deletion stubs/networkx/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.1"
version = "3.2.1"
upstream_repository = "https://github.com/networkx/networkx"
requires = ["numpy"]
partial_stub = true
Expand Down
2 changes: 2 additions & 0 deletions stubs/networkx/networkx/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ from networkx.convert_matrix import *
from networkx.drawing import *
from networkx.exception import *
from networkx.generators import *
from networkx.lazy_imports import _lazy_import as _lazy_import
from networkx.linalg import *
from networkx.readwrite import *
from networkx.relabel import *
from networkx.utils.backends import _dispatch as _dispatch
Copy link
Collaborator Author

@Avasam Avasam Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New re-exports (but they're also private, could be omitted)


from . import (
algorithms as algorithms,
Expand Down
6 changes: 6 additions & 0 deletions stubs/networkx/networkx/algorithms/approximation/clique.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from networkx.utils.backends import _dispatch

@_dispatch
def maximum_independent_set(G): ...
@_dispatch
def max_clique(G): ...
@_dispatch
def clique_removal(G): ...
@_dispatch
def large_clique_size(G): ...
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from _typeshed import Incomplete

from networkx.utils.backends import _dispatch

@_dispatch
def average_clustering(G, trials: int = 1000, seed: Incomplete | None = None): ...
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from _typeshed import Incomplete

from networkx.utils.backends import _dispatch

@_dispatch
def local_node_connectivity(G, source, target, cutoff: Incomplete | None = None): ...
@_dispatch
def node_connectivity(G, s: Incomplete | None = None, t: Incomplete | None = None): ...
@_dispatch
def all_pairs_node_connectivity(G, nbunch: Incomplete | None = None, cutoff: Incomplete | None = None): ...
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from _typeshed import Incomplete

from networkx.utils.backends import _dispatch

@_dispatch
def diameter(G, seed: Incomplete | None = None): ...
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from _typeshed import Incomplete

from networkx.utils.backends import _dispatch

@_dispatch
def min_weighted_dominating_set(G, weight: Incomplete | None = None): ...
@_dispatch
def min_edge_dominating_set(G): ...
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from networkx.utils.backends import _dispatch

@_dispatch
def k_components(G, min_density: float = 0.95): ...
3 changes: 3 additions & 0 deletions stubs/networkx/networkx/algorithms/approximation/matching.pyi
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from networkx.utils.backends import _dispatch

@_dispatch
def min_maximal_matching(G): ...
4 changes: 4 additions & 0 deletions stubs/networkx/networkx/algorithms/approximation/maxcut.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from _typeshed import Incomplete

from networkx.utils.backends import _dispatch

@_dispatch
def randomized_partitioning(G, seed: Incomplete | None = None, p: float = 0.5, weight: Incomplete | None = None): ...
@_dispatch
def one_exchange(G, initial_cut: Incomplete | None = None, seed: Incomplete | None = None, weight: Incomplete | None = None): ...
3 changes: 3 additions & 0 deletions stubs/networkx/networkx/algorithms/approximation/ramsey.pyi
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from networkx.utils.backends import _dispatch

@_dispatch
def ramsey_R2(G): ...
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from _typeshed import Incomplete

from networkx.utils.backends import _dispatch

@_dispatch
def metric_closure(G, weight: str = "weight"): ...
@_dispatch
def steiner_tree(G, terminal_nodes, weight: str = "weight", method: Incomplete | None = None): ...
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from _typeshed import Incomplete

from networkx.utils.backends import _dispatch

@_dispatch
def christofides(G, weight: str = "weight", tree: Incomplete | None = None): ...
@_dispatch
def traveling_salesman_problem(
G, weight: str = "weight", nodes: Incomplete | None = None, cycle: bool = True, method: Incomplete | None = None
): ...
@_dispatch
def asadpour_atsp(G, weight: str = "weight", seed: Incomplete | None = None, source: Incomplete | None = None): ...
@_dispatch
def greedy_tsp(G, weight: str = "weight", source: Incomplete | None = None): ...
@_dispatch
def simulated_annealing_tsp(
G,
init_cycle,
Expand All @@ -19,6 +26,7 @@ def simulated_annealing_tsp(
alpha: float = 0.01,
seed: Incomplete | None = None,
): ...
@_dispatch
def threshold_accepting_tsp(
G,
init_cycle,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from _typeshed import Incomplete

from networkx.utils.backends import _dispatch

__all__ = ["treewidth_min_degree", "treewidth_min_fill_in"]

@_dispatch
def treewidth_min_degree(G): ...
@_dispatch
def treewidth_min_fill_in(G): ...

class MinDegreeHeuristic:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from _typeshed import Incomplete

from networkx.utils.backends import _dispatch

@_dispatch
def min_weighted_vertex_cover(G, weight: Incomplete | None = None): ...
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from _typeshed import Incomplete

from networkx.utils.backends import _dispatch

@_dispatch
def average_degree_connectivity(
G, source: str = "in+out", target: str = "in+out", nodes: Incomplete | None = None, weight: Incomplete | None = None
): ...
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
from _typeshed import Incomplete

from networkx.utils.backends import _dispatch

@_dispatch
def degree_assortativity_coefficient(
G, x: str = "out", y: str = "in", weight: Incomplete | None = None, nodes: Incomplete | None = None
): ...
@_dispatch
def degree_pearson_correlation_coefficient(
G, x: str = "out", y: str = "in", weight: Incomplete | None = None, nodes: Incomplete | None = None
): ...
@_dispatch
def attribute_assortativity_coefficient(G, attribute, nodes: Incomplete | None = None): ...
@_dispatch
def numeric_assortativity_coefficient(G, attribute, nodes: Incomplete | None = None): ...
7 changes: 7 additions & 0 deletions stubs/networkx/networkx/algorithms/assortativity/mixing.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
from _typeshed import Incomplete

from networkx.utils.backends import _dispatch

@_dispatch
def attribute_mixing_dict(G, attribute, nodes: Incomplete | None = None, normalized: bool = False): ...
@_dispatch
def attribute_mixing_matrix(
G, attribute, nodes: Incomplete | None = None, mapping: Incomplete | None = None, normalized: bool = True
): ...
@_dispatch
def degree_mixing_dict(
G, x: str = "out", y: str = "in", weight: Incomplete | None = None, nodes: Incomplete | None = None, normalized: bool = False
): ...
@_dispatch
def degree_mixing_matrix(
G,
x: str = "out",
Expand All @@ -16,4 +22,5 @@ def degree_mixing_matrix(
normalized: bool = True,
mapping: Incomplete | None = None,
): ...
@_dispatch
def mixing_dict(xy, normalized: bool = False): ...
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from _typeshed import Incomplete

from networkx.utils.backends import _dispatch

@_dispatch
def average_neighbor_degree(
G, source: str = "out", target: str = "out", nodes: Incomplete | None = None, weight: Incomplete | None = None
): ...
4 changes: 4 additions & 0 deletions stubs/networkx/networkx/algorithms/assortativity/pairs.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from _typeshed import Incomplete
from collections.abc import Generator

from networkx.utils.backends import _dispatch

@_dispatch
def node_attribute_xy(G, attribute, nodes: Incomplete | None = None) -> Generator[Incomplete, None, None]: ...
@_dispatch
def node_degree_xy(
G, x: str = "out", y: str = "in", weight: Incomplete | None = None, nodes: Incomplete | None = None
) -> Generator[Incomplete, None, None]: ...
4 changes: 4 additions & 0 deletions stubs/networkx/networkx/algorithms/asteroidal.pyi
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
from networkx.utils.backends import _dispatch

@_dispatch
def find_asteroidal_triple(G): ...
@_dispatch
def is_at_free(G): ...
8 changes: 8 additions & 0 deletions stubs/networkx/networkx/algorithms/bipartite/basic.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
from _typeshed import Incomplete

from networkx.utils.backends import _dispatch

@_dispatch
def color(G): ...
@_dispatch
def is_bipartite(G): ...
@_dispatch
def is_bipartite_node_set(G, nodes): ...
@_dispatch
def sets(G, top_nodes: Incomplete | None = None): ...
@_dispatch
def density(B, nodes): ...
@_dispatch
def degrees(B, nodes, weight: Incomplete | None = None): ...
5 changes: 5 additions & 0 deletions stubs/networkx/networkx/algorithms/bipartite/centrality.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
from networkx.utils.backends import _dispatch

@_dispatch
def degree_centrality(G, nodes): ...
@_dispatch
def betweenness_centrality(G, nodes): ...
@_dispatch
def closeness_centrality(G, nodes, normalized: bool = True): ...
5 changes: 5 additions & 0 deletions stubs/networkx/networkx/algorithms/bipartite/cluster.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from _typeshed import Incomplete

from networkx.utils.backends import _dispatch

@_dispatch
def latapy_clustering(G, nodes: Incomplete | None = None, mode: str = "dot"): ...

clustering = latapy_clustering

@_dispatch
def average_clustering(G, nodes: Incomplete | None = None, mode: str = "dot"): ...
@_dispatch
def robins_alexander_clustering(G): ...
3 changes: 3 additions & 0 deletions stubs/networkx/networkx/algorithms/bipartite/covering.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from _typeshed import Incomplete

from networkx.utils.backends import _dispatch

@_dispatch
def min_edge_cover(G, matching_algorithm: Incomplete | None = None): ...
6 changes: 6 additions & 0 deletions stubs/networkx/networkx/algorithms/bipartite/edgelist.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from _typeshed import Incomplete
from collections.abc import Generator

from networkx.utils.backends import _dispatch

@_dispatch
def write_edgelist(G, path, comments: str = "#", delimiter: str = " ", data: bool = True, encoding: str = "utf-8") -> None: ...
@_dispatch
def generate_edgelist(G, delimiter: str = " ", data: bool = True) -> Generator[Incomplete, None, None]: ...
@_dispatch
def parse_edgelist(
lines,
comments: str = "#",
Expand All @@ -11,6 +16,7 @@ def parse_edgelist(
nodetype: Incomplete | None = None,
data: bool = True,
): ...
@_dispatch
def read_edgelist(
path,
comments: str = "#",
Expand Down
10 changes: 10 additions & 0 deletions stubs/networkx/networkx/algorithms/bipartite/generators.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
from _typeshed import Incomplete

from networkx.utils.backends import _dispatch

@_dispatch
def complete_bipartite_graph(n1, n2, create_using: Incomplete | None = None): ...
@_dispatch
def configuration_model(aseq, bseq, create_using: Incomplete | None = None, seed: Incomplete | None = None): ...
@_dispatch
def havel_hakimi_graph(aseq, bseq, create_using: Incomplete | None = None): ...
@_dispatch
def reverse_havel_hakimi_graph(aseq, bseq, create_using: Incomplete | None = None): ...
@_dispatch
def alternating_havel_hakimi_graph(aseq, bseq, create_using: Incomplete | None = None): ...
@_dispatch
def preferential_attachment_graph(aseq, p, create_using: Incomplete | None = None, seed: Incomplete | None = None): ...
@_dispatch
def random_graph(n, m, p, seed: Incomplete | None = None, directed: bool = False): ...
@_dispatch
def gnmk_random_graph(n, m, k, seed: Incomplete | None = None, directed: bool = False): ...
6 changes: 6 additions & 0 deletions stubs/networkx/networkx/algorithms/bipartite/matching.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from _typeshed import Incomplete

from networkx.utils.backends import _dispatch

@_dispatch
def hopcroft_karp_matching(G, top_nodes: Incomplete | None = None): ...
@_dispatch
def eppstein_matching(G, top_nodes: Incomplete | None = None): ...
@_dispatch
def to_vertex_cover(G, matching, top_nodes: Incomplete | None = None): ...

maximum_matching = hopcroft_karp_matching

@_dispatch
def minimum_weight_full_matching(G, top_nodes: Incomplete | None = None, weight: str = "weight"): ...
4 changes: 4 additions & 0 deletions stubs/networkx/networkx/algorithms/bipartite/matrix.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from _typeshed import Incomplete

from networkx.utils.backends import _dispatch

@_dispatch
def biadjacency_matrix(
G,
row_order,
Expand All @@ -8,4 +11,5 @@ def biadjacency_matrix(
weight: str = "weight",
format: str = "csr",
): ...
@_dispatch
def from_biadjacency_matrix(A, create_using: Incomplete | None = None, edge_attribute: str = "weight"): ...
Loading