Skip to content

MNT: Removing 3.4 deprecations #23093

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 11 commits into from
May 24, 2022
50 changes: 50 additions & 0 deletions doc/api/next_api_changes/removals/23093-GL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Get/set window title methods have been removed from the canvas
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Use the corresponding methods on the FigureManager if using pyplot,
or GUI-specific methods if embedding.

``ContourLabeler.get_label_coords()`` has been removed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

There is no replacement, it was considered an internal helper.

The **return_all** keyword argument has been removed from ``gridspec.get_position()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The **minimum_descent** has been removed from ``TextArea``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The minimum_descent is now effectively always True.

Extra parameters to Axes constructor
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Parameters of the Axes constructor other than *fig* and *rect* are now keyword only.

``sphinext.plot_directive.align`` has been removed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Use ``docutils.parsers.rst.directives.images.Image.align`` instead.

``imread()`` no longer accepts URLs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Passing a URL to `~.pyplot.imread()` has been removed. Please open the URL for
reading and directly use the Pillow API
(``PIL.Image.open(urllib.request.urlopen(url))``, or
``PIL.Image.open(io.BytesIO(requests.get(url).content))``) instead.

Deprecated properties of widgets have been removed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

These include ``cids``, ``cnt``, ``observers``, ``change_observers``,
and ``submit_observers``.

Removal of methods and properties of ``Subplot``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

These include ``get_geometry()``, ``change_geometry()``, ``figbox``,
``numRows``, ``numCols``, ``update_params()``, ``is_first_row()``,
``is_first_col()``, ``is_last_row()``, ``is_last_col()``. The subplotspec
contains this information and can be used to replace these methods and properties.
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,8 @@ def __str__(self):
return "{0}({1[0]:g},{1[1]:g};{1[2]:g}x{1[3]:g})".format(
type(self).__name__, self._position.bounds)

@_api.make_keyword_only("3.4", "facecolor")
def __init__(self, fig, rect,
*,
facecolor=None, # defaults to rc axes.facecolor
frameon=True,
sharex=None, # use Axes instance's xaxis info
Expand Down
58 changes: 2 additions & 56 deletions lib/matplotlib/axes/_subplots.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import matplotlib as mpl
from matplotlib import _api, cbook
from matplotlib import cbook
from matplotlib.axes._axes import Axes
from matplotlib.gridspec import GridSpec, SubplotSpec
from matplotlib.gridspec import SubplotSpec


class SubplotBase:
Expand Down Expand Up @@ -35,22 +35,6 @@ def __init__(self, fig, *args, **kwargs):
# This will also update the axes position.
self.set_subplotspec(SubplotSpec._from_subplot_args(fig, args))

@_api.deprecated(
"3.4", alternative="get_subplotspec",
addendum="(get_subplotspec returns a SubplotSpec instance.)")
def get_geometry(self):
"""Get the subplot geometry, e.g., (2, 2, 3)."""
rows, cols, num1, num2 = self.get_subplotspec().get_geometry()
return rows, cols, num1 + 1 # for compatibility

@_api.deprecated("3.4", alternative="set_subplotspec")
def change_geometry(self, numrows, numcols, num):
"""Change subplot geometry, e.g., from (1, 1, 1) to (2, 2, 3)."""
self._subplotspec = GridSpec(numrows, numcols,
figure=self.figure)[num - 1]
self.update_params()
self.set_position(self.figbox)

def get_subplotspec(self):
"""Return the `.SubplotSpec` instance associated with the subplot."""
return self._subplotspec
Expand All @@ -64,44 +48,6 @@ def get_gridspec(self):
"""Return the `.GridSpec` instance associated with the subplot."""
return self._subplotspec.get_gridspec()

@_api.deprecated(
"3.4", alternative="get_position()")
@property
def figbox(self):
return self.get_position()

@_api.deprecated("3.4", alternative="get_gridspec().nrows")
@property
def numRows(self):
return self.get_gridspec().nrows

@_api.deprecated("3.4", alternative="get_gridspec().ncols")
@property
def numCols(self):
return self.get_gridspec().ncols

@_api.deprecated("3.4")
def update_params(self):
"""Update the subplot position from ``self.figure.subplotpars``."""
# Now a no-op, as figbox/numRows/numCols are (deprecated) auto-updating
# properties.

@_api.deprecated("3.4", alternative="ax.get_subplotspec().is_first_row()")
def is_first_row(self):
return self.get_subplotspec().rowspan.start == 0

@_api.deprecated("3.4", alternative="ax.get_subplotspec().is_last_row()")
def is_last_row(self):
return self.get_subplotspec().rowspan.stop == self.get_gridspec().nrows

@_api.deprecated("3.4", alternative="ax.get_subplotspec().is_first_col()")
def is_first_col(self):
return self.get_subplotspec().colspan.start == 0

@_api.deprecated("3.4", alternative="ax.get_subplotspec().is_last_col()")
def is_last_col(self):
return self.get_subplotspec().colspan.stop == self.get_gridspec().ncols

def label_outer(self):
"""
Only show "outer" labels and tick labels.
Expand Down
20 changes: 0 additions & 20 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2307,26 +2307,6 @@ def get_default_filetype(cls):
"""
return rcParams['savefig.format']

@_api.deprecated("3.4", alternative="`.FigureManagerBase.get_window_title`"
" or GUI-specific methods")
def get_window_title(self):
"""
Return the title text of the window containing the figure, or None
if there is no window (e.g., a PS backend).
"""
if self.manager is not None:
return self.manager.get_window_title()

@_api.deprecated("3.4", alternative="`.FigureManagerBase.set_window_title`"
" or GUI-specific methods")
def set_window_title(self, title):
"""
Set the title text of the window containing the figure. Note that
this has no effect if there is no window (e.g., a PS backend).
"""
if self.manager is not None:
self.manager.set_window_title(title)

def get_default_filename(self):
"""
Return a string, which includes extension, suitable for use as
Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ def __setstate__(self, state):
s: {proxy: cid for cid, proxy in d.items()}
for s, d in self.callbacks.items()}

@_api.rename_parameter("3.4", "s", "signal")
def connect(self, signal, func):
"""Register *func* to be called when signal *signal* is generated."""
if signal == "units finalize":
Expand Down
25 changes: 0 additions & 25 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,31 +248,6 @@ def too_close(self, x, y, lw):
return any((x - loc[0]) ** 2 + (y - loc[1]) ** 2 < thresh
for loc in self.labelXYs)

@_api.deprecated("3.4")
def get_label_coords(self, distances, XX, YY, ysize, lw):
"""
Return x, y, and the index of a label location.

Labels are plotted at a location with the smallest
deviation of the contour from a straight line
unless there is another label nearby, in which case
the next best place on the contour is picked up.
If all such candidates are rejected, the beginning
of the contour is chosen.
"""
hysize = int(ysize / 2)
adist = np.argsort(distances)

for ind in adist:
x, y = XX[ind][hysize], YY[ind][hysize]
if self.too_close(x, y, lw):
continue
return x, y, ind

ind = adist[0]
x, y = XX[ind][hysize], YY[ind][hysize]
return x, y, ind

def _get_nth_label_width(self, nth):
"""Return the width of the *nth* label, in pixels."""
fig = self.axes.figure
Expand Down
10 changes: 2 additions & 8 deletions lib/matplotlib/gridspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,7 @@ def is_first_col(self):
def is_last_col(self):
return self.colspan.stop == self.get_gridspec().ncols

@_api.delete_parameter("3.4", "return_all")
def get_position(self, figure, return_all=False):
def get_position(self, figure):
"""
Update the subplot position from ``figure.subplotpars``.
"""
Expand All @@ -679,12 +678,7 @@ def get_position(self, figure, return_all=False):
fig_top = fig_tops[rows].max()
fig_left = fig_lefts[cols].min()
fig_right = fig_rights[cols].max()
figbox = Bbox.from_extents(fig_left, fig_bottom, fig_right, fig_top)

if return_all:
return figbox, rows[0], cols[0], nrows, ncols
else:
return figbox
return Bbox.from_extents(fig_left, fig_bottom, fig_right, fig_top)

def get_topmost_subplotspec(self):
"""
Expand Down
30 changes: 7 additions & 23 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1526,29 +1526,13 @@ def imread(fname, format=None):
ext = format
img_open = (
PIL.PngImagePlugin.PngImageFile if ext == 'png' else PIL.Image.open)
if isinstance(fname, str):
parsed = parse.urlparse(fname)
if len(parsed.scheme) > 1: # Pillow doesn't handle URLs directly.
_api.warn_deprecated(
"3.4", message="Directly reading images from URLs is "
"deprecated since %(since)s and will no longer be supported "
"%(removal)s. Please open the URL for reading and pass the "
"result to Pillow, e.g. with "
"``np.array(PIL.Image.open(urllib.request.urlopen(url)))``.")
# hide imports to speed initial import on systems with slow linkers
from urllib import request
ssl_ctx = mpl._get_ssl_context()
if ssl_ctx is None:
_log.debug(
"Could not get certifi ssl context, https may not work."
)
with request.urlopen(fname, context=ssl_ctx) as response:
import io
try:
response.seek(0)
except (AttributeError, io.UnsupportedOperation):
response = io.BytesIO(response.read())
return imread(response, format=ext)
if isinstance(fname, str) and len(parse.urlparse(fname).scheme) > 1:
# Pillow doesn't handle URLs directly.
raise ValueError(
"Please open the URL for reading and pass the "
"result to Pillow, e.g. with "
"``np.array(PIL.Image.open(urllib.request.urlopen(url)))``."
)
with img_open(fname) as image:
return (_pil_png_to_float_array(image)
if isinstance(image, PIL.PngImagePlugin.PngImageFile) else
Expand Down
26 changes: 0 additions & 26 deletions lib/matplotlib/offsetbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,11 +688,9 @@ class TextArea(OffsetBox):
child text.
"""

@_api.delete_parameter("3.4", "minimumdescent")
def __init__(self, s,
textprops=None,
multilinebaseline=False,
minimumdescent=True,
):
"""
Parameters
Expand All @@ -705,9 +703,6 @@ def __init__(self, s,
multilinebaseline : bool, default: False
Whether the baseline for multiline text is adjusted so that it
is (approximately) center-aligned with single-line text.
minimumdescent : bool, default: True
If `True`, the box has a minimum descent of "p". This is now
effectively always True.
"""
if textprops is None:
textprops = {}
Expand All @@ -719,7 +714,6 @@ def __init__(self, s,
self._text.set_transform(self.offset_transform +
self._baseline_transform)
self._multilinebaseline = multilinebaseline
self._minimumdescent = minimumdescent

def set_text(self, s):
"""Set the text of this area as a string."""
Expand Down Expand Up @@ -748,26 +742,6 @@ def get_multilinebaseline(self):
"""
return self._multilinebaseline

@_api.deprecated("3.4")
def set_minimumdescent(self, t):
"""
Set minimumdescent.

If True, extent of the single line text is adjusted so that
its descent is at least the one of the glyph "p".
"""
# The current implementation of Text._get_layout always behaves as if
# this is True.
self._minimumdescent = t
self.stale = True

@_api.deprecated("3.4")
def get_minimumdescent(self):
"""
Get minimumdescent.
"""
return self._minimumdescent

def set_transform(self, t):
"""
set_transform is ignored.
Expand Down
3 changes: 0 additions & 3 deletions lib/matplotlib/sphinxext/plot_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@
from matplotlib import _api, _pylab_helpers, cbook

matplotlib.use("agg")
align = _api.deprecated(
"3.4", alternative="docutils.parsers.rst.directives.images.Image.align")(
Image.align)

__version__ = 2

Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def pytest_configure(config):
"style: Set alternate Matplotlib style temporarily (deprecated)."),
("markers", "baseline_images: Compare output against references."),
("markers", "pytz: Tests that require pytz to be installed."),
("markers", "network: Tests that reach out to the network."),
("filterwarnings", "error"),
("filterwarnings",
"ignore:.*The py23 module has been deprecated:DeprecationWarning"),
Expand Down
11 changes: 2 additions & 9 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import matplotlib as mpl
from matplotlib import (
_api, colors, image as mimage, patches, pyplot as plt, style, rcParams)
colors, image as mimage, patches, pyplot as plt, style, rcParams)
from matplotlib.image import (AxesImage, BboxImage, FigureImage,
NonUniformImage, PcolorImage)
from matplotlib.testing.decorators import check_figures_equal, image_comparison
Expand Down Expand Up @@ -720,7 +720,7 @@ def test_load_from_url():
url = ('file:'
+ ('///' if sys.platform == 'win32' else '')
+ path.resolve().as_posix())
with _api.suppress_matplotlib_deprecation_warning():
with pytest.raises(ValueError, match="Please open the URL"):
plt.imread(url)
with urllib.request.urlopen(url) as file:
plt.imread(file)
Expand Down Expand Up @@ -1139,13 +1139,6 @@ def test_exact_vmin():
assert np.all(from_image == direct_computation)


@pytest.mark.network
@pytest.mark.flaky
def test_https_imread_smoketest():
with _api.suppress_matplotlib_deprecation_warning():
v = mimage.imread('https://matplotlib.org/1.5.0/_static/logo2.png')


# A basic ndarray subclass that implements a quantity
# It does not implement an entire unit system or all quantity math.
# There is just enough implemented to test handling of ndarray
Expand Down
Loading