summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMridul Seth <seth.mridul@gmail.com>2022-03-29 18:01:52 +0400
committerGitHub <noreply@github.com>2022-03-29 07:01:52 -0700
commitf6755ffa00211b523c6c0bec5398bc6c3c43c8b1 (patch)
tree328c18e52cf8f563064ed319e5d4b46be064149a
parentfd52aa52ada0c08dfc25fc749f08589d7b734c00 (diff)
downloadnetworkx-f6755ffa00211b523c6c0bec5398bc6c3c43c8b1.tar.gz
Update black (#5438)
* CI: sync up black dev requirements version with precommit * Run black Co-authored-by: Jarrod Millman <jarrod.millman@gmail.com>
-rw-r--r--.pre-commit-config.yaml2
-rw-r--r--examples/algorithms/plot_iterated_dynamical_systems.py2
-rw-r--r--networkx/algorithms/assortativity/correlation.py4
-rw-r--r--networkx/algorithms/bipartite/centrality.py4
-rw-r--r--networkx/algorithms/community/quality.py4
-rw-r--r--networkx/algorithms/community/tests/test_quality.py34
-rw-r--r--networkx/algorithms/flow/shortestaugmentingpath.py2
-rw-r--r--networkx/algorithms/shortest_paths/tests/test_weighted.py4
-rw-r--r--networkx/algorithms/similarity.py2
-rw-r--r--networkx/algorithms/threshold.py2
-rw-r--r--networkx/algorithms/tree/tests/test_coding.py6
-rw-r--r--networkx/algorithms/tree/tests/test_operations.py4
-rw-r--r--networkx/drawing/layout.py12
-rw-r--r--networkx/generators/degree_seq.py2
-rw-r--r--networkx/generators/expanders.py2
-rw-r--r--networkx/generators/geometric.py6
-rw-r--r--networkx/generators/tests/test_classic.py8
-rw-r--r--networkx/generators/tests/test_cographs.py2
-rw-r--r--networkx/generators/tests/test_lattice.py2
-rw-r--r--networkx/generators/tests/test_sudoku.py2
-rw-r--r--networkx/linalg/bethehessianmatrix.py4
-rw-r--r--networkx/readwrite/gml.py2
-rw-r--r--networkx/readwrite/graph6.py2
-rw-r--r--networkx/readwrite/sparse6.py2
-rw-r--r--networkx/readwrite/tests/test_gml.py10
-rw-r--r--networkx/utils/random_sequence.py2
-rw-r--r--networkx/utils/tests/test_heaps.py4
-rw-r--r--requirements/developer.txt4
28 files changed, 68 insertions, 68 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 8c7311d6..2c85e1ef 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -3,7 +3,7 @@
repos:
- repo: https://github.com/psf/black
- rev: 21.12b0
+ rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/asottile/pyupgrade
diff --git a/examples/algorithms/plot_iterated_dynamical_systems.py b/examples/algorithms/plot_iterated_dynamical_systems.py
index 1dde3276..a19baeb5 100644
--- a/examples/algorithms/plot_iterated_dynamical_systems.py
+++ b/examples/algorithms/plot_iterated_dynamical_systems.py
@@ -109,7 +109,7 @@ def powersum(n, p, b=10):
dlist = digitsrep(n, b)
sum = 0
for k in dlist:
- sum += k ** p
+ sum += k**p
return sum
diff --git a/networkx/algorithms/assortativity/correlation.py b/networkx/algorithms/assortativity/correlation.py
index bdabf8fb..48801eb6 100644
--- a/networkx/algorithms/assortativity/correlation.py
+++ b/networkx/algorithms/assortativity/correlation.py
@@ -291,8 +291,8 @@ def _numeric_ac(M, mapping):
idx = list(mapping.values())
a = M.sum(axis=0)
b = M.sum(axis=1)
- vara = (a[idx] * x ** 2).sum() - ((a[idx] * x).sum()) ** 2
- varb = (b[idx] * y ** 2).sum() - ((b[idx] * y).sum()) ** 2
+ vara = (a[idx] * x**2).sum() - ((a[idx] * x).sum()) ** 2
+ varb = (b[idx] * y**2).sum() - ((b[idx] * y).sum()) ** 2
xy = np.outer(x, y)
ab = np.outer(a[idx], b[idx])
return (xy * (M - ab)).sum() / np.sqrt(vara * varb)
diff --git a/networkx/algorithms/bipartite/centrality.py b/networkx/algorithms/bipartite/centrality.py
index bbd09394..fa8d3e1c 100644
--- a/networkx/algorithms/bipartite/centrality.py
+++ b/networkx/algorithms/bipartite/centrality.py
@@ -149,14 +149,14 @@ def betweenness_centrality(G, nodes):
s = (n - 1) // m
t = (n - 1) % m
bet_max_top = (
- ((m ** 2) * ((s + 1) ** 2))
+ ((m**2) * ((s + 1) ** 2))
+ (m * (s + 1) * (2 * t - s - 1))
- (t * ((2 * s) - t + 3))
) / 2.0
p = (m - 1) // n
r = (m - 1) % n
bet_max_bot = (
- ((n ** 2) * ((p + 1) ** 2))
+ ((n**2) * ((p + 1) ** 2))
+ (n * (p + 1) * (2 * r - p - 1))
- (r * ((2 * p) - r + 3))
) / 2.0
diff --git a/networkx/algorithms/community/quality.py b/networkx/algorithms/community/quality.py
index ce79727b..5f9d13ef 100644
--- a/networkx/algorithms/community/quality.py
+++ b/networkx/algorithms/community/quality.py
@@ -334,12 +334,12 @@ def modularity(G, communities, weight="weight", resolution=1):
out_degree = dict(G.out_degree(weight=weight))
in_degree = dict(G.in_degree(weight=weight))
m = sum(out_degree.values())
- norm = 1 / m ** 2
+ norm = 1 / m**2
else:
out_degree = in_degree = dict(G.degree(weight=weight))
deg_sum = sum(out_degree.values())
m = deg_sum / 2
- norm = 1 / deg_sum ** 2
+ norm = 1 / deg_sum**2
def community_contribution(community):
comm = set(community)
diff --git a/networkx/algorithms/community/tests/test_quality.py b/networkx/algorithms/community/tests/test_quality.py
index e45d7555..e90f2ba3 100644
--- a/networkx/algorithms/community/tests/test_quality.py
+++ b/networkx/algorithms/community/tests/test_quality.py
@@ -52,9 +52,9 @@ class TestCoverage:
def test_modularity():
G = nx.barbell_graph(3, 0)
C = [{0, 1, 4}, {2, 3, 5}]
- assert (-16 / (14 ** 2)) == pytest.approx(modularity(G, C), abs=1e-7)
+ assert (-16 / (14**2)) == pytest.approx(modularity(G, C), abs=1e-7)
C = [{0, 1, 2}, {3, 4, 5}]
- assert (35 * 2) / (14 ** 2) == pytest.approx(modularity(G, C), abs=1e-7)
+ assert (35 * 2) / (14**2) == pytest.approx(modularity(G, C), abs=1e-7)
n = 1000
G = nx.erdos_renyi_graph(n, 0.09, seed=42, directed=True)
@@ -76,59 +76,59 @@ def test_modularity():
def test_modularity_resolution():
G = nx.barbell_graph(3, 0)
C = [{0, 1, 4}, {2, 3, 5}]
- assert modularity(G, C) == pytest.approx(3 / 7 - 100 / 14 ** 2)
+ assert modularity(G, C) == pytest.approx(3 / 7 - 100 / 14**2)
gamma = 2
result = modularity(G, C, resolution=gamma)
- assert result == pytest.approx(3 / 7 - gamma * 100 / 14 ** 2)
+ assert result == pytest.approx(3 / 7 - gamma * 100 / 14**2)
gamma = 0.2
result = modularity(G, C, resolution=gamma)
- assert result == pytest.approx(3 / 7 - gamma * 100 / 14 ** 2)
+ assert result == pytest.approx(3 / 7 - gamma * 100 / 14**2)
C = [{0, 1, 2}, {3, 4, 5}]
- assert modularity(G, C) == pytest.approx(6 / 7 - 98 / 14 ** 2)
+ assert modularity(G, C) == pytest.approx(6 / 7 - 98 / 14**2)
gamma = 2
result = modularity(G, C, resolution=gamma)
- assert result == pytest.approx(6 / 7 - gamma * 98 / 14 ** 2)
+ assert result == pytest.approx(6 / 7 - gamma * 98 / 14**2)
gamma = 0.2
result = modularity(G, C, resolution=gamma)
- assert result == pytest.approx(6 / 7 - gamma * 98 / 14 ** 2)
+ assert result == pytest.approx(6 / 7 - gamma * 98 / 14**2)
G = nx.barbell_graph(5, 3)
C = [frozenset(range(5)), frozenset(range(8, 13)), frozenset(range(5, 8))]
gamma = 1
result = modularity(G, C, resolution=gamma)
# This C is maximal for gamma=1: modularity = 0.518229
- assert result == pytest.approx((22 / 24) - gamma * (918 / (48 ** 2)))
+ assert result == pytest.approx((22 / 24) - gamma * (918 / (48**2)))
gamma = 2
result = modularity(G, C, resolution=gamma)
- assert result == pytest.approx((22 / 24) - gamma * (918 / (48 ** 2)))
+ assert result == pytest.approx((22 / 24) - gamma * (918 / (48**2)))
gamma = 0.2
result = modularity(G, C, resolution=gamma)
- assert result == pytest.approx((22 / 24) - gamma * (918 / (48 ** 2)))
+ assert result == pytest.approx((22 / 24) - gamma * (918 / (48**2)))
C = [{0, 1, 2, 3}, {9, 10, 11, 12}, {5, 6, 7}, {4}, {8}]
gamma = 1
result = modularity(G, C, resolution=gamma)
- assert result == pytest.approx((14 / 24) - gamma * (598 / (48 ** 2)))
+ assert result == pytest.approx((14 / 24) - gamma * (598 / (48**2)))
gamma = 2.5
result = modularity(G, C, resolution=gamma)
# This C is maximal for gamma=2.5: modularity = -0.06553819
- assert result == pytest.approx((14 / 24) - gamma * (598 / (48 ** 2)))
+ assert result == pytest.approx((14 / 24) - gamma * (598 / (48**2)))
gamma = 0.2
result = modularity(G, C, resolution=gamma)
- assert result == pytest.approx((14 / 24) - gamma * (598 / (48 ** 2)))
+ assert result == pytest.approx((14 / 24) - gamma * (598 / (48**2)))
C = [frozenset(range(8)), frozenset(range(8, 13))]
gamma = 1
result = modularity(G, C, resolution=gamma)
- assert result == pytest.approx((23 / 24) - gamma * (1170 / (48 ** 2)))
+ assert result == pytest.approx((23 / 24) - gamma * (1170 / (48**2)))
gamma = 2
result = modularity(G, C, resolution=gamma)
- assert result == pytest.approx((23 / 24) - gamma * (1170 / (48 ** 2)))
+ assert result == pytest.approx((23 / 24) - gamma * (1170 / (48**2)))
gamma = 0.3
result = modularity(G, C, resolution=gamma)
# This C is maximal for gamma=0.3: modularity = 0.805990
- assert result == pytest.approx((23 / 24) - gamma * (1170 / (48 ** 2)))
+ assert result == pytest.approx((23 / 24) - gamma * (1170 / (48**2)))
def test_inter_community_edges_with_digraphs():
diff --git a/networkx/algorithms/flow/shortestaugmentingpath.py b/networkx/algorithms/flow/shortestaugmentingpath.py
index 6c7ce16e..b523c254 100644
--- a/networkx/algorithms/flow/shortestaugmentingpath.py
+++ b/networkx/algorithms/flow/shortestaugmentingpath.py
@@ -102,7 +102,7 @@ def shortest_augmenting_path_impl(G, s, t, capacity, residual, two_phase, cutoff
flow_value = 0
path = [s]
u = s
- d = n if not two_phase else int(min(m ** 0.5, 2 * n ** (2.0 / 3)))
+ d = n if not two_phase else int(min(m**0.5, 2 * n ** (2.0 / 3)))
done = R_nodes[s]["height"] >= d
while not done:
height = R_nodes[u]["height"]
diff --git a/networkx/algorithms/shortest_paths/tests/test_weighted.py b/networkx/algorithms/shortest_paths/tests/test_weighted.py
index 15a219ee..2b186968 100644
--- a/networkx/algorithms/shortest_paths/tests/test_weighted.py
+++ b/networkx/algorithms/shortest_paths/tests/test_weighted.py
@@ -198,7 +198,7 @@ class TestWeightedPath(WeightedTestBase):
def test_weight_functions(self):
def heuristic(*z):
- return sum(val ** 2 for val in z)
+ return sum(val**2 for val in z)
def getpath(pred, v, s):
return [v] if v == s else getpath(pred, pred[v], s) + [v]
@@ -223,7 +223,7 @@ class TestWeightedPath(WeightedTestBase):
path = [6] + list(range(t + 1))
def weight(u, v, _):
- return 1 + v ** 2
+ return 1 + v**2
length = sum(weight(u, v, None) for u, v in pairwise(path))
vlp(G, s, t, length, nx.bidirectional_dijkstra, weight)
diff --git a/networkx/algorithms/similarity.py b/networkx/algorithms/similarity.py
index cc6d646a..d5f46353 100644
--- a/networkx/algorithms/similarity.py
+++ b/networkx/algorithms/similarity.py
@@ -1582,7 +1582,7 @@ def panther_similarity(G, source, k=5, path_length=5, c=0.5, delta=0.1, eps=None
# Calculate the sample size ``R`` for how many paths
# to randomly generate
t_choose_2 = math.comb(path_length, 2)
- sample_size = int((c / eps ** 2) * (np.log2(t_choose_2) + 1 + np.log(1 / delta)))
+ sample_size = int((c / eps**2) * (np.log2(t_choose_2) + 1 + np.log(1 / delta)))
index_map = {}
_ = list(
generate_random_paths(
diff --git a/networkx/algorithms/threshold.py b/networkx/algorithms/threshold.py
index aa9b13db..217b70e6 100644
--- a/networkx/algorithms/threshold.py
+++ b/networkx/algorithms/threshold.py
@@ -547,7 +547,7 @@ def degree_correlation(creation_sequence):
for dj in rdi:
degj = ds[dj]
s1 += degj * degi
- s2 += degi ** 2 + degj ** 2
+ s2 += degi**2 + degj**2
s3 += degi + degj
m += 1
denom = 2 * m * s2 - s3 * s3
diff --git a/networkx/algorithms/tree/tests/test_coding.py b/networkx/algorithms/tree/tests/test_coding.py
index 42568aff..1c3b127d 100644
--- a/networkx/algorithms/tree/tests/test_coding.py
+++ b/networkx/algorithms/tree/tests/test_coding.py
@@ -83,7 +83,7 @@ class TestNestedTuple:
nx.to_nested_tuple(G, "bogus")
def test_encoding(self):
- T = nx.full_rary_tree(2, 2 ** 3 - 1)
+ T = nx.full_rary_tree(2, 2**3 - 1)
expected = (((), ()), ((), ()))
actual = nx.to_nested_tuple(T, 0)
assert nodes_equal(expected, actual)
@@ -100,7 +100,7 @@ class TestNestedTuple:
def test_decoding(self):
balanced = (((), ()), ((), ()))
- expected = nx.full_rary_tree(2, 2 ** 3 - 1)
+ expected = nx.full_rary_tree(2, 2**3 - 1)
actual = nx.from_nested_tuple(balanced)
assert nx.is_isomorphic(expected, actual)
@@ -108,5 +108,5 @@ class TestNestedTuple:
balanced = (((), ()), ((), ()))
T = nx.from_nested_tuple(balanced, sensible_relabeling=True)
edges = [(0, 1), (0, 2), (1, 3), (1, 4), (2, 5), (2, 6)]
- assert nodes_equal(list(T), list(range(2 ** 3 - 1)))
+ assert nodes_equal(list(T), list(range(2**3 - 1)))
assert edges_equal(list(T.edges()), edges)
diff --git a/networkx/algorithms/tree/tests/test_operations.py b/networkx/algorithms/tree/tests/test_operations.py
index 3f580dde..522c6dce 100644
--- a/networkx/algorithms/tree/tests/test_operations.py
+++ b/networkx/algorithms/tree/tests/test_operations.py
@@ -31,7 +31,7 @@ class TestJoin:
def test_basic(self):
"""Tests for joining multiple subtrees at a root node."""
- trees = [(nx.full_rary_tree(2, 2 ** 2 - 1), 0) for i in range(2)]
+ trees = [(nx.full_rary_tree(2, 2**2 - 1), 0) for i in range(2)]
actual = nx.join(trees)
- expected = nx.full_rary_tree(2, 2 ** 3 - 1)
+ expected = nx.full_rary_tree(2, 2**3 - 1)
assert nx.is_isomorphic(actual, expected)
diff --git a/networkx/drawing/layout.py b/networkx/drawing/layout.py
index b4946c71..cca9f757 100644
--- a/networkx/drawing/layout.py
+++ b/networkx/drawing/layout.py
@@ -544,7 +544,7 @@ def _fruchterman_reingold(
np.clip(distance, 0.01, None, out=distance)
# displacement "force"
displacement = np.einsum(
- "ijk,ij->ik", delta, (k * k / distance ** 2 - A * distance / k)
+ "ijk,ij->ik", delta, (k * k / distance**2 - A * distance / k)
)
# update positions
length = np.linalg.norm(displacement, axis=-1)
@@ -614,17 +614,17 @@ def _sparse_fruchterman_reingold(
# difference between this row's node position and all others
delta = (pos[i] - pos).T
# distance between points
- distance = np.sqrt((delta ** 2).sum(axis=0))
+ distance = np.sqrt((delta**2).sum(axis=0))
# enforce minimum distance of 0.01
distance = np.where(distance < 0.01, 0.01, distance)
# the adjacency matrix row
Ai = A.getrowview(i).toarray() # TODO: revisit w/ sparse 1D container
# displacement "force"
displacement[:, i] += (
- delta * (k * k / distance ** 2 - Ai * distance / k)
+ delta * (k * k / distance**2 - Ai * distance / k)
).sum(axis=1)
# update positions
- length = np.sqrt((displacement ** 2).sum(axis=0))
+ length = np.sqrt((displacement**2).sum(axis=0))
length = np.where(length < 0.01, 0.1, length)
delta_pos = (displacement * t / length).T
pos += delta_pos
@@ -747,14 +747,14 @@ def _kamada_kawai_costfn(pos_vec, np, invdist, meanweight, dim):
offset = nodesep * invdist - 1.0
offset[np.diag_indices(nNodes)] = 0
- cost = 0.5 * np.sum(offset ** 2)
+ cost = 0.5 * np.sum(offset**2)
grad = np.einsum("ij,ij,ijk->ik", invdist, offset, direction) - np.einsum(
"ij,ij,ijk->jk", invdist, offset, direction
)
# Additional parabolic term to encourage mean position to be near origin:
sumpos = np.sum(pos_arr, axis=0)
- cost += 0.5 * meanweight * np.sum(sumpos ** 2)
+ cost += 0.5 * meanweight * np.sum(sumpos**2)
grad += meanweight * sumpos
return (cost, grad.ravel())
diff --git a/networkx/generators/degree_seq.py b/networkx/generators/degree_seq.py
index 05e86797..46244f0e 100644
--- a/networkx/generators/degree_seq.py
+++ b/networkx/generators/degree_seq.py
@@ -820,7 +820,7 @@ class DegreeSequenceRandomGraph:
def phase1(self):
# choose node pairs from (degree) weighted distribution
rem_deg = self.remaining_degree
- while sum(rem_deg.values()) >= 2 * self.dmax ** 2:
+ while sum(rem_deg.values()) >= 2 * self.dmax**2:
u, v = sorted(random_weighted_sample(rem_deg, 2, self.rng))
if self.graph.has_edge(u, v):
continue
diff --git a/networkx/generators/expanders.py b/networkx/generators/expanders.py
index 88c49ea3..14ed9a79 100644
--- a/networkx/generators/expanders.py
+++ b/networkx/generators/expanders.py
@@ -193,7 +193,7 @@ def paley_graph(p, create_using=None):
# Compute the squares in Z/pZ.
# Make it a set to uniquify (there are exactly (p-1)/2 squares in Z/pZ
# when is prime).
- square_set = {(x ** 2) % p for x in range(1, p) if (x ** 2) % p != 0}
+ square_set = {(x**2) % p for x in range(1, p) if (x**2) % p != 0}
for x in range(p):
for x2 in square_set:
diff --git a/networkx/generators/geometric.py b/networkx/generators/geometric.py
index 9888a6ae..4df4e439 100644
--- a/networkx/generators/geometric.py
+++ b/networkx/generators/geometric.py
@@ -91,7 +91,7 @@ def geometric_edges(G, radius, p):
import scipy.spatial # call as sp.spatial
except ImportError:
# no scipy KDTree so compute by for-loop
- radius_p = radius ** p
+ radius_p = radius**p
edges = [
(u, v)
for (u, pu), (v, pv) in combinations(nodes_pos, 2)
@@ -465,7 +465,7 @@ def geographical_threshold_graph(
if p_dist is None:
def p_dist(r):
- return r ** -2
+ return r**-2
# Returns ``True`` if and only if the nodes whose attributes are
# ``du`` and ``dv`` should be joined, according to the threshold
@@ -668,7 +668,7 @@ def navigable_small_world_graph(n, p=1, q=1, r=2, dim=2, seed=None):
d = sum((abs(b - a) for a, b in zip(p1, p2)))
if d <= p:
G.add_edge(p1, p2)
- probs.append(d ** -r)
+ probs.append(d**-r)
cdf = list(accumulate(probs))
for _ in range(q):
target = nodes[bisect_left(cdf, seed.uniform(0, cdf[-1]))]
diff --git a/networkx/generators/tests/test_classic.py b/networkx/generators/tests/test_classic.py
index 24077725..6a6038fc 100644
--- a/networkx/generators/tests/test_classic.py
+++ b/networkx/generators/tests/test_classic.py
@@ -26,9 +26,9 @@ class TestGeneratorClassic:
assert t.size() == order - 1
dh = nx.degree_histogram(t)
assert dh[0] == 0 # no nodes of 0
- assert dh[1] == r ** h # nodes of degree 1 are leaves
+ assert dh[1] == r**h # nodes of degree 1 are leaves
assert dh[r] == 1 # root is degree r
- assert dh[r + 1] == order - r ** h - 1 # everyone else is degree r+1
+ assert dh[r + 1] == order - r**h - 1 # everyone else is degree r+1
assert len(dh) == r + 2
def test_balanced_tree_star(self):
@@ -141,8 +141,8 @@ class TestGeneratorClassic:
for create_using in graphs:
for n in range(0, 4):
b = nx.binomial_tree(n, create_using)
- assert nx.number_of_nodes(b) == 2 ** n
- assert nx.number_of_edges(b) == (2 ** n - 1)
+ assert nx.number_of_nodes(b) == 2**n
+ assert nx.number_of_edges(b) == (2**n - 1)
def test_complete_graph(self):
# complete_graph(m) is a connected graph with
diff --git a/networkx/generators/tests/test_cographs.py b/networkx/generators/tests/test_cographs.py
index d357af1a..4d841964 100644
--- a/networkx/generators/tests/test_cographs.py
+++ b/networkx/generators/tests/test_cographs.py
@@ -9,7 +9,7 @@ def test_random_cograph():
n = 3
G = nx.random_cograph(n)
- assert len(G) == 2 ** n
+ assert len(G) == 2**n
# Every connected subgraph of G has diameter <= 2
if nx.is_connected(G):
diff --git a/networkx/generators/tests/test_lattice.py b/networkx/generators/tests/test_lattice.py
index 07271e3a..9e90573f 100644
--- a/networkx/generators/tests/test_lattice.py
+++ b/networkx/generators/tests/test_lattice.py
@@ -139,7 +139,7 @@ class TestHypercubeGraph:
def test_degree_distribution(self):
for n in range(1, 10):
G = nx.hypercube_graph(n)
- expected_histogram = [0] * n + [2 ** n]
+ expected_histogram = [0] * n + [2**n]
assert nx.degree_histogram(G) == expected_histogram
diff --git a/networkx/generators/tests/test_sudoku.py b/networkx/generators/tests/test_sudoku.py
index 366701d3..78809706 100644
--- a/networkx/generators/tests/test_sudoku.py
+++ b/networkx/generators/tests/test_sudoku.py
@@ -13,7 +13,7 @@ def test_sudoku_negative():
def test_sudoku_generator(n):
"""Generate Sudoku graphs of various sizes and verify their properties."""
G = nx.sudoku_graph(n)
- expected_nodes = n ** 4
+ expected_nodes = n**4
expected_degree = (n - 1) * (3 * n + 1)
expected_edges = expected_nodes * expected_degree // 2
assert not G.is_directed()
diff --git a/networkx/linalg/bethehessianmatrix.py b/networkx/linalg/bethehessianmatrix.py
index cb008465..d0354e36 100644
--- a/networkx/linalg/bethehessianmatrix.py
+++ b/networkx/linalg/bethehessianmatrix.py
@@ -66,7 +66,7 @@ def bethe_hessian_matrix(G, r=None, nodelist=None):
if nodelist is None:
nodelist = list(G)
if r is None:
- r = sum(d ** 2 for v, d in nx.degree(G)) / sum(d for v, d in nx.degree(G)) - 1
+ r = sum(d**2 for v, d in nx.degree(G)) / sum(d for v, d in nx.degree(G)) - 1
A = nx.to_scipy_sparse_array(G, nodelist=nodelist, format="csr")
n, m = A.shape
# TODO: Rm csr_array wrapper when spdiags array creation becomes available
@@ -81,4 +81,4 @@ def bethe_hessian_matrix(G, r=None, nodelist=None):
stacklevel=2,
)
# TODO: Remove the csr_matrix wrapper in NetworkX 3.0
- return sp.sparse.csr_matrix((r ** 2 - 1) * I - r * A + D)
+ return sp.sparse.csr_matrix((r**2 - 1) * I - r * A + D)
diff --git a/networkx/readwrite/gml.py b/networkx/readwrite/gml.py
index cb46e616..b5af8660 100644
--- a/networkx/readwrite/gml.py
+++ b/networkx/readwrite/gml.py
@@ -701,7 +701,7 @@ def generate_gml(G, stringizer=None):
elif value is False:
yield indent + key + " 0"
# GML only supports signed 32-bit integers
- elif value < -(2 ** 31) or value >= 2 ** 31:
+ elif value < -(2**31) or value >= 2**31:
yield indent + key + ' "' + str(value) + '"'
else:
yield indent + key + " " + str(value)
diff --git a/networkx/readwrite/graph6.py b/networkx/readwrite/graph6.py
index a7517f85..85aa2542 100644
--- a/networkx/readwrite/graph6.py
+++ b/networkx/readwrite/graph6.py
@@ -41,7 +41,7 @@ def _generate_graph6_bytes(G, nodes, header):
"""
n = len(G)
- if n >= 2 ** 36:
+ if n >= 2**36:
raise ValueError(
"graph6 is only defined if number of nodes is less " "than 2 ** 36"
)
diff --git a/networkx/readwrite/sparse6.py b/networkx/readwrite/sparse6.py
index 7d769f66..03e136de 100644
--- a/networkx/readwrite/sparse6.py
+++ b/networkx/readwrite/sparse6.py
@@ -41,7 +41,7 @@ def _generate_sparse6_bytes(G, nodes, header):
"""
n = len(G)
- if n >= 2 ** 36:
+ if n >= 2**36:
raise ValueError(
"sparse6 is only defined if number of nodes is less " "than 2 ** 36"
)
diff --git a/networkx/readwrite/tests/test_gml.py b/networkx/readwrite/tests/test_gml.py
index 50facec5..53dea957 100644
--- a/networkx/readwrite/tests/test_gml.py
+++ b/networkx/readwrite/tests/test_gml.py
@@ -433,7 +433,7 @@ graph
data = [
True,
False,
- 10 ** 20,
+ 10**20,
-2e33,
"'",
'"&&amp;&&#34;"',
@@ -592,13 +592,13 @@ graph
# Test export for numbers that barely fit or don't fit into 32 bits,
# and 3 numbers in the middle
numbers = {
- "toosmall": (-(2 ** 31)) - 1,
- "small": -(2 ** 31),
+ "toosmall": (-(2**31)) - 1,
+ "small": -(2**31),
"med1": -4,
"med2": 0,
"med3": 17,
- "big": (2 ** 31) - 1,
- "toobig": 2 ** 31,
+ "big": (2**31) - 1,
+ "toobig": 2**31,
}
G.add_node("Node", **numbers)
diff --git a/networkx/utils/random_sequence.py b/networkx/utils/random_sequence.py
index ad9b34a3..ac60b1f3 100644
--- a/networkx/utils/random_sequence.py
+++ b/networkx/utils/random_sequence.py
@@ -84,7 +84,7 @@ def zipf_rv(alpha, xmin=1, seed=None):
if alpha <= 1:
raise ValueError("a <= 1.0")
a1 = alpha - 1.0
- b = 2 ** a1
+ b = 2**a1
while True:
u = 1.0 - seed.random() # u in (0,1]
v = seed.random() # v in [0,1)
diff --git a/networkx/utils/tests/test_heaps.py b/networkx/utils/tests/test_heaps.py
index 29433881..cc1c66a9 100644
--- a/networkx/utils/tests/test_heaps.py
+++ b/networkx/utils/tests/test_heaps.py
@@ -48,9 +48,9 @@ data = [ # min should not invent an element.
# int and float values should interop.
("min", (1, -2.0)),
# pop removes minimum-valued element.
- ("insert", 3, -(10 ** 100), True),
+ ("insert", 3, -(10**100), True),
("insert", 4, 5, True),
- ("pop", (3, -(10 ** 100))),
+ ("pop", (3, -(10**100))),
("pop", (1, -2.0)),
# Decrease-insert should succeed.
("insert", 4, -50, True),
diff --git a/requirements/developer.txt b/requirements/developer.txt
index 057e25ee..fb04b33d 100644
--- a/requirements/developer.txt
+++ b/requirements/developer.txt
@@ -1,4 +1,4 @@
-black==22.1
+black==22.3.0
pyupgrade>=2.31
pre-commit>=2.17
-mypy>=0.931
+mypy>=0.942