From 679d3ed897ee24d12a1038c212c2c296249444e4 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Tue, 10 Oct 2017 19:04:33 -0400 Subject: [PATCH] Backport PR #9335: Fix poorly done deprecations in image.py. --- lib/matplotlib/backends/qt_editor/figureoptions.py | 4 ++-- lib/matplotlib/image.py | 5 ++++- lib/matplotlib/tests/test_image.py | 8 ++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/backends/qt_editor/figureoptions.py b/lib/matplotlib/backends/qt_editor/figureoptions.py index af9feaf5e5c6..40572c8bd827 100644 --- a/lib/matplotlib/backends/qt_editor/figureoptions.py +++ b/lib/matplotlib/backends/qt_editor/figureoptions.py @@ -16,7 +16,7 @@ import re import matplotlib -from matplotlib import cm, markers, colors as mcolors +from matplotlib import cm, colors as mcolors, markers, image as mimage import matplotlib.backends.qt_editor.formlayout as formlayout from matplotlib.backends.qt_compat import QtGui @@ -165,7 +165,7 @@ def prepare_data(d, init): ('Max. value', high), ('Interpolation', [image.get_interpolation()] - + [(name, name) for name in sorted(image.iterpnames)])] + + [(name, name) for name in sorted(mimage.interpolations_names)])] images.append([imagedata, label, ""]) # Is there an image displayed? has_image = bool(images) diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index ea2331cb48a7..6b8477f63018 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -180,15 +180,18 @@ def _rgb_to_rgba(A): class _ImageBase(martist.Artist, cm.ScalarMappable): zorder = 0 + @property @cbook.deprecated("2.1") def _interpd(self): return _interpd_ + @property @cbook.deprecated("2.1") def _interpdr(self): return {v: k for k, v in six.iteritems(_interpd_)} - @cbook.deprecated("2.1") + @property + @cbook.deprecated("2.1", alternative="mpl.image.interpolation_names") def iterpnames(self): return interpolations_names diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 9f99fdc6ec8b..15c148f17cdb 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -827,3 +827,11 @@ def test_imshow_float128(): def test_imshow_bool(): fig, ax = plt.subplots() ax.imshow(np.array([[True, False], [False, True]], dtype=bool)) + + +def test_imshow_deprecated_interd_warn(): + im = plt.imshow([[1, 2], [3, np.nan]]) + for k in ('_interpd', '_interpdr', 'iterpnames'): + with warnings.catch_warnings(record=True) as warns: + getattr(im, k) + assert len(warns) == 1