Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be a bit more stringent on invalid inputs. #12627

Merged
merged 1 commit into from Oct 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions 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.
4 changes: 1 addition & 3 deletions lib/matplotlib/backends/backend_cairo.py
Expand Up @@ -8,7 +8,6 @@

import copy
import gzip
import warnings

import numpy as np

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/cbook/deprecation.py
Expand Up @@ -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:
Expand Down
26 changes: 15 additions & 11 deletions lib/matplotlib/legend.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
23 changes: 10 additions & 13 deletions lib/matplotlib/offsetbox.py
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions lib/matplotlib/table.py
Expand Up @@ -17,9 +17,7 @@
Author : John Gill <jng@europe.renre.com>
Copyright : 2004 John Gill and John Hunter
License : matplotlib license

"""
import warnings

from . import artist, cbook, docstring
from .artist import Artist, allow_rasterization
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 5 additions & 9 deletions lib/matplotlib/ticker.py
Expand Up @@ -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:
Expand Down