Skip to content

Commit 08dc21b

Browse files
committed
Remove more API deprecated in 3.1
1 parent 1632a53 commit 08dc21b

File tree

10 files changed

+32
-146
lines changed

10 files changed

+32
-146
lines changed

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()``
@@ -78,6 +85,10 @@ Classes and methods
7885
- ``ticker.LogFormatter.pprint_val()`` (no replacement)
7986
- ``ticker.decade_down()`` (no replacement)
8087
- ``ticker.decade_up()`` (no replacement)
88+
- ``Tick`` properties ``gridOn``, ``tick1On``, ``tick2On``, ``label1On``,
89+
``label2On`` (use ``set_visible()`` / ``get_visible()`` on ``Tick.gridline``,
90+
``Tick.tick1line``, ``Tick.tick2line``, ``Tick.label1``, ``Tick.label2``
91+
instead)
8192

8293
- ``Artist.aname`` property (no replacement)
8394
- ``Axis.iter_ticks`` (no replacement)
@@ -169,6 +180,13 @@ Arguments
169180
- The ``s`` parameter of `.Annotation` has been renamed to ``text``.
170181
- For all functions in `.bezier` that supported a ``tolerence`` parameter, this
171182
parameter has been renamed to ``tolerance``.
183+
- ``axis("normal")`` is not supported anymore. Use the equivalent
184+
``axis("auto")`` instead.
185+
- ``axis()`` does not accept arbitrary keyword arguments anymore.
186+
- ``Axis.set_ticklabels()`` does not accept arbitrary positional arguments
187+
other than ``ticklabels``.
188+
- ``mpl_toolkits.mplot3d.art3d.Poly3DCollection.set_zsort`` does not accept
189+
the value ``True`` anymore. Pass the equivalent value 'average' instead.
172190

173191
rcParams
174192
~~~~~~~~

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
@@ -352,26 +352,6 @@ def strip_math(s):
352352
return s
353353

354354

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

537517

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

737676

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

18211747

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

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)