Skip to content

Commit 886be24

Browse files
committed
Suppress/fix some test warnings.
The only remaining test that throws a warning is test_image.py::test_full_invalid ("converting a masked element to nan"), which I didn't suppress in the test because I think that should indeed not throw (we don't throw warnings when passing partially-nan data either).
1 parent 2eb26ee commit 886be24

File tree

6 files changed

+17
-13
lines changed

6 files changed

+17
-13
lines changed

lib/matplotlib/colors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,8 @@ def _transform(self, a):
11121112
"""
11131113
Inplace transformation.
11141114
"""
1115-
masked = np.abs(a) > self.linthresh
1115+
with np.errstate(invalid="ignore"):
1116+
masked = np.abs(a) > self.linthresh
11161117
sign = np.sign(a[masked])
11171118
log = (self._linscale_adj + np.log(np.abs(a[masked]) / self.linthresh))
11181119
log *= sign * self.linthresh

lib/matplotlib/tests/test_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1714,7 +1714,7 @@ def test_scatter_marker(self):
17141714
c=[(1, 0, 0), 'y', 'b', 'lime'],
17151715
s=[60, 50, 40, 30],
17161716
edgecolors=['k', 'r', 'g', 'b'],
1717-
verts=verts)
1717+
marker=verts)
17181718

17191719
@image_comparison(baseline_images=['scatter_2D'], remove_text=True,
17201720
extensions=['png'])

lib/matplotlib/tests/test_font_manager.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ def test_otf():
6767
if os.path.exists(fname):
6868
assert is_opentype_cff_font(fname)
6969

70-
otf_files = [f for f in fontManager.ttffiles if 'otf' in f]
71-
for f in otf_files:
72-
with open(f, 'rb') as fd:
73-
res = fd.read(4) == b'OTTO'
74-
assert res == is_opentype_cff_font(f)
70+
for f in fontManager.ttflist:
71+
if 'otf' in f.name:
72+
with open(f.name, 'rb') as fd:
73+
res = fd.read(4) == b'OTTO'
74+
assert res == is_opentype_cff_font(f.name)
7575

7676

7777
@pytest.mark.skipif(not has_fclist, reason='no fontconfig installed')

lib/matplotlib/tests/test_image.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,9 @@ def test_empty_imshow(make_norm):
875875
def test_imshow_float128():
876876
fig, ax = plt.subplots()
877877
ax.imshow(np.zeros((3, 3), dtype=np.longdouble))
878-
# Ensure that drawing doesn't cause crash
879-
fig.canvas.draw()
878+
with pytest.warns(UserWarning):
879+
# Ensure that drawing doesn't cause crash.
880+
fig.canvas.draw()
880881

881882

882883
def test_imshow_bool():

lib/matplotlib/tests/test_patches.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from numpy.testing import assert_almost_equal, assert_array_equal
66
import pytest
77

8+
from matplotlib.cbook import MatplotlibDeprecationWarning
89
from matplotlib.patches import Polygon, Rectangle
910
from matplotlib.testing.decorators import image_comparison, check_figures_equal
1011
import matplotlib.pyplot as plt
@@ -344,8 +345,9 @@ def test_patch_str():
344345
s = mpatches.Shadow(p, 1, 1)
345346
assert str(s) == "Shadow(ConnectionPatch((1, 2), (3, 4)))"
346347

347-
p = mpatches.YAArrow(plt.gcf(), (1, 0), (2, 1), width=0.1)
348-
assert str(p) == "YAArrow()"
348+
with pytest.warns(MatplotlibDeprecationWarning):
349+
p = mpatches.YAArrow(plt.gcf(), (1, 0), (2, 1), width=0.1)
350+
assert str(p) == "YAArrow()"
349351

350352
# Not testing Arrow, FancyArrow here
351353
# because they seem to exist only for historical reasons.

lib/matplotlib/tests/test_rcparams.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pytest
1111

1212
import matplotlib as mpl
13+
from matplotlib.cbook import MatplotlibDeprecationWarning
1314
import matplotlib.pyplot as plt
1415
import matplotlib.colors as mcolors
1516
import numpy as np
@@ -120,8 +121,7 @@ def test_Bug_2543():
120121
# printed in the test suite.
121122
with warnings.catch_warnings():
122123
warnings.filterwarnings('ignore',
123-
message='.*(deprecated|obsolete)',
124-
category=UserWarning)
124+
category=MatplotlibDeprecationWarning)
125125
with mpl.rc_context():
126126
_copy = mpl.rcParams.copy()
127127
for key in _copy:

0 commit comments

Comments
 (0)