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

Skip to content

Commit 8ff23db

Browse files
committed
MNT: suppress RuntimeWarning for invalid float comparison in images
If do not warn for invalid values when looking for over/under pixels in _ImageBase._make_image. closes #7746
1 parent bffe631 commit 8ff23db

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/matplotlib/image.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,9 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
368368
# values to carry the over/under/bad information
369369
rgba = np.empty((A.shape[0], A.shape[1], 4), dtype=A.dtype)
370370
rgba[..., 0] = A # normalized data
371-
rgba[..., 1] = A < 0 # under data
372-
rgba[..., 2] = A > 1 # over data
371+
with np.errstate(invalid='ignore'):
372+
rgba[..., 1] = A < 0 # under data
373+
rgba[..., 2] = A > 1 # over data
373374
rgba[..., 3] = ~A.mask # bad data
374375
A = rgba
375376
output = np.zeros((out_height, out_width, 4),

lib/matplotlib/tests/test_image.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import six
55
import io
66
import os
7+
import warnings
78

89
from nose.plugins.attrib import attr
910

@@ -753,5 +754,12 @@ def test_imshow_endianess():
753754
ax2.imshow(Z.astype('>f8'), **kwargs)
754755

755756

757+
@cleanup
758+
def test_imshow_no_warn_invalid():
759+
with warnings.catch_warnings(record=True) as warns:
760+
plt.imshow([[1, 2], [3, np.nan]])
761+
assert len(warns) == 0
762+
763+
756764
if __name__ == '__main__':
757765
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
 (0)