diff --git a/doc/api/next_api_changes/2018-10-25-AL.rst b/doc/api/next_api_changes/2018-10-25-AL.rst new file mode 100644 index 000000000000..a121fb14ef0e --- /dev/null +++ b/doc/api/next_api_changes/2018-10-25-AL.rst @@ -0,0 +1,13 @@ +Invalid inputs +`````````````` + +Passing invalid locations to `legend` and `table` used to fallback on a default +location. This behavior is deprecated and will throw an exception in a future +version. + +`offsetbox.AnchoredText` is unable to handle the ``horizontalalignment`` or +``verticalalignment`` kwargs, and used to ignore them with a warning. This +behavior is deprecated and will throw an exception in a future version. + +Passing steps less than 1 or greater than 10 to `MaxNLocator` used to result in +undefined behavior. It now throws a ValueError. diff --git a/lib/matplotlib/backends/backend_cairo.py b/lib/matplotlib/backends/backend_cairo.py index ac6ae9c301aa..da2a21ac85b9 100644 --- a/lib/matplotlib/backends/backend_cairo.py +++ b/lib/matplotlib/backends/backend_cairo.py @@ -8,7 +8,6 @@ import copy import gzip -import warnings import numpy as np @@ -602,8 +601,7 @@ def _save(self, fo, fmt, **kwargs): fo = gzip.GzipFile(None, 'wb', fileobj=fo) surface = cairo.SVGSurface(fo, width_in_points, height_in_points) else: - warnings.warn("unknown format: %s" % fmt, stacklevel=2) - return + raise ValueError("Unknown format: {!r}".format(fmt)) # surface.set_dpi() can be used renderer = RendererCairo(self.figure.dpi) diff --git a/lib/matplotlib/cbook/deprecation.py b/lib/matplotlib/cbook/deprecation.py index 4a968242bda8..e18169fa2173 100644 --- a/lib/matplotlib/cbook/deprecation.py +++ b/lib/matplotlib/cbook/deprecation.py @@ -24,7 +24,7 @@ def _generate_deprecation_message( obj_type='attribute', addendum='', *, removal=''): if removal == "": - removal = {"2.2": "in 3.1", "3.0": "in 3.2"}.get( + removal = {"2.2": "in 3.1", "3.0": "in 3.2", "3.1": "in 3.3"}.get( since, "two minor releases later") elif removal: if pending: diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index 98d73f7b72e5..a9d13d7fce2b 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -27,7 +27,7 @@ import numpy as np from matplotlib import rcParams -from matplotlib import docstring +from matplotlib import cbook, docstring from matplotlib.artist import Artist, allow_rasterization from matplotlib.cbook import silent_list, is_hashable, warn_deprecated from matplotlib.font_manager import FontProperties @@ -491,22 +491,26 @@ def __init__(self, parent, handles, labels, if isinstance(loc, str): if loc not in self.codes: if self.isaxes: - warnings.warn('Unrecognized location "%s". Falling back ' - 'on "best"; valid locations are\n\t%s\n' - % (loc, '\n\t'.join(self.codes))) + cbook.warn_deprecated( + "3.1", message="Unrecognized location {!r}. Falling " + "back on 'best'; valid locations are\n\t{}\n" + "This will raise an exception %(removal)s." + .format(loc, '\n\t'.join(self.codes))) loc = 0 else: - warnings.warn('Unrecognized location "%s". Falling back ' - 'on "upper right"; ' - 'valid locations are\n\t%s\n' - % (loc, '\n\t'.join(self.codes))) + cbook.warn_deprecated( + "3.1", message="Unrecognized location {!r}. Falling " + "back on 'upper right'; valid locations are\n\t{}\n'" + "This will raise an exception %(removal)s." + .format(loc, '\n\t'.join(self.codes))) loc = 1 else: loc = self.codes[loc] if not self.isaxes and loc == 0: - warnings.warn('Automatic legend placement (loc="best") not ' - 'implemented for figure legend. ' - 'Falling back on "upper right".') + cbook.warn_deprecated( + "3.1", message="Automatic legend placement (loc='best') not " + "implemented for figure legend. Falling back on 'upper " + "right'. This will raise an exception %(removal)s.") loc = 1 self._mode = mode diff --git a/lib/matplotlib/offsetbox.py b/lib/matplotlib/offsetbox.py index 65208fe39b6a..9e693a6396c5 100644 --- a/lib/matplotlib/offsetbox.py +++ b/lib/matplotlib/offsetbox.py @@ -18,22 +18,17 @@ import numpy as np -import matplotlib.transforms as mtransforms +from matplotlib import cbook, docstring, rcParams import matplotlib.artist as martist -import matplotlib.text as mtext import matplotlib.path as mpath -from matplotlib.transforms import Bbox, BboxBase, TransformedBbox - +import matplotlib.text as mtext +import matplotlib.transforms as mtransforms from matplotlib.font_manager import FontProperties -from matplotlib.patches import FancyBboxPatch, FancyArrowPatch -from matplotlib import rcParams - -from matplotlib import docstring - from matplotlib.image import BboxImage - -from matplotlib.patches import bbox_artist as mbbox_artist +from matplotlib.patches import ( + FancyBboxPatch, FancyArrowPatch, bbox_artist as mbbox_artist) from matplotlib.text import _AnnotationBase +from matplotlib.transforms import Bbox, BboxBase, TransformedBbox DEBUG = False @@ -1249,8 +1244,10 @@ def __init__(self, s, loc, pad=0.4, borderpad=0.5, prop=None, **kwargs): prop = {} badkwargs = {'ha', 'horizontalalignment', 'va', 'verticalalignment'} if badkwargs & set(prop): - warnings.warn("Mixing horizontalalignment or verticalalignment " - "with AnchoredText is not supported.") + cbook.warn_deprecated( + "3.1", "Mixing horizontalalignment or verticalalignment with " + "AnchoredText is not supported, deprecated since %(version)s, " + "and will raise an exception %(removal)s.") self.txt = TextArea(s, textprops=prop, minimumdescent=False) fp = self.txt._text.get_fontproperties() diff --git a/lib/matplotlib/table.py b/lib/matplotlib/table.py index 885aa7b0cf06..758f2ef150d6 100644 --- a/lib/matplotlib/table.py +++ b/lib/matplotlib/table.py @@ -17,9 +17,7 @@ Author : John Gill Copyright : 2004 John Gill and John Hunter License : matplotlib license - """ -import warnings from . import artist, cbook, docstring from .artist import Artist, allow_rasterization @@ -243,9 +241,11 @@ def __init__(self, ax, loc=None, bbox=None, **kwargs): if isinstance(loc, str): if loc not in self.codes: - warnings.warn('Unrecognized location %s. Falling back on ' - 'bottom; valid locations are\n%s\t' % - (loc, '\n\t'.join(self.codes))) + cbook.warn_deprecated( + "3.1", message="Unrecognized location {!r}. Falling back " + "on 'bottom'; valid locations are\n\t{}\n" + "This will raise an exception %(removal)s." + .format(loc, '\n\t'.join(self.codes))) loc = 'bottom' loc = self.codes[loc] self.set_figure(ax.figure) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 88dd8a73a764..96ddf3279100 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -1878,16 +1878,12 @@ def __init__(self, *args, **kwargs): @staticmethod def _validate_steps(steps): if not np.iterable(steps): - raise ValueError('steps argument must be a sequence of numbers ' - 'from 1 to 10') + raise ValueError('steps argument must be an increasing sequence ' + 'of numbers between 1 and 10 inclusive') steps = np.asarray(steps) - if np.any(np.diff(steps) <= 0): - raise ValueError('steps argument must be uniformly increasing') - if steps[-1] > 10 or steps[0] < 1: - warnings.warn('Steps argument should be a sequence of numbers\n' - 'increasing from 1 to 10, inclusive. Behavior with\n' - 'values outside this range is undefined, and will\n' - 'raise a ValueError in future versions of mpl.') + if np.any(np.diff(steps) <= 0) or steps[-1] > 10 or steps[0] < 1: + raise ValueError('steps argument must be an increasing sequence ' + 'of numbers between 1 and 10 inclusive') if steps[0] != 1: steps = np.hstack((1, steps)) if steps[-1] != 10: