summaryrefslogtreecommitdiff
path: root/networkx/algorithms
diff options
context:
space:
mode:
authorJarrod Millman <jarrod.millman@gmail.com>2023-02-14 12:52:22 -0800
committerGitHub <noreply@github.com>2023-02-14 12:52:22 -0800
commit79586c3f1a0f47e6643919887ace7e7e9335db8a (patch)
tree34bdd8f2afbaff5caa02bff01b1d8fe8c9f8b0ef /networkx/algorithms
parent44f0794f00a9fcba33a62f9d626ff882bee040ee (diff)
downloadnetworkx-79586c3f1a0f47e6643919887ace7e7e9335db8a.tar.gz
Update developer requirements (#6429)
* Update developer requirements * Run linter
Diffstat (limited to 'networkx/algorithms')
-rw-r--r--networkx/algorithms/approximation/tests/test_maxcut.py4
-rw-r--r--networkx/algorithms/approximation/tests/test_traveling_salesman.py2
-rw-r--r--networkx/algorithms/approximation/tests/test_treewidth.py2
-rw-r--r--networkx/algorithms/bipartite/matching.py1
-rw-r--r--networkx/algorithms/bipartite/tests/test_matching.py2
-rw-r--r--networkx/algorithms/bipartite/tests/test_spectral_bipartivity.py1
-rw-r--r--networkx/algorithms/centrality/dispersion.py2
-rw-r--r--networkx/algorithms/centrality/tests/test_degree_centrality.py1
-rw-r--r--networkx/algorithms/centrality/tests/test_eigenvector_centrality.py8
-rw-r--r--networkx/algorithms/centrality/tests/test_katz_centrality.py8
-rw-r--r--networkx/algorithms/centrality/tests/test_load_centrality.py1
-rw-r--r--networkx/algorithms/coloring/equitable_coloring.py4
-rw-r--r--networkx/algorithms/coloring/greedy_coloring.py4
-rw-r--r--networkx/algorithms/coloring/tests/test_coloring.py6
-rw-r--r--networkx/algorithms/community/label_propagation.py1
-rw-r--r--networkx/algorithms/community/lukes.py2
-rw-r--r--networkx/algorithms/community/tests/test_lukes.py3
-rw-r--r--networkx/algorithms/community/tests/test_modularity_max.py2
-rw-r--r--networkx/algorithms/connectivity/edge_augmentation.py6
-rw-r--r--networkx/algorithms/connectivity/utils.py4
-rw-r--r--networkx/algorithms/cycles.py1
-rw-r--r--networkx/algorithms/dag.py2
-rw-r--r--networkx/algorithms/distance_measures.py4
-rw-r--r--networkx/algorithms/flow/networksimplex.py1
-rw-r--r--networkx/algorithms/isomorphism/isomorphvf2.py1
-rw-r--r--networkx/algorithms/isomorphism/tests/test_tree_isomorphism.py11
-rw-r--r--networkx/algorithms/isomorphism/tests/test_vf2userfunc.py1
-rw-r--r--networkx/algorithms/isomorphism/tree_isomorphism.py4
-rw-r--r--networkx/algorithms/isomorphism/vf2userfunc.py1
-rw-r--r--networkx/algorithms/link_analysis/tests/test_hits.py1
-rw-r--r--networkx/algorithms/link_analysis/tests/test_pagerank.py2
-rw-r--r--networkx/algorithms/matching.py9
-rw-r--r--networkx/algorithms/minors/contraction.py2
-rw-r--r--networkx/algorithms/operators/product.py1
-rw-r--r--networkx/algorithms/operators/tests/test_product.py16
-rw-r--r--networkx/algorithms/regular.py4
-rw-r--r--networkx/algorithms/simple_paths.py2
-rw-r--r--networkx/algorithms/tests/test_asteroidal.py1
-rw-r--r--networkx/algorithms/tests/test_chordal.py2
-rw-r--r--networkx/algorithms/tests/test_communicability.py1
-rw-r--r--networkx/algorithms/tests/test_lowest_common_ancestors.py2
-rw-r--r--networkx/algorithms/tests/test_reciprocity.py1
-rw-r--r--networkx/algorithms/threshold.py2
-rw-r--r--networkx/algorithms/tree/branchings.py4
-rw-r--r--networkx/algorithms/tree/tests/test_recognition.py2
-rw-r--r--networkx/algorithms/triads.py4
46 files changed, 57 insertions, 89 deletions
diff --git a/networkx/algorithms/approximation/tests/test_maxcut.py b/networkx/algorithms/approximation/tests/test_maxcut.py
index ec75b59f..39291fbf 100644
--- a/networkx/algorithms/approximation/tests/test_maxcut.py
+++ b/networkx/algorithms/approximation/tests/test_maxcut.py
@@ -36,7 +36,7 @@ def test_random_partitioning_all_to_one():
def test_one_exchange_basic():
G = nx.complete_graph(5)
random.seed(5)
- for (u, v, w) in G.edges(data=True):
+ for u, v, w in G.edges(data=True):
w["weight"] = random.randrange(-100, 100, 1) / 10
initial_cut = set(random.sample(sorted(G.nodes()), k=5))
@@ -68,7 +68,7 @@ def test_one_exchange_optimal():
def test_negative_weights():
G = nx.complete_graph(5)
random.seed(5)
- for (u, v, w) in G.edges(data=True):
+ for u, v, w in G.edges(data=True):
w["weight"] = -1 * random.random()
initial_cut = set(random.sample(sorted(G.nodes()), k=5))
diff --git a/networkx/algorithms/approximation/tests/test_traveling_salesman.py b/networkx/algorithms/approximation/tests/test_traveling_salesman.py
index 6f9b3b0c..ccb553e1 100644
--- a/networkx/algorithms/approximation/tests/test_traveling_salesman.py
+++ b/networkx/algorithms/approximation/tests/test_traveling_salesman.py
@@ -12,7 +12,7 @@ pairwise = nx.utils.pairwise
def test_christofides_hamiltonian():
random.seed(42)
G = nx.complete_graph(20)
- for (u, v) in G.edges():
+ for u, v in G.edges():
G[u][v]["weight"] = random.randint(0, 10)
H = nx.Graph()
diff --git a/networkx/algorithms/approximation/tests/test_treewidth.py b/networkx/algorithms/approximation/tests/test_treewidth.py
index fdccfd14..461b0f2e 100644
--- a/networkx/algorithms/approximation/tests/test_treewidth.py
+++ b/networkx/algorithms/approximation/tests/test_treewidth.py
@@ -22,7 +22,7 @@ def is_tree_decomp(graph, decomp):
assert appear_once
# Check if each connected pair of nodes are at least once together in a bag
- for (x, y) in graph.edges():
+ for x, y in graph.edges():
appear_together = False
for bag in decomp.nodes():
if x in bag and y in bag:
diff --git a/networkx/algorithms/bipartite/matching.py b/networkx/algorithms/bipartite/matching.py
index 5c042b1a..d00595fa 100644
--- a/networkx/algorithms/bipartite/matching.py
+++ b/networkx/algorithms/bipartite/matching.py
@@ -115,6 +115,7 @@ def hopcroft_karp_matching(G, top_nodes=None):
2.4 (1973), pp. 225--231. <https://doi.org/10.1137/0202019>.
"""
+
# First we define some auxiliary search functions.
#
# If you are a human reading these auxiliary search functions, the "global"
diff --git a/networkx/algorithms/bipartite/tests/test_matching.py b/networkx/algorithms/bipartite/tests/test_matching.py
index abef330e..7ed7cdcb 100644
--- a/networkx/algorithms/bipartite/tests/test_matching.py
+++ b/networkx/algorithms/bipartite/tests/test_matching.py
@@ -104,7 +104,7 @@ class TestMatching:
# the number of vertices in a minimum vertex cover.
assert len(vertices) == 5
# Assert that the set is truly a vertex cover.
- for (u, v) in self.graph.edges():
+ for u, v in self.graph.edges():
assert u in vertices or v in vertices
# TODO Assert that the vertices are the correct ones.
diff --git a/networkx/algorithms/bipartite/tests/test_spectral_bipartivity.py b/networkx/algorithms/bipartite/tests/test_spectral_bipartivity.py
index 0cdc2d60..b9406497 100644
--- a/networkx/algorithms/bipartite/tests/test_spectral_bipartivity.py
+++ b/networkx/algorithms/bipartite/tests/test_spectral_bipartivity.py
@@ -66,7 +66,6 @@ class TestSpectralBipartivity:
assert sb(G) == pytest.approx(0.597, abs=1e-3)
def test_single_nodes(self):
-
# single nodes
G = nx.complete_bipartite_graph(2, 3)
G.add_edge(2, 4)
diff --git a/networkx/algorithms/centrality/dispersion.py b/networkx/algorithms/centrality/dispersion.py
index a61a7b4f..4c38ad08 100644
--- a/networkx/algorithms/centrality/dispersion.py
+++ b/networkx/algorithms/centrality/dispersion.py
@@ -59,7 +59,7 @@ def dispersion(G, u=None, v=None, normalized=True, alpha=1.0, b=0.0, c=0.0):
# all possible ties of connections that u and b share
possib = combinations(ST, 2)
total = 0
- for (s, t) in possib:
+ for s, t in possib:
# neighbors of s that are in G_u, not including u and v
nbrs_s = u_nbrs.intersection(G_u[s]) - set_uv
# s and t are not directly connected
diff --git a/networkx/algorithms/centrality/tests/test_degree_centrality.py b/networkx/algorithms/centrality/tests/test_degree_centrality.py
index 591df6a8..f3f6c39d 100644
--- a/networkx/algorithms/centrality/tests/test_degree_centrality.py
+++ b/networkx/algorithms/centrality/tests/test_degree_centrality.py
@@ -9,7 +9,6 @@ import networkx as nx
class TestDegreeCentrality:
def setup_method(self):
-
self.K = nx.krackhardt_kite_graph()
self.P3 = nx.path_graph(3)
self.K5 = nx.complete_graph(5)
diff --git a/networkx/algorithms/centrality/tests/test_eigenvector_centrality.py b/networkx/algorithms/centrality/tests/test_eigenvector_centrality.py
index 407205b6..b8620056 100644
--- a/networkx/algorithms/centrality/tests/test_eigenvector_centrality.py
+++ b/networkx/algorithms/centrality/tests/test_eigenvector_centrality.py
@@ -128,25 +128,25 @@ class TestEigenvectorCentralityDirected:
def test_eigenvector_centrality_weighted(self):
G = self.G
p = nx.eigenvector_centrality(G)
- for (a, b) in zip(list(p.values()), self.G.evc):
+ for a, b in zip(list(p.values()), self.G.evc):
assert a == pytest.approx(b, abs=1e-4)
def test_eigenvector_centrality_weighted_numpy(self):
G = self.G
p = nx.eigenvector_centrality_numpy(G)
- for (a, b) in zip(list(p.values()), self.G.evc):
+ for a, b in zip(list(p.values()), self.G.evc):
assert a == pytest.approx(b, abs=1e-7)
def test_eigenvector_centrality_unweighted(self):
G = self.H
p = nx.eigenvector_centrality(G)
- for (a, b) in zip(list(p.values()), self.G.evc):
+ for a, b in zip(list(p.values()), self.G.evc):
assert a == pytest.approx(b, abs=1e-4)
def test_eigenvector_centrality_unweighted_numpy(self):
G = self.H
p = nx.eigenvector_centrality_numpy(G)
- for (a, b) in zip(list(p.values()), self.G.evc):
+ for a, b in zip(list(p.values()), self.G.evc):
assert a == pytest.approx(b, abs=1e-7)
diff --git a/networkx/algorithms/centrality/tests/test_katz_centrality.py b/networkx/algorithms/centrality/tests/test_katz_centrality.py
index 25114533..a070e5a0 100644
--- a/networkx/algorithms/centrality/tests/test_katz_centrality.py
+++ b/networkx/algorithms/centrality/tests/test_katz_centrality.py
@@ -295,14 +295,14 @@ class TestKatzCentralityDirected:
G = self.G
alpha = self.G.alpha
p = nx.katz_centrality(G, alpha, weight="weight")
- for (a, b) in zip(list(p.values()), self.G.evc):
+ for a, b in zip(list(p.values()), self.G.evc):
assert a == pytest.approx(b, abs=1e-7)
def test_katz_centrality_unweighted(self):
H = self.H
alpha = self.H.alpha
p = nx.katz_centrality(H, alpha, weight="weight")
- for (a, b) in zip(list(p.values()), self.H.evc):
+ for a, b in zip(list(p.values()), self.H.evc):
assert a == pytest.approx(b, abs=1e-7)
@@ -318,14 +318,14 @@ class TestKatzCentralityDirectedNumpy(TestKatzCentralityDirected):
G = self.G
alpha = self.G.alpha
p = nx.katz_centrality_numpy(G, alpha, weight="weight")
- for (a, b) in zip(list(p.values()), self.G.evc):
+ for a, b in zip(list(p.values()), self.G.evc):
assert a == pytest.approx(b, abs=1e-7)
def test_katz_centrality_unweighted(self):
H = self.H
alpha = self.H.alpha
p = nx.katz_centrality_numpy(H, alpha, weight="weight")
- for (a, b) in zip(list(p.values()), self.H.evc):
+ for a, b in zip(list(p.values()), self.H.evc):
assert a == pytest.approx(b, abs=1e-7)
diff --git a/networkx/algorithms/centrality/tests/test_load_centrality.py b/networkx/algorithms/centrality/tests/test_load_centrality.py
index d994394f..bb7da657 100644
--- a/networkx/algorithms/centrality/tests/test_load_centrality.py
+++ b/networkx/algorithms/centrality/tests/test_load_centrality.py
@@ -6,7 +6,6 @@ import networkx as nx
class TestLoadCentrality:
@classmethod
def setup_class(cls):
-
G = nx.Graph()
G.add_edge(0, 1, weight=3)
G.add_edge(0, 2, weight=2)
diff --git a/networkx/algorithms/coloring/equitable_coloring.py b/networkx/algorithms/coloring/equitable_coloring.py
index 3072a0a9..a45d9ce9 100644
--- a/networkx/algorithms/coloring/equitable_coloring.py
+++ b/networkx/algorithms/coloring/equitable_coloring.py
@@ -12,7 +12,7 @@ __all__ = ["equitable_color"]
def is_coloring(G, coloring):
"""Determine if the coloring is a valid coloring for the graph G."""
# Verify that the coloring is valid.
- for (s, d) in G.edges:
+ for s, d in G.edges:
if coloring[s] == coloring[d]:
return False
return True
@@ -201,7 +201,6 @@ def procedure_P(V_minus, V_plus, N, H, F, C, L, excluded_colors=None):
made_equitable = False
for W_1 in R_cal[::-1]:
-
for v in C[W_1]:
X = None
@@ -482,7 +481,6 @@ def equitable_color(G, num_colors):
for u in sorted(G.nodes):
for v in sorted(G.neighbors(u)):
-
# Do not double count edges if (v, u) has already been seen.
if (v, u) in edges_seen:
continue
diff --git a/networkx/algorithms/coloring/greedy_coloring.py b/networkx/algorithms/coloring/greedy_coloring.py
index 78e0d157..f258d1f9 100644
--- a/networkx/algorithms/coloring/greedy_coloring.py
+++ b/networkx/algorithms/coloring/greedy_coloring.py
@@ -196,7 +196,7 @@ def strategy_connected_sequential(G, colors, traversal="bfs"):
# Yield the source node, then all the nodes in the specified
# traversal order.
yield source
- for (_, end) in traverse(G.subgraph(component), source):
+ for _, end in traverse(G.subgraph(component), source):
yield end
@@ -470,7 +470,7 @@ def _greedy_coloring_with_interchange(G, nodes):
graph = {node: _Node(node, n) for node in G}
- for (node1, node2) in G.edges():
+ for node1, node2 in G.edges():
adj_entry1 = _AdjEntry(node2)
adj_entry2 = _AdjEntry(node1)
adj_entry1.mate = adj_entry2
diff --git a/networkx/algorithms/coloring/tests/test_coloring.py b/networkx/algorithms/coloring/tests/test_coloring.py
index 6ab95bee..772758dd 100644
--- a/networkx/algorithms/coloring/tests/test_coloring.py
+++ b/networkx/algorithms/coloring/tests/test_coloring.py
@@ -438,7 +438,6 @@ class TestColoring:
full_color_assignment=None,
nodes_to_add_between_calls=1,
):
-
color_assignments = []
aux_colored_nodes = colored_nodes.copy()
@@ -474,7 +473,6 @@ class TestColoring:
return color_assignments, aux_colored_nodes
for G, _, _ in SPECIAL_TEST_CASES["saturation_largest_first"]:
-
G = G()
# Check that function still works when nodes are colored between iterations
@@ -530,7 +528,7 @@ def dict_to_sets(colors):
k = max(colors.values()) + 1
sets = [set() for _ in range(k)]
- for (node, color) in colors.items():
+ for node, color in colors.items():
sets[color].add(node)
return sets
@@ -856,7 +854,7 @@ def make_params_from_graph(G, F):
"""Returns {N, L, H, C} from the given graph."""
num_nodes = len(G)
L = {u: [] for u in range(num_nodes)}
- for (u, v) in G.edges:
+ for u, v in G.edges:
L[u].append(v)
L[v].append(u)
diff --git a/networkx/algorithms/community/label_propagation.py b/networkx/algorithms/community/label_propagation.py
index 09c07c27..307afc8c 100644
--- a/networkx/algorithms/community/label_propagation.py
+++ b/networkx/algorithms/community/label_propagation.py
@@ -69,7 +69,6 @@ def asyn_lpa_communities(G, weight=None, seed=None):
seed.shuffle(nodes)
for node in nodes:
-
if not G[node]:
continue
diff --git a/networkx/algorithms/community/lukes.py b/networkx/algorithms/community/lukes.py
index b34077a2..28cf749a 100644
--- a/networkx/algorithms/community/lukes.py
+++ b/networkx/algorithms/community/lukes.py
@@ -26,7 +26,6 @@ def _split_n_from(n, min_size_of_first_part):
def lukes_partitioning(G, max_size, node_weight=None, edge_weight=None):
-
"""Optimal partitioning of a weighted tree using the Lukes algorithm.
This algorithm partitions a connected, acyclic graph featuring integer
@@ -147,7 +146,6 @@ def lukes_partitioning(G, max_size, node_weight=None, edge_weight=None):
return ccx[0]
def _concatenate_or_merge(partition_1, partition_2, x, i, ref_weigth):
-
ccx = _pivot(partition_1, x)
cci = _pivot(partition_2, i)
merged_xi = ccx.union(cci)
diff --git a/networkx/algorithms/community/tests/test_lukes.py b/networkx/algorithms/community/tests/test_lukes.py
index 80e2de34..e7a47106 100644
--- a/networkx/algorithms/community/tests/test_lukes.py
+++ b/networkx/algorithms/community/tests/test_lukes.py
@@ -11,7 +11,6 @@ NWL = "n_weight"
# first test from the Lukes original paper
def paper_1_case(float_edge_wt=False, explicit_node_wt=True, directed=False):
-
# problem-specific constants
limit = 3
@@ -50,7 +49,6 @@ def paper_1_case(float_edge_wt=False, explicit_node_wt=True, directed=False):
# second test from the Lukes original paper
def paper_2_case(explicit_edge_wt=True, directed=False):
-
# problem specific constants
byte_block_size = 32
@@ -132,7 +130,6 @@ def test_mandatory_tree():
def test_mandatory_integrality():
-
byte_block_size = 32
ex_1_broken = nx.DiGraph()
diff --git a/networkx/algorithms/community/tests/test_modularity_max.py b/networkx/algorithms/community/tests/test_modularity_max.py
index acdb19d6..c1f82d0d 100644
--- a/networkx/algorithms/community/tests/test_modularity_max.py
+++ b/networkx/algorithms/community/tests/test_modularity_max.py
@@ -96,7 +96,7 @@ def test_greedy_modularity_communities_directed():
)
def test_modularity_communities_weighted(func):
G = nx.balanced_tree(2, 3)
- for (a, b) in G.edges:
+ for a, b in G.edges:
if ((a == 1) or (a == 2)) and (b != 0):
G[a][b]["weight"] = 10.0
else:
diff --git a/networkx/algorithms/connectivity/edge_augmentation.py b/networkx/algorithms/connectivity/edge_augmentation.py
index b9e5f5d2..3195df89 100644
--- a/networkx/algorithms/connectivity/edge_augmentation.py
+++ b/networkx/algorithms/connectivity/edge_augmentation.py
@@ -374,7 +374,7 @@ def partial_k_edge_augmentation(G, k, avail, weight=None):
# Generate all edges between CCs that could not be k-edge-connected
for cc1, cc2 in it.combinations(k_edge_subgraphs, 2):
- for (u, v) in _edges_between_disjoint(H, cc1, cc2):
+ for u, v in _edges_between_disjoint(H, cc1, cc2):
d = H.get_edge_data(u, v)
edge = d.get("generator", None)
if edge is not None:
@@ -1223,7 +1223,7 @@ def greedy_k_edge_augmentation(G, k, avail=None, weight=None, seed=None):
# Incrementally add edges in until we are k-connected
H = G.copy()
- for (u, v) in avail_uv:
+ for u, v in avail_uv:
done = False
if not is_locally_k_edge_connected(H, u, v, k=k):
# Only add edges in parts that are not yet locally k-edge-connected
@@ -1241,7 +1241,7 @@ def greedy_k_edge_augmentation(G, k, avail=None, weight=None, seed=None):
# Randomized attempt to reduce the size of the solution
_compat_shuffle(seed, aug_edges)
- for (u, v) in list(aug_edges):
+ for u, v in list(aug_edges):
# Don't remove if we know it would break connectivity
if H.degree(u) <= k or H.degree(v) <= k:
continue
diff --git a/networkx/algorithms/connectivity/utils.py b/networkx/algorithms/connectivity/utils.py
index 06d2fdc3..96ebb2ab 100644
--- a/networkx/algorithms/connectivity/utils.py
+++ b/networkx/algorithms/connectivity/utils.py
@@ -47,7 +47,7 @@ def build_auxiliary_node_connectivity(G):
H.add_edge(f"{i}A", f"{i}B", capacity=1)
edges = []
- for (source, target) in G.edges():
+ for source, target in G.edges():
edges.append((f"{mapping[source]}B", f"{mapping[target]}A"))
if not directed:
edges.append((f"{mapping[target]}B", f"{mapping[source]}A"))
@@ -80,6 +80,6 @@ def build_auxiliary_edge_connectivity(G):
else:
H = nx.DiGraph()
H.add_nodes_from(G.nodes())
- for (source, target) in G.edges():
+ for source, target in G.edges():
H.add_edges_from([(source, target), (target, source)], capacity=1)
return H
diff --git a/networkx/algorithms/cycles.py b/networkx/algorithms/cycles.py
index 1dd91bd0..2ab610cd 100644
--- a/networkx/algorithms/cycles.py
+++ b/networkx/algorithms/cycles.py
@@ -269,6 +269,7 @@ def recursive_simple_cycles(G):
--------
simple_cycles, cycle_basis
"""
+
# Jon Olav Vik, 2010-08-09
def _unblock(thisnode):
"""Recursively unblock and remove nodes from B[thisnode]."""
diff --git a/networkx/algorithms/dag.py b/networkx/algorithms/dag.py
index 20735160..c897b75d 100644
--- a/networkx/algorithms/dag.py
+++ b/networkx/algorithms/dag.py
@@ -1083,7 +1083,7 @@ def dag_longest_path_length(G, weight="weight", default_weight=1):
i = max(G[u][v], key=lambda x: G[u][v][x].get(weight, default_weight))
path_length += G[u][v][i].get(weight, default_weight)
else:
- for (u, v) in pairwise(path):
+ for u, v in pairwise(path):
path_length += G[u][v].get(weight, default_weight)
return path_length
diff --git a/networkx/algorithms/distance_measures.py b/networkx/algorithms/distance_measures.py
index 9ea6c07c..02af4267 100644
--- a/networkx/algorithms/distance_measures.py
+++ b/networkx/algorithms/distance_measures.py
@@ -721,10 +721,10 @@ def resistance_distance(G, nodeA, nodeB, weight=None, invert_weight=True):
if invert_weight and weight is not None:
if G.is_multigraph():
- for (u, v, k, d) in G.edges(keys=True, data=True):
+ for u, v, k, d in G.edges(keys=True, data=True):
d[weight] = 1 / d[weight]
else:
- for (u, v, d) in G.edges(data=True):
+ for u, v, d in G.edges(data=True):
d[weight] = 1 / d[weight]
# Replace with collapsing topology or approximated zero?
diff --git a/networkx/algorithms/flow/networksimplex.py b/networkx/algorithms/flow/networksimplex.py
index 3e2eaf5b..85902ccf 100644
--- a/networkx/algorithms/flow/networksimplex.py
+++ b/networkx/algorithms/flow/networksimplex.py
@@ -15,7 +15,6 @@ class _DataEssentialsAndFunctions:
def __init__(
self, G, multigraph, demand="demand", capacity="capacity", weight="weight"
):
-
# Number all nodes and edges and hereafter reference them using ONLY their numbers
self.node_list = list(G) # nodes
self.node_indices = {u: i for i, u in enumerate(self.node_list)} # node indices
diff --git a/networkx/algorithms/isomorphism/isomorphvf2.py b/networkx/algorithms/isomorphism/isomorphvf2.py
index 878924e7..56c0624c 100644
--- a/networkx/algorithms/isomorphism/isomorphvf2.py
+++ b/networkx/algorithms/isomorphism/isomorphvf2.py
@@ -725,7 +725,6 @@ class DiGraphMatcher(GraphMatcher):
return False
if self.test != "mono":
-
# Look ahead 1
# R_termin
diff --git a/networkx/algorithms/isomorphism/tests/test_tree_isomorphism.py b/networkx/algorithms/isomorphism/tests/test_tree_isomorphism.py
index 1628bea7..58ca7b78 100644
--- a/networkx/algorithms/isomorphism/tests/test_tree_isomorphism.py
+++ b/networkx/algorithms/isomorphism/tests/test_tree_isomorphism.py
@@ -15,7 +15,6 @@ from networkx.classes.function import is_directed
# and confirm it is identical to t1
# randomize the order of the edges when constructing
def check_isomorphism(t1, t2, isomorphism):
-
# get the name of t1, given the name in t2
mapping = {v2: v1 for (v1, v2) in isomorphism}
@@ -25,7 +24,7 @@ def check_isomorphism(t1, t2, isomorphism):
assert d1 == d2
edges_1 = []
- for (u, v) in t1.edges():
+ for u, v in t1.edges():
if d1:
edges_1.append((u, v))
else:
@@ -37,7 +36,7 @@ def check_isomorphism(t1, t2, isomorphism):
edges_1.append((v, u))
edges_2 = []
- for (u, v) in t2.edges():
+ for u, v in t2.edges():
# translate to names for t1
u = mapping[u]
v = mapping[v]
@@ -53,7 +52,6 @@ def check_isomorphism(t1, t2, isomorphism):
def test_hardcoded():
-
print("hardcoded test")
# define a test problem
@@ -170,7 +168,6 @@ def random_swap(t):
# that is isomorphic to t1, with a known isomorphism
# and test that our algorithm found the right one
def positive_single_tree(t1):
-
assert nx.is_tree(t1)
nodes1 = [n for n in t1.nodes()]
@@ -210,7 +207,6 @@ def positive_single_tree(t1):
# larger values run slow down significantly
# as the number of trees grows rapidly
def test_positive(maxk=14):
-
print("positive test")
for k in range(2, maxk + 1):
@@ -225,7 +221,6 @@ def test_positive(maxk=14):
# test the trivial case of a single node in each tree
# note that nonisomorphic_trees doesn't work for k = 1
def test_trivial():
-
print("trivial test")
# back to an undirected graph
@@ -247,7 +242,6 @@ def test_trivial():
# test another trivial case where the two graphs have
# different numbers of nodes
def test_trivial_2():
-
print("trivial test 2")
edges_1 = [("a", "b"), ("a", "c")]
@@ -275,7 +269,6 @@ def test_trivial_2():
# larger values run slow down significantly
# as the number of trees grows rapidly
def test_negative(maxk=11):
-
print("negative test")
for k in range(4, maxk + 1):
diff --git a/networkx/algorithms/isomorphism/tests/test_vf2userfunc.py b/networkx/algorithms/isomorphism/tests/test_vf2userfunc.py
index 5a22d415..66a434e0 100644
--- a/networkx/algorithms/isomorphism/tests/test_vf2userfunc.py
+++ b/networkx/algorithms/isomorphism/tests/test_vf2userfunc.py
@@ -14,7 +14,6 @@ def test_simple():
w = "weight"
edges = [(0, 0, 1), (0, 0, 1.5), (0, 1, 2), (1, 0, 3)]
for g1 in [nx.Graph(), nx.DiGraph(), nx.MultiGraph(), nx.MultiDiGraph()]:
-
g1.add_weighted_edges_from(edges)
g2 = g1.subgraph(g1.nodes())
if g1.is_multigraph():
diff --git a/networkx/algorithms/isomorphism/tree_isomorphism.py b/networkx/algorithms/isomorphism/tree_isomorphism.py
index cfb0a935..176e8bd3 100644
--- a/networkx/algorithms/isomorphism/tree_isomorphism.py
+++ b/networkx/algorithms/isomorphism/tree_isomorphism.py
@@ -74,7 +74,7 @@ def root_trees(t1, root1, t2, root2):
def assign_levels(G, root):
level = {}
level[root] = 0
- for (v1, v2) in nx.bfs_edges(G, root):
+ for v1, v2 in nx.bfs_edges(G, root):
level[v2] = level[v1] + 1
return level
@@ -83,7 +83,7 @@ def assign_levels(G, root):
# now group the nodes at each level
def group_by_levels(levels):
L = {}
- for (n, lev) in levels.items():
+ for n, lev in levels.items():
if lev not in L:
L[lev] = []
L[lev].append(n)
diff --git a/networkx/algorithms/isomorphism/vf2userfunc.py b/networkx/algorithms/isomorphism/vf2userfunc.py
index 349129ee..ee2cdd75 100644
--- a/networkx/algorithms/isomorphism/vf2userfunc.py
+++ b/networkx/algorithms/isomorphism/vf2userfunc.py
@@ -46,7 +46,6 @@ def _semantic_feasibility(self, G1_node, G2_node):
# Make sure the edges match
if self.edge_match is not None:
-
# Cached lookups
G1nbrs = self.G1_adj[G1_node]
G2nbrs = self.G2_adj[G2_node]
diff --git a/networkx/algorithms/link_analysis/tests/test_hits.py b/networkx/algorithms/link_analysis/tests/test_hits.py
index 1b242a1f..cb9d647d 100644
--- a/networkx/algorithms/link_analysis/tests/test_hits.py
+++ b/networkx/algorithms/link_analysis/tests/test_hits.py
@@ -20,7 +20,6 @@ from networkx.algorithms.link_analysis.hits_alg import (
class TestHITS:
@classmethod
def setup_class(cls):
-
G = nx.DiGraph()
edges = [(1, 3), (1, 5), (2, 1), (3, 5), (5, 4), (5, 3), (6, 5)]
diff --git a/networkx/algorithms/link_analysis/tests/test_pagerank.py b/networkx/algorithms/link_analysis/tests/test_pagerank.py
index 930b4e44..fa73493b 100644
--- a/networkx/algorithms/link_analysis/tests/test_pagerank.py
+++ b/networkx/algorithms/link_analysis/tests/test_pagerank.py
@@ -87,7 +87,7 @@ class TestPageRank:
M = nx.google_matrix(G, alpha=0.9, nodelist=sorted(G))
_, ev = np.linalg.eig(M.T)
p = ev[:, 0] / ev[:, 0].sum()
- for (a, b) in zip(p, self.G.pagerank.values()):
+ for a, b in zip(p, self.G.pagerank.values()):
assert a == pytest.approx(b, abs=1e-7)
@pytest.mark.parametrize("alg", (nx.pagerank, _pagerank_python, _pagerank_numpy))
diff --git a/networkx/algorithms/matching.py b/networkx/algorithms/matching.py
index da6416df..dd8546d6 100644
--- a/networkx/algorithms/matching.py
+++ b/networkx/algorithms/matching.py
@@ -806,7 +806,7 @@ def max_weight_matching(G, maxcardinality=False, weight="weight"):
# Swap matched/unmatched edges over an alternating path between two
# single vertices. The augmenting path runs through S-vertices v and w.
def augmentMatching(v, w):
- for (s, j) in ((v, w), (w, v)):
+ for s, j in ((v, w), (w, v)):
# Match vertex s to vertex j. Then trace back from s
# until we find a single vertex, swapping matched and unmatched
# edges as we go.
@@ -863,7 +863,7 @@ def max_weight_matching(G, maxcardinality=False, weight="weight"):
jblossoms.append(blossomparent[jblossoms[-1]])
iblossoms.reverse()
jblossoms.reverse()
- for (bi, bj) in zip(iblossoms, jblossoms):
+ for bi, bj in zip(iblossoms, jblossoms):
if bi != bj:
break
s += 2 * blossomdual[bi]
@@ -878,13 +878,12 @@ def max_weight_matching(G, maxcardinality=False, weight="weight"):
for b in blossomdual:
if blossomdual[b] > 0:
assert len(b.edges) % 2 == 1
- for (i, j) in b.edges[1::2]:
+ for i, j in b.edges[1::2]:
assert mate[i] == j and mate[j] == i
# Ok.
# Main loop: continue until no further improvement is possible.
while 1:
-
# Each iteration of this loop is a "stage".
# A stage finds an augmenting path and uses that to improve
# the matching.
@@ -913,7 +912,6 @@ def max_weight_matching(G, maxcardinality=False, weight="weight"):
# Loop until we succeed in augmenting the matching.
augmented = 0
while 1:
-
# Each iteration of this loop is a "substage".
# A substage tries to find an augmenting path;
# if found, the path is used to improve the matching and
@@ -924,7 +922,6 @@ def max_weight_matching(G, maxcardinality=False, weight="weight"):
# Continue labeling until all vertices which are reachable
# through an alternating path have got a label.
while queue and not augmented:
-
# Take an S vertex from the queue.
v = queue.pop()
assert label[inblossom[v]] == 1
diff --git a/networkx/algorithms/minors/contraction.py b/networkx/algorithms/minors/contraction.py
index c1e9adfe..89cf4907 100644
--- a/networkx/algorithms/minors/contraction.py
+++ b/networkx/algorithms/minors/contraction.py
@@ -505,7 +505,7 @@ def contracted_nodes(G, u, v, self_loops=True, copy=True):
v_data = H.nodes[v]
H.remove_node(v)
- for (prev_w, prev_x, d) in edges_to_remap:
+ for prev_w, prev_x, d in edges_to_remap:
w = prev_w if prev_w != v else u
x = prev_x if prev_x != v else u
diff --git a/networkx/algorithms/operators/product.py b/networkx/algorithms/operators/product.py
index a43dab19..54cdeb8c 100644
--- a/networkx/algorithms/operators/product.py
+++ b/networkx/algorithms/operators/product.py
@@ -512,7 +512,6 @@ def corona_product(G, H):
GH.add_edges_from(G.edges)
for G_node in G:
-
# copy nodes of H in GH, call it H_i
GH.add_nodes_from((G_node, v) for v in H)
diff --git a/networkx/algorithms/operators/tests/test_product.py b/networkx/algorithms/operators/tests/test_product.py
index 75bc0489..50bc7b7e 100644
--- a/networkx/algorithms/operators/tests/test_product.py
+++ b/networkx/algorithms/operators/tests/test_product.py
@@ -90,8 +90,8 @@ def test_tensor_product_random():
H = nx.erdos_renyi_graph(10, 2 / 10.0)
GH = nx.tensor_product(G, H)
- for (u_G, u_H) in GH.nodes():
- for (v_G, v_H) in GH.nodes():
+ for u_G, u_H in GH.nodes():
+ for v_G, v_H in GH.nodes():
if H.has_edge(u_H, v_H) and G.has_edge(u_G, v_G):
assert GH.has_edge((u_G, u_H), (v_G, v_H))
else:
@@ -196,8 +196,8 @@ def test_cartesian_product_random():
H = nx.erdos_renyi_graph(10, 2 / 10.0)
GH = nx.cartesian_product(G, H)
- for (u_G, u_H) in GH.nodes():
- for (v_G, v_H) in GH.nodes():
+ for u_G, u_H in GH.nodes():
+ for v_G, v_H in GH.nodes():
if (u_G == v_G and H.has_edge(u_H, v_H)) or (
u_H == v_H and G.has_edge(u_G, v_G)
):
@@ -274,8 +274,8 @@ def test_lexicographic_product_random():
H = nx.erdos_renyi_graph(10, 2 / 10.0)
GH = nx.lexicographic_product(G, H)
- for (u_G, u_H) in GH.nodes():
- for (v_G, v_H) in GH.nodes():
+ for u_G, u_H in GH.nodes():
+ for v_G, v_H in GH.nodes():
if G.has_edge(u_G, v_G) or (u_G == v_G and H.has_edge(u_H, v_H)):
assert GH.has_edge((u_G, u_H), (v_G, v_H))
else:
@@ -350,8 +350,8 @@ def test_strong_product_random():
H = nx.erdos_renyi_graph(10, 2 / 10.0)
GH = nx.strong_product(G, H)
- for (u_G, u_H) in GH.nodes():
- for (v_G, v_H) in GH.nodes():
+ for u_G, u_H in GH.nodes():
+ for v_G, v_H in GH.nodes():
if (
(u_G == v_G and H.has_edge(u_H, v_H))
or (u_H == v_H and G.has_edge(u_G, v_G))
diff --git a/networkx/algorithms/regular.py b/networkx/algorithms/regular.py
index 94ec71d7..da6e4b56 100644
--- a/networkx/algorithms/regular.py
+++ b/networkx/algorithms/regular.py
@@ -122,7 +122,7 @@ def k_factor(G, k, matching_weight="weight"):
adj_view = self.g[self.original]
neighbors = list(adj_view.keys())
edge_attrs = list(adj_view.values())
- for (outer, neighbor, edge_attrs) in zip(
+ for outer, neighbor, edge_attrs in zip(
self.outer_vertices, neighbors, edge_attrs
):
self.g.add_edge(outer, neighbor, **edge_attrs)
@@ -155,7 +155,7 @@ def k_factor(G, k, matching_weight="weight"):
def replace_node(self):
adj_view = self.g[self.original]
- for (outer, inner, (neighbor, edge_attrs)) in zip(
+ for outer, inner, (neighbor, edge_attrs) in zip(
self.outer_vertices, self.inner_vertices, list(adj_view.items())
):
self.g.add_edge(outer, inner)
diff --git a/networkx/algorithms/simple_paths.py b/networkx/algorithms/simple_paths.py
index d81d2345..05a59733 100644
--- a/networkx/algorithms/simple_paths.py
+++ b/networkx/algorithms/simple_paths.py
@@ -433,7 +433,7 @@ def _all_simple_edge_paths_multigraph(G, source, targets, cutoff):
visited.append(child)
stack.append(iter(G.edges(child[1], keys=True)))
else: # len(visited) == cutoff:
- for (u, v, k) in [child] + list(children):
+ for u, v, k in [child] + list(children):
if v in targets:
yield visited[1:] + [(u, v, k)]
stack.pop()
diff --git a/networkx/algorithms/tests/test_asteroidal.py b/networkx/algorithms/tests/test_asteroidal.py
index b0487aff..67131b2d 100644
--- a/networkx/algorithms/tests/test_asteroidal.py
+++ b/networkx/algorithms/tests/test_asteroidal.py
@@ -2,7 +2,6 @@ import networkx as nx
def test_is_at_free():
-
is_at_free = nx.asteroidal.is_at_free
cycle = nx.cycle_graph(6)
diff --git a/networkx/algorithms/tests/test_chordal.py b/networkx/algorithms/tests/test_chordal.py
index 2d4b757e..97eb46cd 100644
--- a/networkx/algorithms/tests/test_chordal.py
+++ b/networkx/algorithms/tests/test_chordal.py
@@ -98,7 +98,7 @@ class TestMCS:
def test_chordal_find_cliques_path(self):
G = nx.path_graph(10)
cliqueset = nx.chordal_graph_cliques(G)
- for (u, v) in G.edges():
+ for u, v in G.edges():
assert frozenset([u, v]) in cliqueset or frozenset([v, u]) in cliqueset
def test_chordal_find_cliquesCC(self):
diff --git a/networkx/algorithms/tests/test_communicability.py b/networkx/algorithms/tests/test_communicability.py
index bf219888..0f447094 100644
--- a/networkx/algorithms/tests/test_communicability.py
+++ b/networkx/algorithms/tests/test_communicability.py
@@ -26,7 +26,6 @@ class TestCommunicability:
assert answer[k1][k2] == pytest.approx(result[k1][k2], abs=1e-7)
def test_communicability2(self):
-
answer_orig = {
("1", "1"): 1.6445956054135658,
("1", "Albert"): 0.7430186221096251,
diff --git a/networkx/algorithms/tests/test_lowest_common_ancestors.py b/networkx/algorithms/tests/test_lowest_common_ancestors.py
index 1a8fd03c..66d75220 100644
--- a/networkx/algorithms/tests/test_lowest_common_ancestors.py
+++ b/networkx/algorithms/tests/test_lowest_common_ancestors.py
@@ -48,7 +48,7 @@ class TestTreeLCA:
@staticmethod
def assert_has_same_pairs(d1, d2):
- for (a, b) in ((min(pair), max(pair)) for pair in chain(d1, d2)):
+ for a, b in ((min(pair), max(pair)) for pair in chain(d1, d2)):
assert get_pair(d1, a, b) == get_pair(d2, a, b)
def test_tree_all_pairs_lca_default_root(self):
diff --git a/networkx/algorithms/tests/test_reciprocity.py b/networkx/algorithms/tests/test_reciprocity.py
index 2c5fc04c..eee6f2ee 100644
--- a/networkx/algorithms/tests/test_reciprocity.py
+++ b/networkx/algorithms/tests/test_reciprocity.py
@@ -4,7 +4,6 @@ import networkx as nx
class TestReciprocity:
-
# test overall reicprocity by passing whole graph
def test_reciprocity_digraph(self):
DG = nx.DiGraph([(1, 2), (2, 1)])
diff --git a/networkx/algorithms/threshold.py b/networkx/algorithms/threshold.py
index f462f265..1031ca15 100644
--- a/networkx/algorithms/threshold.py
+++ b/networkx/algorithms/threshold.py
@@ -357,7 +357,7 @@ def find_alternating_4_cycle(G):
Otherwise returns the cycle as [a,b,c,d] where (a,b)
and (c,d) are edges and (a,c) and (b,d) are not.
"""
- for (u, v) in G.edges():
+ for u, v in G.edges():
for w in G.nodes():
if not G.has_edge(u, w) and u != w:
for x in G.neighbors(w):
diff --git a/networkx/algorithms/tree/branchings.py b/networkx/algorithms/tree/branchings.py
index 8f8602b3..264f98cc 100644
--- a/networkx/algorithms/tree/branchings.py
+++ b/networkx/algorithms/tree/branchings.py
@@ -352,7 +352,7 @@ class Edmonds:
d[partition] = data.get(partition)
if preserve_attrs:
- for (d_k, d_v) in data.items():
+ for d_k, d_v in data.items():
if d_k != attr:
d[d_k] = d_v
@@ -698,7 +698,7 @@ class Edmonds:
# Optionally, preserve the other edge attributes of the original
# graph
if preserve_attrs:
- for (key, value) in d.items():
+ for key, value in d.items():
if key not in [self.attr, self.candidate_attr]:
dd[key] = value
diff --git a/networkx/algorithms/tree/tests/test_recognition.py b/networkx/algorithms/tree/tests/test_recognition.py
index d9c49438..a9c6c5aa 100644
--- a/networkx/algorithms/tree/tests/test_recognition.py
+++ b/networkx/algorithms/tree/tests/test_recognition.py
@@ -4,13 +4,11 @@ import networkx as nx
class TestTreeRecognition:
-
graph = nx.Graph
multigraph = nx.MultiGraph
@classmethod
def setup_class(cls):
-
cls.T1 = cls.graph()
cls.T2 = cls.graph()
diff --git a/networkx/algorithms/triads.py b/networkx/algorithms/triads.py
index b81ad094..0b40a325 100644
--- a/networkx/algorithms/triads.py
+++ b/networkx/algorithms/triads.py
@@ -490,7 +490,7 @@ def triad_type(G):
elif e1[1] == e2[0] or e2[1] == e1[0]:
return "021C"
elif num_edges == 3:
- for (e1, e2, e3) in permutations(G.edges(), 3):
+ for e1, e2, e3 in permutations(G.edges(), 3):
if set(e1) == set(e2):
if e3[0] in e1:
return "111U"
@@ -502,7 +502,7 @@ def triad_type(G):
# e3 == (e1[0], e2[1]) and e2 == (e1[1], e3[1]):
return "030T"
elif num_edges == 4:
- for (e1, e2, e3, e4) in permutations(G.edges(), 4):
+ for e1, e2, e3, e4 in permutations(G.edges(), 4):
if set(e1) == set(e2):
# identify pair of symmetric edges (which necessarily exists)
if set(e3) == set(e4):