Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e547e70

Browse files
authored
Merge pull request #18905 from brunobeltran/fail-docs-on-warn
DOC: Make docs fail on Warning (and fix all existing warnings)
2 parents 93157a3 + b705e02 commit e547e70

16 files changed

Lines changed: 92 additions & 128 deletions

File tree

doc/conf.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
# General configuration
3131
# ---------------------
3232

33+
# Unless we catch the warning explicitly somewhere, a warning should cause the
34+
# docs build to fail. This is especially useful for getting rid of deprecated
35+
# usage in the gallery.
36+
warnings.filterwarnings('error', append=True)
37+
3338
# Strip backslahes in function's signature
3439
# To be removed when numpydoc > 0.9.x
3540
strip_signature_backslash = True
@@ -108,6 +113,12 @@ def _check_dependencies():
108113

109114
autosummary_generate = True
110115

116+
# we should ignore warnings coming from importing deprecated modules for
117+
# autodoc purposes, as this will disappear automatically when they are removed
118+
warnings.filterwarnings('ignore', category=MatplotlibDeprecationWarning,
119+
module='importlib', # used by sphinx.autodoc.importer
120+
message=r'(\n|.)*module was deprecated.*')
121+
111122
autodoc_docstring_signature = True
112123
autodoc_default_options = {'members': None, 'undoc-members': None}
113124

doc/devel/documenting_mpl.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Optional, but recommended:
9191
* `optipng <http://optipng.sourceforge.net>`_
9292
* the font "Humor Sans" (aka the "XKCD" font), or the free alternative
9393
`Comic Neue <http://comicneue.com/>`_.
94+
* the font "Times New Roman"
9495

9596
.. note::
9697

examples/animation/rain.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525

2626
# Create rain data
2727
n_drops = 50
28-
rain_drops = np.zeros(n_drops, dtype=[('position', float, 2),
29-
('size', float, 1),
30-
('growth', float, 1),
31-
('color', float, 4)])
28+
rain_drops = np.zeros(n_drops, dtype=[('position', float, (2,)),
29+
('size', float),
30+
('growth', float),
31+
('color', float, (4,))])
3232

3333
# Initialize the raindrops in random positions and with
3434
# random growth rates.

examples/images_contours_and_fields/contourf_demo.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
66
How to use the `.axes.Axes.contourf` method to create filled contour plots.
77
"""
8-
98
import numpy as np
109
import matplotlib.pyplot as plt
1110

@@ -88,8 +87,7 @@
8887
# Illustrate all 4 possible "extend" settings:
8988
extends = ["neither", "both", "min", "max"]
9089
cmap = plt.cm.get_cmap("winter")
91-
cmap.set_under("magenta")
92-
cmap.set_over("yellow")
90+
cmap = cmap.with_extremes(under="magenta", over="yellow")
9391
# Note: contouring simply excludes masked or nan regions, so
9492
# instead of using the "bad" colormap value for them, it draws
9593
# nothing at all in them. Therefore the following would have

examples/images_contours_and_fields/pcolormesh_grids.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,16 @@ def _annotate(ax, x, y, title):
5555
# -----------------------------
5656
#
5757
# Often, however, data is provided where *X* and *Y* match the shape of *Z*.
58-
# As of Matplotlib v3.3, ``shading='flat'`` is deprecated when this is the
59-
# case, a warning is raised, and the last row and column of *Z* are dropped.
60-
# This dropping of the last row and column is what Matplotlib did silently
61-
# previous to v3.3, and is compatible with what Matlab does.
58+
# While this makes sense for other ``shading`` types, it is no longer permitted
59+
# when ``shading='flat'`` (and will raise a MatplotlibDeprecationWarning as of
60+
# Matplotlib v3.3). Historically, Matplotlib silently dropped the last row and
61+
# column of *Z* in this case, to match Matlab's behavior. If this behavior is
62+
# still desired, simply drop the last row and column manually:
6263

6364
x = np.arange(ncols) # note *not* ncols + 1 as before
6465
y = np.arange(nrows)
6566
fig, ax = plt.subplots()
66-
ax.pcolormesh(x, y, Z, shading='flat', vmin=Z.min(), vmax=Z.max())
67+
ax.pcolormesh(x, y, Z[:-1, :-1], shading='flat', vmin=Z.min(), vmax=Z.max())
6768
_annotate(ax, x, y, "shading='flat': X, Y, C same shape")
6869

6970
###############################################################################

examples/images_contours_and_fields/pcolormesh_levels.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@
5151
# ---------------------
5252
#
5353
# Often a user wants to pass *X* and *Y* with the same sizes as *Z* to
54-
# `.axes.Axes.pcolormesh`. This is also allowed if ``shading='auto'`` is
55-
# passed (default set by :rc:`pcolor.shading`). Pre Matplotlib 3.3,
54+
# `.axes.Axes.pcolormesh`. This is also allowed if ``shading='auto'`` is
55+
# passed (default set by :rc:`pcolor.shading`). Pre Matplotlib 3.3,
5656
# ``shading='flat'`` would drop the last column and row of *Z*; while that
5757
# is still allowed for back compatibility purposes, a DeprecationWarning is
58-
# raised.
58+
# raised. If this is really what you want, then simply drop the last row and
59+
# column of Z manually:
5960

6061
x = np.arange(10) # len = 10
6162
y = np.arange(6) # len = 6
@@ -64,7 +65,8 @@
6465
fig, axs = plt.subplots(2, 1, sharex=True, sharey=True)
6566
axs[0].pcolormesh(X, Y, Z, vmin=np.min(Z), vmax=np.max(Z), shading='auto')
6667
axs[0].set_title("shading='auto' = 'nearest'")
67-
axs[1].pcolormesh(X, Y, Z, vmin=np.min(Z), vmax=np.max(Z), shading='flat')
68+
axs[1].pcolormesh(X, Y, Z[:-1, :-1], vmin=np.min(Z), vmax=np.max(Z),
69+
shading='flat')
6870
axs[1].set_title("shading='flat'")
6971

7072
###############################################################################

examples/specialty_plots/advanced_hillshading.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def display_colorbar():
2525
# Use a proxy artist for the colorbar...
2626
im = ax.imshow(z, cmap=cmap)
2727
im.remove()
28-
fig.colorbar(im)
28+
fig.colorbar(im, ax=ax)
2929

3030
ax.set_title('Using a colorbar with a shaded plot', size='x-large')
3131

examples/style_sheets/style_sheets_reference.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ def plot_figure(style_label=""):
137137

138138
# Plot a demonstration figure for every available style sheet.
139139
for style_label in style_list:
140-
with plt.style.context(style_label):
141-
fig = plot_figure(style_label=style_label)
140+
with plt.rc_context({"figure.max_open_warning": len(style_list)}):
141+
with plt.style.context(style_label):
142+
fig = plot_figure(style_label=style_label)
142143

143144
plt.show()

examples/subplots_axes_and_figures/secondary_axis.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,20 @@ def rad2deg(x):
5757
ax.set_title('Random spectrum')
5858

5959

60-
def forward(x):
61-
return 1 / x
60+
def one_over(x):
61+
"""Vectorized 1/x, treating x==0 manually"""
62+
x = np.array(x).astype(float)
63+
near_zero = np.isclose(x, 0)
64+
x[near_zero] = np.inf
65+
x[~near_zero] = 1 / x[~near_zero]
66+
return x
6267

6368

64-
def inverse(x):
65-
return 1 / x
69+
# the function "1/x" is its own inverse
70+
inverse = one_over
6671

6772

68-
secax = ax.secondary_xaxis('top', functions=(forward, inverse))
73+
secax = ax.secondary_xaxis('top', functions=(one_over, inverse))
6974
secax.set_xlabel('period [s]')
7075
plt.show()
7176

examples/text_labels_and_annotations/usetex_baseline_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ def __init__(self, *args, preview=False, **kwargs):
3030
super().__init__(*args, **kwargs)
3131

3232
def draw(self, renderer):
33-
with plt.rc_context({"text.latex.preview": self.preview}):
34-
super().draw(renderer)
33+
from matplotlib import _api # internal, *do not use*
34+
with _api.suppress_matplotlib_deprecation_warning():
35+
with plt.rc_context({"text.latex.preview": self.preview}):
36+
super().draw(renderer)
3537

3638

3739
def test_window_extent(ax, usetex, preview):

0 commit comments

Comments
 (0)