Skip to content

Commit 90b63d7

Browse files
authored
Fix type annotations for matplotlib 3.10 and numpy 2.2 (#811)
1 parent 86e8707 commit 90b63d7

File tree

6 files changed

+24
-15
lines changed

6 files changed

+24
-15
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ repos:
6868
| advanced/interfacing_with_c/numpy_c_api/test_cos_module_np\.py$
6969
| intro/numpy/solutions/2_a_call_fortran\.py$
7070
| advanced/advanced_numpy/examples/mandelplot\.py$
71+
| intro/numpy/solutions/2_5_markov_chain\.py$
72+
| intro/matplotlib/examples/plot_bar\.py$
7173
)
7274
7375
- repo: https://github.com/codespell-project/codespell

advanced/optimizing/ica.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def _ica_par(X, tol, g, gprime, fun_args, maxit, w_init):
8787

8888
W1 = _sym_decorrelation(W1)
8989

90-
lim = max(abs(abs(np.diag(W1 @ W.T)) - 1))
90+
lim = np.max(np.abs(np.abs(np.diag(W1 @ W.T)) - 1))
9191
W = W1
9292
it = it + 1
9393

intro/matplotlib/examples/plot_bar.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
n = 12
1212
X = np.arange(n)
1313
rng = np.random.default_rng()
14-
Y1 = (1 - X / float(n)) * rng.uniform(0.5, 1.0, n)
15-
Y2 = (1 - X / float(n)) * rng.uniform(0.5, 1.0, n)
14+
Y1 = (1 - X / n) * rng.uniform(0.5, 1.0, n)
15+
Y2 = (1 - X / n) * rng.uniform(0.5, 1.0, n)
1616

1717
plt.axes((0.025, 0.025, 0.95, 0.95))
1818
plt.bar(X, +Y1, facecolor="#9999ff", edgecolor="white")
1919
plt.bar(X, -Y2, facecolor="#ff9999", edgecolor="white")
2020

21-
for x, y in zip(X, Y1, strict=True):
22-
plt.text(x + 0.4, y + 0.05, f"{y:.2f}", ha="center", va="bottom")
21+
for x, y in zip(X, Y1):
22+
plt.text(x, y + 0.05, f"{y:.2f}", ha="center", va="bottom")
2323

24-
for x, y in zip(X, Y2, strict=True):
25-
plt.text(x + 0.4, -y - 0.05, f"{y:.2f}", ha="center", va="top")
24+
for x, y in zip(X, Y2):
25+
plt.text(x, -y - 0.05, f"{y:.2f}", ha="center", va="top")
2626

2727
plt.xlim(-0.5, n)
2828
plt.xticks([])

intro/matplotlib/examples/plot_plot3d.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
from mpl_toolkits.mplot3d import Axes3D
1111

1212
ax: Axes3D = plt.figure().add_subplot(projection="3d")
13-
X = np.arange(-4, 4, 0.25)
14-
Y = np.arange(-4, 4, 0.25)
15-
X, Y = np.meshgrid(X, Y)
13+
x = np.arange(-4, 4, 0.25)
14+
y = np.arange(-4, 4, 0.25)
15+
X, Y = np.meshgrid(x, y)
1616
R = np.sqrt(X**2 + Y**2)
1717
Z = np.sin(R)
1818

intro/matplotlib/examples/pretty_plots/plot_plot3d_ext.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99
import matplotlib.pyplot as plt
1010
from mpl_toolkits.mplot3d import Axes3D
1111

12-
fig = plt.figure()
13-
ax = Axes3D(fig)
14-
X = np.arange(-4, 4, 0.25)
15-
Y = np.arange(-4, 4, 0.25)
16-
X, Y = np.meshgrid(X, Y)
12+
x = np.arange(-4, 4, 0.25)
13+
y = np.arange(-4, 4, 0.25)
14+
X, Y = np.meshgrid(x, y)
1715
R = np.sqrt(X**2 + Y**2)
1816
Z = np.sin(R)
1917

18+
fig = plt.figure()
19+
ax: Axes3D = fig.add_subplot(111, projection="3d")
20+
2021
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap="hot")
2122
ax.contourf(X, Y, Z, zdir="z", offset=-2, cmap="hot")
23+
2224
ax.set_zlim(-2, 2)
2325
plt.xticks([])
2426
plt.yticks([])

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ exclude = '''
2323
| advanced/interfacing_with_c/numpy_c_api/test_cos_module_np\.py$
2424
| intro/numpy/solutions/2_a_call_fortran\.py$
2525
| advanced/advanced_numpy/examples/mandelplot\.py$
26+
| intro/numpy/solutions/2_5_markov_chain\.py$
27+
| intro/matplotlib/examples/plot_bar\.py$
2628
)
2729
'''
30+
# intro/numpy/solutions/2_5_markov_chain.py -> https://github.com/numpy/numpy/issues/27957
31+
# intro/matplotliub/examples/plot_bar.py -> https://github.com/matplotlib/matplotlib/issues/29332
2832

2933
# Can make these more strict over time
3034
allow_untyped_defs = true
@@ -109,6 +113,7 @@ ignore = [
109113
"B006", # Do not use mutable data structures for argument defaults
110114
"B007", # Loop control variable {name} not used within loop body
111115
"B018", # Found useless expression. Either assign it to a variable or remove it.
116+
"B905", # Zip without explicit `strict` keyword
112117
"E402", # Module level import not at top of file
113118
"E501", # Line too long
114119
"E741", # Ambiguous variable name

0 commit comments

Comments
 (0)