Skip to content

Commit 5f5a560

Browse files
committed
Remove remaining 3.8 deprecations
1 parent 8e73998 commit 5f5a560

15 files changed

+93
-105
lines changed

doc/api/next_api_changes/removals/28874-ES.rst

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,48 @@
1+
Passing extra positional arguments to ``Figure.add_axes``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Positional arguments passed to `.Figure.add_axes` other than a rect or an existing
5+
``Axes`` were previously ignored, and is now an error.
6+
7+
8+
Artists explicitly passed in will no longer be filtered by legend() based on their label
9+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10+
11+
Previously, artists explicitly passed to ``legend(handles=[...])`` are filtered out if
12+
their label starts with an underscore. This filter is no longer applied; explicitly
13+
filter out such artists (``[art for art in artists if not
14+
art.get_label().startswith('_')]``) if necessary.
15+
16+
Note that if no handles are specified at all, then the default still filters out labels
17+
starting with an underscore.
18+
19+
20+
The parameter of ``Annotation.contains`` and ``Legend.contains`` is renamed to *mouseevent*
21+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22+
23+
... consistently with `.Artist.contains`.
24+
25+
26+
Support for passing the "frac" key in ``annotate(..., arrowprops={"frac": ...})``
27+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28+
29+
... has been removed. This key has had no effect since Matplotlib 1.5.
30+
31+
32+
Passing non-int or sequence of non-int to ``Table.auto_set_column_width``
33+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34+
35+
Column numbers are ints, and formerly passing any other type was effectively ignored.
36+
This has now become an error.
37+
38+
39+
Widgets
40+
~~~~~~~
41+
42+
The *visible* attribute getter of ``*Selector`` widgets has been removed; use
43+
``get_visible`` instead.
44+
45+
146
Auto-closing of figures when switching backend
247
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
348

@@ -61,6 +106,13 @@ which should cover most use cases.
61106
... with no replacement.
62107

63108

109+
``TexManager.texcache``
110+
~~~~~~~~~~~~~~~~~~~~~~~
111+
112+
... is considered private and has been removed. The location of the cache directory is
113+
clarified in the doc-string.
114+
115+
64116
``cbook`` API changes
65117
~~~~~~~~~~~~~~~~~~~~~
66118

@@ -74,6 +126,25 @@ now auto-loads numpy arrays. Use ``get_sample_data(..., asfileobj=False)`` inste
74126
the filename of the data file, which can then be passed to `open`, if desired.
75127

76128

129+
Calling ``paths.get_path_collection_extents`` with empty *offsets*
130+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
131+
132+
Calling `~.get_path_collection_extents` with an empty *offsets* parameter has an
133+
ambiguous interpretation and is no longer allowed.
134+
135+
136+
``bbox.anchored()`` with no explicit container
137+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
138+
139+
Not passing a *container* argument to `.BboxBase.anchored` is no longer supported.
140+
141+
142+
``INVALID_NON_AFFINE``, ``INVALID_AFFINE``, ``INVALID`` attributes of ``TransformNode``
143+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144+
145+
These attributes have been removed.
146+
147+
77148
``axes_grid1`` API changes
78149
~~~~~~~~~~~~~~~~~~~~~~~~~~
79150

lib/matplotlib/figure.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -613,22 +613,22 @@ def add_axes(self, *args, **kwargs):
613613
"""
614614

615615
if not len(args) and 'rect' not in kwargs:
616-
raise TypeError(
617-
"add_axes() missing 1 required positional argument: 'rect'")
616+
raise TypeError("add_axes() missing 1 required positional argument: 'rect'")
618617
elif 'rect' in kwargs:
619618
if len(args):
620-
raise TypeError(
621-
"add_axes() got multiple values for argument 'rect'")
619+
raise TypeError("add_axes() got multiple values for argument 'rect'")
622620
args = (kwargs.pop('rect'), )
621+
if len(args) != 1:
622+
raise _api.nargs_error("add_axes", 1, len(args))
623623

624624
if isinstance(args[0], Axes):
625-
a, *extra_args = args
625+
a, = args
626626
key = a._projection_init
627627
if a.get_figure(root=False) is not self:
628628
raise ValueError(
629629
"The Axes must have been created in the present figure")
630630
else:
631-
rect, *extra_args = args
631+
rect, = args
632632
if not np.isfinite(rect).all():
633633
raise ValueError(f'all entries in rect must be finite not {rect}')
634634
projection_class, pkw = self._process_projection_requirements(**kwargs)
@@ -637,11 +637,6 @@ def add_axes(self, *args, **kwargs):
637637
a = projection_class(self, rect, **pkw)
638638
key = (projection_class, pkw)
639639

640-
if extra_args:
641-
_api.warn_deprecated(
642-
"3.8",
643-
name="Passing more than one positional argument to Figure.add_axes",
644-
addendum="Any additional positional arguments are currently ignored.")
645640
return self._add_axes_internal(a, key)
646641

647642
@_docstring.interpd

lib/matplotlib/legend.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -454,24 +454,10 @@ def __init__(
454454
self.borderaxespad = mpl._val_or_rc(borderaxespad, 'legend.borderaxespad')
455455
self.columnspacing = mpl._val_or_rc(columnspacing, 'legend.columnspacing')
456456
self.shadow = mpl._val_or_rc(shadow, 'legend.shadow')
457-
# trim handles and labels if illegal label...
458-
_lab, _hand = [], []
459-
for label, handle in zip(labels, handles):
460-
if isinstance(label, str) and label.startswith('_'):
461-
_api.warn_deprecated("3.8", message=(
462-
"An artist whose label starts with an underscore was passed to "
463-
"legend(); such artists will no longer be ignored in the future. "
464-
"To suppress this warning, explicitly filter out such artists, "
465-
"e.g. with `[art for art in artists if not "
466-
"art.get_label().startswith('_')]`."))
467-
else:
468-
_lab.append(label)
469-
_hand.append(handle)
470-
labels, handles = _lab, _hand
471457

472458
if reverse:
473-
labels.reverse()
474-
handles.reverse()
459+
labels = [*reversed(labels)]
460+
handles = [*reversed(handles)]
475461

476462
if len(handles) < 2:
477463
ncols = 1

lib/matplotlib/path.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,10 +1086,7 @@ def get_path_collection_extents(
10861086
if len(paths) == 0:
10871087
raise ValueError("No paths provided")
10881088
if len(offsets) == 0:
1089-
_api.warn_deprecated(
1090-
"3.8", message="Calling get_path_collection_extents() with an"
1091-
" empty offsets list is deprecated since %(since)s. Support will"
1092-
" be removed %(removal)s.")
1089+
raise ValueError("No offsets provided")
10931090
extents, minpos = _path.get_path_collection_extents(
10941091
master_transform, paths, np.atleast_3d(transforms),
10951092
offsets, offset_transform)

lib/matplotlib/table.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,7 @@ def auto_set_column_width(self, col):
496496
"""
497497
col1d = np.atleast_1d(col)
498498
if not np.issubdtype(col1d.dtype, np.integer):
499-
_api.warn_deprecated("3.8", name="col",
500-
message="%(name)r must be an int or sequence of ints. "
501-
"Passing other types is deprecated since %(since)s "
502-
"and will be removed %(removal)s.")
503-
return
499+
raise TypeError("col must be an int or sequence of ints.")
504500
for cell in col1d:
505501
self._autoColumns.append(cell)
506502

lib/matplotlib/tests/test_figure.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,12 +518,10 @@ def test_invalid_figure_add_axes():
518518
fig.add_axes(ax)
519519

520520
fig2.delaxes(ax)
521-
with pytest.warns(mpl.MatplotlibDeprecationWarning,
522-
match="Passing more than one positional argument"):
521+
with pytest.raises(TypeError, match=r"add_axes\(\) takes 1 positional arguments"):
523522
fig2.add_axes(ax, "extra positional argument")
524523

525-
with pytest.warns(mpl.MatplotlibDeprecationWarning,
526-
match="Passing more than one positional argument"):
524+
with pytest.raises(TypeError, match=r"add_axes\(\) takes 1 positional arguments"):
527525
fig.add_axes([0, 0, 1, 1], "extra positional argument")
528526

529527

lib/matplotlib/tests/test_legend.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import matplotlib.lines as mlines
2020
from matplotlib.legend_handler import HandlerTuple
2121
import matplotlib.legend as mlegend
22-
from matplotlib import _api, rc_context
22+
from matplotlib import rc_context
2323
from matplotlib.font_manager import FontProperties
2424

2525

@@ -138,19 +138,6 @@ def test_various_labels():
138138
ax.legend(numpoints=1, loc='best')
139139

140140

141-
def test_legend_label_with_leading_underscore():
142-
"""
143-
Test that artists with labels starting with an underscore are not added to
144-
the legend, and that a warning is issued if one tries to add them
145-
explicitly.
146-
"""
147-
fig, ax = plt.subplots()
148-
line, = ax.plot([0, 1], label='_foo')
149-
with pytest.warns(_api.MatplotlibDeprecationWarning, match="with an underscore"):
150-
legend = ax.legend(handles=[line])
151-
assert len(legend.legend_handles) == 0
152-
153-
154141
@image_comparison(['legend_labels_first.png'], remove_text=True,
155142
tol=0.013 if platform.machine() == 'arm64' else 0)
156143
def test_labels_first():

lib/matplotlib/tests/test_table.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
from unittest.mock import Mock
33

44
import numpy as np
5-
import pytest
65

76
import matplotlib.pyplot as plt
8-
import matplotlib as mpl
97
from matplotlib.path import Path
108
from matplotlib.table import CustomCell, Table
119
from matplotlib.testing.decorators import image_comparison, check_figures_equal
@@ -128,10 +126,9 @@ def test_customcell():
128126

129127
@image_comparison(['table_auto_column.png'])
130128
def test_auto_column():
131-
fig = plt.figure()
129+
fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1)
132130

133131
# iterable list input
134-
ax1 = fig.add_subplot(4, 1, 1)
135132
ax1.axis('off')
136133
tb1 = ax1.table(
137134
cellText=[['Fit Text', 2],
@@ -144,7 +141,6 @@ def test_auto_column():
144141
tb1.auto_set_column_width([-1, 0, 1])
145142

146143
# iterable tuple input
147-
ax2 = fig.add_subplot(4, 1, 2)
148144
ax2.axis('off')
149145
tb2 = ax2.table(
150146
cellText=[['Fit Text', 2],
@@ -157,7 +153,6 @@ def test_auto_column():
157153
tb2.auto_set_column_width((-1, 0, 1))
158154

159155
# 3 single inputs
160-
ax3 = fig.add_subplot(4, 1, 3)
161156
ax3.axis('off')
162157
tb3 = ax3.table(
163158
cellText=[['Fit Text', 2],
@@ -171,8 +166,8 @@ def test_auto_column():
171166
tb3.auto_set_column_width(0)
172167
tb3.auto_set_column_width(1)
173168

174-
# 4 non integer iterable input
175-
ax4 = fig.add_subplot(4, 1, 4)
169+
# 4 this used to test non-integer iterable input, which did nothing, but only
170+
# remains to avoid re-generating the test image.
176171
ax4.axis('off')
177172
tb4 = ax4.table(
178173
cellText=[['Fit Text', 2],
@@ -182,12 +177,6 @@ def test_auto_column():
182177
loc="center")
183178
tb4.auto_set_font_size(False)
184179
tb4.set_fontsize(12)
185-
with pytest.warns(mpl.MatplotlibDeprecationWarning,
186-
match="'col' must be an int or sequence of ints"):
187-
tb4.auto_set_column_width("-101") # type: ignore [arg-type]
188-
with pytest.warns(mpl.MatplotlibDeprecationWarning,
189-
match="'col' must be an int or sequence of ints"):
190-
tb4.auto_set_column_width(["-101"]) # type: ignore [list-item]
191180

192181

193182
def test_table_cells():

lib/matplotlib/tests/test_widgets.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import operator
44
from unittest import mock
55

6-
import matplotlib as mpl
76
from matplotlib.backend_bases import MouseEvent
87
import matplotlib.colors as mcolors
98
import matplotlib.widgets as widgets
@@ -131,16 +130,6 @@ def test_rectangle_minspan(ax, spancoords, minspanx, x1, minspany, y1):
131130
assert kwargs == {}
132131

133132

134-
def test_deprecation_selector_visible_attribute(ax):
135-
tool = widgets.RectangleSelector(ax)
136-
137-
assert tool.get_visible()
138-
139-
with pytest.warns(mpl.MatplotlibDeprecationWarning,
140-
match="was deprecated in Matplotlib 3.8"):
141-
tool.visible
142-
143-
144133
@pytest.mark.parametrize('drag_from_anywhere, new_center',
145134
[[True, (60, 75)],
146135
[False, (30, 20)]])

lib/matplotlib/texmanager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import numpy as np
3232

3333
import matplotlib as mpl
34-
from matplotlib import _api, cbook, dviread
34+
from matplotlib import cbook, dviread
3535

3636
_log = logging.getLogger(__name__)
3737

@@ -63,7 +63,6 @@ class TexManager:
6363
Repeated calls to this constructor always return the same instance.
6464
"""
6565

66-
texcache = _api.deprecate_privatize_attribute("3.8")
6766
_texcache = os.path.join(mpl.get_cachedir(), 'tex.cache')
6867
_grey_arrayd = {}
6968

lib/matplotlib/text.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,10 +1842,6 @@ def transform(renderer) -> Transform
18421842
# modified YAArrow API to be used with FancyArrowPatch
18431843
for key in ['width', 'headwidth', 'headlength', 'shrink']:
18441844
arrowprops.pop(key, None)
1845-
if 'frac' in arrowprops:
1846-
_api.warn_deprecated(
1847-
"3.8", name="the (unused) 'frac' key in 'arrowprops'")
1848-
arrowprops.pop("frac")
18491845
self.arrow_patch = FancyArrowPatch((0, 0), (1, 1), **arrowprops)
18501846
else:
18511847
self.arrow_patch = None

lib/matplotlib/transforms.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ class TransformNode:
9393
# Invalidation may affect only the affine part. If the
9494
# invalidation was "affine-only", the _invalid member is set to
9595
# INVALID_AFFINE_ONLY
96-
INVALID_NON_AFFINE = _api.deprecated("3.8")(_api.classproperty(lambda cls: 1))
97-
INVALID_AFFINE = _api.deprecated("3.8")(_api.classproperty(lambda cls: 2))
98-
INVALID = _api.deprecated("3.8")(_api.classproperty(lambda cls: 3))
9996

10097
# Possible values for the _invalid attribute.
10198
_VALID, _INVALID_AFFINE_ONLY, _INVALID_FULL = range(3)
@@ -480,7 +477,7 @@ def transformed(self, transform):
480477
'NW': (0, 1.0),
481478
'W': (0, 0.5)}
482479

483-
def anchored(self, c, container=None):
480+
def anchored(self, c, container):
484481
"""
485482
Return a copy of the `Bbox` anchored to *c* within *container*.
486483
@@ -490,19 +487,13 @@ def anchored(self, c, container=None):
490487
Either an (*x*, *y*) pair of relative coordinates (0 is left or
491488
bottom, 1 is right or top), 'C' (center), or a cardinal direction
492489
('SW', southwest, is bottom left, etc.).
493-
container : `Bbox`, optional
490+
container : `Bbox`
494491
The box within which the `Bbox` is positioned.
495492
496493
See Also
497494
--------
498495
.Axes.set_anchor
499496
"""
500-
if container is None:
501-
_api.warn_deprecated(
502-
"3.8", message="Calling anchored() with no container bbox "
503-
"returns a frozen copy of the original bbox and is deprecated "
504-
"since %(since)s.")
505-
container = self
506497
l, b, w, h = container.bounds
507498
L, B, W, H = self.bounds
508499
cx, cy = self.coefs[c] if isinstance(c, str) else c

lib/matplotlib/transforms.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ class BboxBase(TransformNode):
7777
def fully_overlaps(self, other: BboxBase) -> bool: ...
7878
def transformed(self, transform: Transform) -> Bbox: ...
7979
coefs: dict[str, tuple[float, float]]
80-
# anchored type can be s/str/Literal["C", "SW", "S", "SE", "E", "NE", "N", "NW", "W"]
8180
def anchored(
82-
self, c: tuple[float, float] | str, container: BboxBase | None = ...
81+
self,
82+
c: tuple[float, float] | Literal['C', 'SW', 'S', 'SE', 'E', 'NE', 'N', 'NW', 'W'],
83+
container: BboxBase,
8384
) -> Bbox: ...
8485
def shrunk(self, mx: float, my: float) -> Bbox: ...
8586
def shrunk_to_aspect(

0 commit comments

Comments
 (0)