From 359de9f4945f26b8e5b3afd3571b35fa9d3bdbbd Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Mon, 23 Nov 2015 20:10:34 -0500 Subject: [PATCH 1/2] DEP: remove vmin/vmax from ContourSet These are unused public attributes which were flagged to be removed in 2012 in 9cba6fb3a7aa83d5276eb208edfa82480bb4fa89 by @efiring. --- lib/matplotlib/contour.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/contour.py b/lib/matplotlib/contour.py index cfb19bf95001..5416d58932fc 100644 --- a/lib/matplotlib/contour.py +++ b/lib/matplotlib/contour.py @@ -27,6 +27,7 @@ import matplotlib.patches as mpatches import matplotlib.texmanager as texmanager import matplotlib.transforms as mtrans +from matplotlib.cbook import mplDeprecation # Import needed for adding manual selection capability to clabel from matplotlib.blocking_input import BlockingContourLabeler @@ -1198,6 +1199,20 @@ def _contour_level_args(self, z, args): else: raise ValueError("Contour levels must be increasing") + @property + def vmin(self): + warnings.warn("vmin is deprecated and will be removed in 2.2 " + "and not replaced.", + mplDeprecation) + return getattr(self, '_vmin', None) + + @property + def vmax(self): + warnings.warn("vmax is deprecated and will be removed in 2.2 " + "and not replaced.", + mplDeprecation) + return getattr(self, '_vmax', None) + def _process_levels(self): """ Assign values to :attr:`layers` based on :attr:`levels`, @@ -1207,10 +1222,9 @@ def _process_levels(self): a line is a thin layer. No extended levels are needed with line contours. """ - # The following attributes are no longer needed, and - # should be deprecated and removed to reduce confusion. - self.vmin = np.amin(self.levels) - self.vmax = np.amax(self.levels) + # following are deprecated and will be removed in 2.2 + self._vmin = np.amin(self.levels) + self._vmax = np.amax(self.levels) # Make a private _levels to include extended regions; we # want to leave the original levels attribute unchanged. From 4c8205f001528382c7861eeb0b3db5a34f38a0ff Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Mon, 23 Nov 2015 21:45:52 -0500 Subject: [PATCH 2/2] TST: ContourSet vmin/vmax deprecation warnings --- lib/matplotlib/tests/test_contour.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/matplotlib/tests/test_contour.py b/lib/matplotlib/tests/test_contour.py index d9af79353d64..2c4383495500 100644 --- a/lib/matplotlib/tests/test_contour.py +++ b/lib/matplotlib/tests/test_contour.py @@ -279,6 +279,25 @@ def test_contourf_decreasing_levels(): assert_equal(len(w), 2) +@cleanup +def test_vminvmax_warning(): + z = [[0.1, 0.3], [0.5, 0.7]] + plt.figure() + cs = plt.contourf(z, [0.0, 1.0]) + + with warnings.catch_warnings(record=True) as w: + cs.vmin + assert len(w) == 1 + assert (str(w[0].message).startswith( + ("vmin is deprecated and will be removed in 2.2 "))) + + with warnings.catch_warnings(record=True) as w: + cs.vmax + assert len(w) == 1 + assert (str(w[0].message).startswith( + ("vmax is deprecated and will be removed in 2.2 "))) + + if __name__ == '__main__': import nose nose.runmodule(argv=['-s', '--with-doctest'], exit=False)