Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e3446cb

Browse files
authored
Merge pull request #16778 from timhoffm/remove-3.1-deprecations7
Remove more API deprecated in 3.1(part 7)
2 parents 26054d4 + 08dc21b commit e3446cb

10 files changed

Lines changed: 32 additions & 146 deletions

File tree

doc/api/next_api_changes/removals.rst

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Modules
77
- ``backends.qt_editor.formlayout`` (use the formlayout module available on
88
PyPI instead).
99

10-
Classes and methods
11-
~~~~~~~~~~~~~~~~~~~
10+
Classes, methods and attributes
11+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1212
- ``backend_bases.RendererBase.strip_math()``
1313
(use ``cbook.strip_math()`` instead)
1414

@@ -39,6 +39,13 @@ Classes and methods
3939
- ``backend_qt5.NavigationToolbar2QT.buttons`` property (no replacement)
4040
- ``backend_qt5.NavigationToolbar2QT.adj_window`` property (no replacement)
4141

42+
- ``cbook.dedent()`` (use `inspect.cleandoc` instead)
43+
- ``cbook.get_label()`` (no replacement)
44+
- ``cbook.is_hashable()`` (use ``isinstance(..., collections.abc.Hashable)``
45+
instead)
46+
- ``cbook.iterable()`` (use ``numpy.iterable()`` instead)
47+
- ``cbook.safezip()`` (no replacement)
48+
4249
- ``docstring.Appender`` (no replacement)
4350
- ``docstring.dedent()`` (use `inspect.getdoc` instead)
4451
- ``docstring.copy_dedent()``
@@ -86,6 +93,10 @@ Classes and methods
8693
- ``ticker.LogFormatter.pprint_val()`` (no replacement)
8794
- ``ticker.decade_down()`` (no replacement)
8895
- ``ticker.decade_up()`` (no replacement)
96+
- ``Tick`` properties ``gridOn``, ``tick1On``, ``tick2On``, ``label1On``,
97+
``label2On`` (use ``set_visible()`` / ``get_visible()`` on ``Tick.gridline``,
98+
``Tick.tick1line``, ``Tick.tick2line``, ``Tick.label1``, ``Tick.label2``
99+
instead)
89100

90101
- ``Artist.aname`` property (no replacement)
91102
- ``Axis.iter_ticks`` (no replacement)
@@ -177,6 +188,13 @@ Arguments
177188
- The ``s`` parameter of `.Annotation` has been renamed to ``text``.
178189
- For all functions in `.bezier` that supported a ``tolerence`` parameter, this
179190
parameter has been renamed to ``tolerance``.
191+
- ``axis("normal")`` is not supported anymore. Use the equivalent
192+
``axis("auto")`` instead.
193+
- ``axis()`` does not accept arbitrary keyword arguments anymore.
194+
- ``Axis.set_ticklabels()`` does not accept arbitrary positional arguments
195+
other than ``ticklabels``.
196+
- ``mpl_toolkits.mplot3d.art3d.Poly3DCollection.set_zsort`` does not accept
197+
the value ``True`` anymore. Pass the equivalent value 'average' instead.
180198

181199
rcParams
182200
~~~~~~~~

doc/api/prev_api_changes/api_changes_3.1.0.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -860,11 +860,11 @@ future version.
860860
- ``backend_ps.PsBackendHelper``
861861
- ``backend_ps.ps_backend_helper``,
862862

863-
- `.cbook.iterable`
864-
- `.cbook.get_label`
865-
- `.cbook.safezip`
863+
- ``cbook.iterable``
864+
- ``cbook.get_label``
865+
- ``cbook.safezip``
866866
Manually check the lengths of the inputs instead, or rely on NumPy to do it.
867-
- `.cbook.is_hashable`
867+
- ``cbook.is_hashable``
868868
Use ``isinstance(..., collections.abc.Hashable)`` instead.
869869

870870
- The ``.backend_bases.RendererBase.strip_math``. Use

lib/matplotlib/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@
105105
# cbook must import matplotlib only within function
106106
# definitions, so it is safe to import from it here.
107107
from . import cbook, rcsetup
108-
from matplotlib.cbook import (
109-
MatplotlibDeprecationWarning, dedent, get_label, sanitize_sequence)
108+
from matplotlib.cbook import MatplotlibDeprecationWarning, sanitize_sequence
110109
from matplotlib.cbook import mplDeprecation # deprecated
111110
from matplotlib.rcsetup import defaultParams, validate_backend, cycler
112111

lib/matplotlib/axes/_base.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,6 @@ def axis(self, *args, emit=True, **kwargs):
16571657
'tight' Set limits just large enough to show all data, then
16581658
disable further autoscaling.
16591659
'auto' Automatic scaling (fill plot box with data).
1660-
'normal' Same as 'auto'; deprecated.
16611660
'image' 'scaled' with axis limits equal to data limits.
16621661
'square' Square plot; similar to 'scaled', but initially forcing
16631662
``xmax-xmin == ymax-ymin``.
@@ -1689,12 +1688,7 @@ def axis(self, *args, emit=True, **kwargs):
16891688
self.set_axis_on()
16901689
elif s == 'off':
16911690
self.set_axis_off()
1692-
elif s in ('equal', 'tight', 'scaled', 'normal',
1693-
'auto', 'image', 'square'):
1694-
if s == 'normal':
1695-
cbook.warn_deprecated(
1696-
"3.1", message="Passing 'normal' to axis() is "
1697-
"deprecated since %(since)s; use 'auto' instead.")
1691+
elif s in ('equal', 'tight', 'scaled', 'auto', 'image', 'square'):
16981692
self.set_autoscale_on(True)
16991693
self.set_aspect('auto')
17001694
self.autoscale_view(tight=False)
@@ -1752,9 +1746,8 @@ def axis(self, *args, emit=True, **kwargs):
17521746
self.set_xlim(xmin, xmax, emit=emit, auto=xauto)
17531747
self.set_ylim(ymin, ymax, emit=emit, auto=yauto)
17541748
if kwargs:
1755-
cbook.warn_deprecated(
1756-
"3.1", message="Passing unsupported keyword arguments to "
1757-
"axis() will raise a TypeError %(removal)s.")
1749+
raise TypeError(f"axis() got an unexpected keyword argument "
1750+
f"'{next(iter(kwargs))}'")
17581751
return (*self.get_xlim(), *self.get_ylim())
17591752

17601753
def get_legend(self):

lib/matplotlib/axis.py

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -186,27 +186,6 @@ def __init__(self, axes, loc, label=None,
186186

187187
self.update_position(loc)
188188

189-
for _old_name, _new_name in [
190-
("gridOn", "gridline"),
191-
("tick1On", "tick1line"),
192-
("tick2On", "tick2line"),
193-
("label1On", "label1"),
194-
("label2On", "label2")]:
195-
locals()[_old_name] = property(
196-
cbook.deprecated(
197-
"3.1",
198-
name=_old_name,
199-
alternative="Tick.{}.get_visible".format(_new_name))(
200-
lambda self, _new_name=_new_name:
201-
getattr(self, _new_name).get_visible()),
202-
cbook.deprecated(
203-
"3.1",
204-
name=_old_name,
205-
alternative="Tick.{}.set_visible".format(_new_name))(
206-
lambda self, value, _new_name=_new_name:
207-
getattr(self, _new_name).set_visible(value)))
208-
del _old_name, _new_name
209-
210189
@property
211190
@cbook.deprecated("3.1", alternative="Tick.label1", pending=True)
212191
def label(self):
@@ -1605,7 +1584,7 @@ def set_pickradius(self, pickradius):
16051584
"""
16061585
self.pickradius = pickradius
16071586

1608-
def set_ticklabels(self, ticklabels, *args, minor=False, **kwargs):
1587+
def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
16091588
r"""
16101589
Set the text values of the tick labels.
16111590
@@ -1630,11 +1609,6 @@ def set_ticklabels(self, ticklabels, *args, minor=False, **kwargs):
16301609
For each tick, includes ``tick.label1`` if it is visible, then
16311610
``tick.label2`` if it is visible, in that order.
16321611
"""
1633-
if args:
1634-
cbook.warn_deprecated(
1635-
"3.1", message="Additional positional arguments to "
1636-
"set_ticklabels are ignored, and deprecated since Matplotlib "
1637-
"3.1; passing them will raise a TypeError in Matplotlib 3.3.")
16381612
ticklabels = [t.get_text() if hasattr(t, 'get_text') else t
16391613
for t in ticklabels]
16401614
if minor:

lib/matplotlib/cbook/__init__.py

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -353,26 +353,6 @@ def strip_math(s):
353353
return s
354354

355355

356-
@deprecated('3.1', alternative='np.iterable')
357-
def iterable(obj):
358-
"""return true if *obj* is iterable"""
359-
try:
360-
iter(obj)
361-
except TypeError:
362-
return False
363-
return True
364-
365-
366-
@deprecated("3.1", alternative="isinstance(..., collections.abc.Hashable)")
367-
def is_hashable(obj):
368-
"""Returns true if *obj* can be hashed"""
369-
try:
370-
hash(obj)
371-
except TypeError:
372-
return False
373-
return True
374-
375-
376356
def is_writable_file_like(obj):
377357
"""Return whether *obj* looks like a file object with a *write* method."""
378358
return callable(getattr(obj, 'write', None))
@@ -536,47 +516,6 @@ def get_realpath_and_stat(path):
536516
_dedent_regex = {}
537517

538518

539-
@deprecated("3.1", alternative="inspect.cleandoc")
540-
def dedent(s):
541-
"""
542-
Remove excess indentation from docstring *s*.
543-
544-
Discards any leading blank lines, then removes up to n whitespace
545-
characters from each line, where n is the number of leading
546-
whitespace characters in the first line. It differs from
547-
textwrap.dedent in its deletion of leading blank lines and its use
548-
of the first non-blank line to determine the indentation.
549-
550-
It is also faster in most cases.
551-
"""
552-
# This implementation has a somewhat obtuse use of regular
553-
# expressions. However, this function accounted for almost 30% of
554-
# matplotlib startup time, so it is worthy of optimization at all
555-
# costs.
556-
557-
if not s: # includes case of s is None
558-
return ''
559-
560-
match = _find_dedent_regex.match(s)
561-
if match is None:
562-
return s
563-
564-
# This is the number of spaces to remove from the left-hand side.
565-
nshift = match.end(1) - match.start(1)
566-
if nshift == 0:
567-
return s
568-
569-
# Get a regex that will remove *up to* nshift spaces from the
570-
# beginning of each line. If it isn't in the cache, generate it.
571-
unindent = _dedent_regex.get(nshift, None)
572-
if unindent is None:
573-
unindent = re.compile("\n\r? {0,%d}" % nshift)
574-
_dedent_regex[nshift] = unindent
575-
576-
result = unindent.sub("\n", s).strip()
577-
return result
578-
579-
580519
class maxdict(dict):
581520
"""
582521
A dictionary with a maximum size.
@@ -736,19 +675,6 @@ def call(command, os_name):
736675
return mem
737676

738677

739-
_safezip_msg = 'In safezip, len(args[0])=%d but len(args[%d])=%d'
740-
741-
742-
@deprecated("3.1")
743-
def safezip(*args):
744-
"""make sure *args* are equal len before zipping"""
745-
Nx = len(args[0])
746-
for i, arg in enumerate(args[1:]):
747-
if len(arg) != Nx:
748-
raise ValueError(_safezip_msg % (Nx, i + 1, len(arg)))
749-
return list(zip(*args))
750-
751-
752678
def safe_masked_invalid(x, copy=False):
753679
x = np.array(x, subok=True, copy=copy)
754680
if not x.dtype.isnative:
@@ -1820,14 +1746,6 @@ def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(),
18201746
return ret
18211747

18221748

1823-
@deprecated("3.1")
1824-
def get_label(y, default_name):
1825-
try:
1826-
return y.name
1827-
except AttributeError:
1828-
return default_name
1829-
1830-
18311749
@contextlib.contextmanager
18321750
def _lock_path(path):
18331751
"""

lib/matplotlib/pylab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
considered bad style nowadays.
1212
"""
1313

14-
from matplotlib.cbook import flatten, silent_list, iterable, dedent
14+
from matplotlib.cbook import flatten, silent_list
1515

1616
import matplotlib as mpl
1717

lib/matplotlib/pyplot.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
from matplotlib import rcsetup, style
3939
from matplotlib import _pylab_helpers, interactive
4040
from matplotlib import cbook
41-
from matplotlib.cbook import dedent, deprecated, silent_list, warn_deprecated
4241
from matplotlib import docstring
4342
from matplotlib.backend_bases import FigureCanvasBase, MouseButton
4443
from matplotlib.figure import Figure, figaspect

lib/matplotlib/tests/test_cbook.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@
1515
from matplotlib.cbook import MatplotlibDeprecationWarning, delete_masked_points
1616

1717

18-
def test_is_hashable():
19-
with pytest.warns(MatplotlibDeprecationWarning):
20-
s = 'string'
21-
assert cbook.is_hashable(s)
22-
lst = ['list', 'of', 'stings']
23-
assert not cbook.is_hashable(lst)
24-
25-
2618
class Test_delete_masked_points:
2719
def test_bad_first_arg(self):
2820
with pytest.raises(ValueError):

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import numpy as np
1313

1414
from matplotlib import (
15-
artist, cbook, colors as mcolors, lines, text as mtext, path as mpath)
15+
artist, colors as mcolors, lines, text as mtext, path as mpath)
1616
from matplotlib.collections import (
1717
LineCollection, PolyCollection, PatchCollection, PathCollection)
1818
from matplotlib.colors import Normalize
@@ -584,15 +584,8 @@ def set_zsort(self, zsort):
584584
----------
585585
zsort : {'average', 'min', 'max'}
586586
The function applied on the z-coordinates of the vertices in the
587-
viewer's coordinate system, to determine the z-order. *True* is
588-
deprecated and equivalent to 'average'.
587+
viewer's coordinate system, to determine the z-order.
589588
"""
590-
if zsort is True:
591-
cbook.warn_deprecated(
592-
"3.1", message="Passing True to mean 'average' for set_zsort "
593-
"is deprecated and support will be removed in Matplotlib 3.3; "
594-
"pass 'average' instead.")
595-
zsort = 'average'
596589
self._zsortfunc = self._zsort_functions[zsort]
597590
self._sort_zpos = None
598591
self.stale = True

0 commit comments

Comments
 (0)