From 08dc21b038e43401652fed765288bb669abb8b0c Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Sun, 15 Mar 2020 17:29:04 +0100 Subject: [PATCH] Remove more API deprecated in 3.1 --- doc/api/next_api_changes/removals.rst | 22 ++++- .../prev_api_changes/api_changes_3.1.0.rst | 8 +- lib/matplotlib/__init__.py | 3 +- lib/matplotlib/axes/_base.py | 13 +-- lib/matplotlib/axis.py | 28 +------ lib/matplotlib/cbook/__init__.py | 82 ------------------- lib/matplotlib/pylab.py | 2 +- lib/matplotlib/pyplot.py | 1 - lib/matplotlib/tests/test_cbook.py | 8 -- lib/mpl_toolkits/mplot3d/art3d.py | 11 +-- 10 files changed, 32 insertions(+), 146 deletions(-) diff --git a/doc/api/next_api_changes/removals.rst b/doc/api/next_api_changes/removals.rst index 24da01c0e715..780fd9821e05 100644 --- a/doc/api/next_api_changes/removals.rst +++ b/doc/api/next_api_changes/removals.rst @@ -7,8 +7,8 @@ Modules - ``backends.qt_editor.formlayout`` (use the formlayout module available on PyPI instead). -Classes and methods -~~~~~~~~~~~~~~~~~~~ +Classes, methods and attributes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ``backend_bases.RendererBase.strip_math()`` (use ``cbook.strip_math()`` instead) @@ -39,6 +39,13 @@ Classes and methods - ``backend_qt5.NavigationToolbar2QT.buttons`` property (no replacement) - ``backend_qt5.NavigationToolbar2QT.adj_window`` property (no replacement) +- ``cbook.dedent()`` (use `inspect.cleandoc` instead) +- ``cbook.get_label()`` (no replacement) +- ``cbook.is_hashable()`` (use ``isinstance(..., collections.abc.Hashable)`` + instead) +- ``cbook.iterable()`` (use ``numpy.iterable()`` instead) +- ``cbook.safezip()`` (no replacement) + - ``docstring.Appender`` (no replacement) - ``docstring.dedent()`` (use `inspect.getdoc` instead) - ``docstring.copy_dedent()`` @@ -78,6 +85,10 @@ Classes and methods - ``ticker.LogFormatter.pprint_val()`` (no replacement) - ``ticker.decade_down()`` (no replacement) - ``ticker.decade_up()`` (no replacement) +- ``Tick`` properties ``gridOn``, ``tick1On``, ``tick2On``, ``label1On``, + ``label2On`` (use ``set_visible()`` / ``get_visible()`` on ``Tick.gridline``, + ``Tick.tick1line``, ``Tick.tick2line``, ``Tick.label1``, ``Tick.label2`` + instead) - ``Artist.aname`` property (no replacement) - ``Axis.iter_ticks`` (no replacement) @@ -169,6 +180,13 @@ Arguments - The ``s`` parameter of `.Annotation` has been renamed to ``text``. - For all functions in `.bezier` that supported a ``tolerence`` parameter, this parameter has been renamed to ``tolerance``. +- ``axis("normal")`` is not supported anymore. Use the equivalent + ``axis("auto")`` instead. +- ``axis()`` does not accept arbitrary keyword arguments anymore. +- ``Axis.set_ticklabels()`` does not accept arbitrary positional arguments + other than ``ticklabels``. +- ``mpl_toolkits.mplot3d.art3d.Poly3DCollection.set_zsort`` does not accept + the value ``True`` anymore. Pass the equivalent value 'average' instead. rcParams ~~~~~~~~ diff --git a/doc/api/prev_api_changes/api_changes_3.1.0.rst b/doc/api/prev_api_changes/api_changes_3.1.0.rst index 9c116088e11b..88c8ce751951 100644 --- a/doc/api/prev_api_changes/api_changes_3.1.0.rst +++ b/doc/api/prev_api_changes/api_changes_3.1.0.rst @@ -860,11 +860,11 @@ future version. - ``backend_ps.PsBackendHelper`` - ``backend_ps.ps_backend_helper``, -- `.cbook.iterable` -- `.cbook.get_label` -- `.cbook.safezip` +- ``cbook.iterable`` +- ``cbook.get_label`` +- ``cbook.safezip`` Manually check the lengths of the inputs instead, or rely on NumPy to do it. -- `.cbook.is_hashable` +- ``cbook.is_hashable`` Use ``isinstance(..., collections.abc.Hashable)`` instead. - The ``.backend_bases.RendererBase.strip_math``. Use diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index b9f4cafc6c7e..3a437f2bf1c3 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -105,8 +105,7 @@ # cbook must import matplotlib only within function # definitions, so it is safe to import from it here. from . import cbook, rcsetup -from matplotlib.cbook import ( - MatplotlibDeprecationWarning, dedent, get_label, sanitize_sequence) +from matplotlib.cbook import MatplotlibDeprecationWarning, sanitize_sequence from matplotlib.cbook import mplDeprecation # deprecated from matplotlib.rcsetup import defaultParams, validate_backend, cycler diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 109e2a5b1c03..cf91d4a3019a 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -1657,7 +1657,6 @@ def axis(self, *args, emit=True, **kwargs): 'tight' Set limits just large enough to show all data, then disable further autoscaling. 'auto' Automatic scaling (fill plot box with data). - 'normal' Same as 'auto'; deprecated. 'image' 'scaled' with axis limits equal to data limits. 'square' Square plot; similar to 'scaled', but initially forcing ``xmax-xmin == ymax-ymin``. @@ -1689,12 +1688,7 @@ def axis(self, *args, emit=True, **kwargs): self.set_axis_on() elif s == 'off': self.set_axis_off() - elif s in ('equal', 'tight', 'scaled', 'normal', - 'auto', 'image', 'square'): - if s == 'normal': - cbook.warn_deprecated( - "3.1", message="Passing 'normal' to axis() is " - "deprecated since %(since)s; use 'auto' instead.") + elif s in ('equal', 'tight', 'scaled', 'auto', 'image', 'square'): self.set_autoscale_on(True) self.set_aspect('auto') self.autoscale_view(tight=False) @@ -1752,9 +1746,8 @@ def axis(self, *args, emit=True, **kwargs): self.set_xlim(xmin, xmax, emit=emit, auto=xauto) self.set_ylim(ymin, ymax, emit=emit, auto=yauto) if kwargs: - cbook.warn_deprecated( - "3.1", message="Passing unsupported keyword arguments to " - "axis() will raise a TypeError %(removal)s.") + raise TypeError(f"axis() got an unexpected keyword argument " + f"'{next(iter(kwargs))}'") return (*self.get_xlim(), *self.get_ylim()) def get_legend(self): diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index ca1b3c5d762a..16953d7c2458 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -186,27 +186,6 @@ def __init__(self, axes, loc, label=None, self.update_position(loc) - for _old_name, _new_name in [ - ("gridOn", "gridline"), - ("tick1On", "tick1line"), - ("tick2On", "tick2line"), - ("label1On", "label1"), - ("label2On", "label2")]: - locals()[_old_name] = property( - cbook.deprecated( - "3.1", - name=_old_name, - alternative="Tick.{}.get_visible".format(_new_name))( - lambda self, _new_name=_new_name: - getattr(self, _new_name).get_visible()), - cbook.deprecated( - "3.1", - name=_old_name, - alternative="Tick.{}.set_visible".format(_new_name))( - lambda self, value, _new_name=_new_name: - getattr(self, _new_name).set_visible(value))) - del _old_name, _new_name - @property @cbook.deprecated("3.1", alternative="Tick.label1", pending=True) def label(self): @@ -1605,7 +1584,7 @@ def set_pickradius(self, pickradius): """ self.pickradius = pickradius - def set_ticklabels(self, ticklabels, *args, minor=False, **kwargs): + def set_ticklabels(self, ticklabels, *, minor=False, **kwargs): r""" Set the text values of the tick labels. @@ -1630,11 +1609,6 @@ def set_ticklabels(self, ticklabels, *args, minor=False, **kwargs): For each tick, includes ``tick.label1`` if it is visible, then ``tick.label2`` if it is visible, in that order. """ - if args: - cbook.warn_deprecated( - "3.1", message="Additional positional arguments to " - "set_ticklabels are ignored, and deprecated since Matplotlib " - "3.1; passing them will raise a TypeError in Matplotlib 3.3.") ticklabels = [t.get_text() if hasattr(t, 'get_text') else t for t in ticklabels] if minor: diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index c51681835645..0278d26c62a4 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -352,26 +352,6 @@ def strip_math(s): return s -@deprecated('3.1', alternative='np.iterable') -def iterable(obj): - """return true if *obj* is iterable""" - try: - iter(obj) - except TypeError: - return False - return True - - -@deprecated("3.1", alternative="isinstance(..., collections.abc.Hashable)") -def is_hashable(obj): - """Returns true if *obj* can be hashed""" - try: - hash(obj) - except TypeError: - return False - return True - - def is_writable_file_like(obj): """Return whether *obj* looks like a file object with a *write* method.""" return callable(getattr(obj, 'write', None)) @@ -535,47 +515,6 @@ def get_realpath_and_stat(path): _dedent_regex = {} -@deprecated("3.1", alternative="inspect.cleandoc") -def dedent(s): - """ - Remove excess indentation from docstring *s*. - - Discards any leading blank lines, then removes up to n whitespace - characters from each line, where n is the number of leading - whitespace characters in the first line. It differs from - textwrap.dedent in its deletion of leading blank lines and its use - of the first non-blank line to determine the indentation. - - It is also faster in most cases. - """ - # This implementation has a somewhat obtuse use of regular - # expressions. However, this function accounted for almost 30% of - # matplotlib startup time, so it is worthy of optimization at all - # costs. - - if not s: # includes case of s is None - return '' - - match = _find_dedent_regex.match(s) - if match is None: - return s - - # This is the number of spaces to remove from the left-hand side. - nshift = match.end(1) - match.start(1) - if nshift == 0: - return s - - # Get a regex that will remove *up to* nshift spaces from the - # beginning of each line. If it isn't in the cache, generate it. - unindent = _dedent_regex.get(nshift, None) - if unindent is None: - unindent = re.compile("\n\r? {0,%d}" % nshift) - _dedent_regex[nshift] = unindent - - result = unindent.sub("\n", s).strip() - return result - - class maxdict(dict): """ A dictionary with a maximum size. @@ -735,19 +674,6 @@ def call(command, os_name): return mem -_safezip_msg = 'In safezip, len(args[0])=%d but len(args[%d])=%d' - - -@deprecated("3.1") -def safezip(*args): - """make sure *args* are equal len before zipping""" - Nx = len(args[0]) - for i, arg in enumerate(args[1:]): - if len(arg) != Nx: - raise ValueError(_safezip_msg % (Nx, i + 1, len(arg))) - return list(zip(*args)) - - def safe_masked_invalid(x, copy=False): x = np.array(x, subok=True, copy=copy) if not x.dtype.isnative: @@ -1819,14 +1745,6 @@ def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(), return ret -@deprecated("3.1") -def get_label(y, default_name): - try: - return y.name - except AttributeError: - return default_name - - @contextlib.contextmanager def _lock_path(path): """ diff --git a/lib/matplotlib/pylab.py b/lib/matplotlib/pylab.py index fddf382ec775..79a0c2c7668c 100644 --- a/lib/matplotlib/pylab.py +++ b/lib/matplotlib/pylab.py @@ -11,7 +11,7 @@ considered bad style nowadays. """ -from matplotlib.cbook import flatten, silent_list, iterable, dedent +from matplotlib.cbook import flatten, silent_list import matplotlib as mpl diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index bce356516fdd..44f0ca465145 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -38,7 +38,6 @@ from matplotlib import rcsetup, style from matplotlib import _pylab_helpers, interactive from matplotlib import cbook -from matplotlib.cbook import dedent, deprecated, silent_list, warn_deprecated from matplotlib import docstring from matplotlib.backend_bases import FigureCanvasBase, MouseButton from matplotlib.figure import Figure, figaspect diff --git a/lib/matplotlib/tests/test_cbook.py b/lib/matplotlib/tests/test_cbook.py index fd759c11cf0d..e5ae03a4f530 100644 --- a/lib/matplotlib/tests/test_cbook.py +++ b/lib/matplotlib/tests/test_cbook.py @@ -15,14 +15,6 @@ from matplotlib.cbook import MatplotlibDeprecationWarning, delete_masked_points -def test_is_hashable(): - with pytest.warns(MatplotlibDeprecationWarning): - s = 'string' - assert cbook.is_hashable(s) - lst = ['list', 'of', 'stings'] - assert not cbook.is_hashable(lst) - - class Test_delete_masked_points: def test_bad_first_arg(self): with pytest.raises(ValueError): diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index 206641e5814f..226bb04e84b9 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -12,7 +12,7 @@ import numpy as np from matplotlib import ( - artist, cbook, colors as mcolors, lines, text as mtext, path as mpath) + artist, colors as mcolors, lines, text as mtext, path as mpath) from matplotlib.collections import ( LineCollection, PolyCollection, PatchCollection, PathCollection) from matplotlib.colors import Normalize @@ -584,15 +584,8 @@ def set_zsort(self, zsort): ---------- zsort : {'average', 'min', 'max'} The function applied on the z-coordinates of the vertices in the - viewer's coordinate system, to determine the z-order. *True* is - deprecated and equivalent to 'average'. + viewer's coordinate system, to determine the z-order. """ - if zsort is True: - cbook.warn_deprecated( - "3.1", message="Passing True to mean 'average' for set_zsort " - "is deprecated and support will be removed in Matplotlib 3.3; " - "pass 'average' instead.") - zsort = 'average' self._zsortfunc = self._zsort_functions[zsort] self._sort_zpos = None self.stale = True
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: