Skip to content

Remove more API deprecated in 3.1(part 7) #16778

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

Merged
merged 1 commit into from
Mar 23, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions doc/api/next_api_changes/removals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()``
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
~~~~~~~~
Expand Down
8 changes: 4 additions & 4 deletions doc/api/prev_api_changes/api_changes_3.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 3 additions & 10 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
28 changes: 1 addition & 27 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.

Expand All @@ -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:
Expand Down
82 changes: 0 additions & 82 deletions lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/pylab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions lib/matplotlib/tests/test_cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 2 additions & 9 deletions lib/mpl_toolkits/mplot3d/art3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down