8000 Expire QuadMesh old signature deprecation · matplotlib/matplotlib@8407301 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8407301

Browse files
committed
Expire QuadMesh old signature deprecation
1 parent 6c09a56 commit 8407301

File tree

3 files changed

+31
-110
lines changed

3 files changed

+31
-110
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
``QuadMesh`` signature
2+
~~~~~~~~~~~~~~~~~~~~~~
3+
4+
The `.QuadMesh` signature ::
5+
6+
def __init__(meshWidth, meshHeight, coordinates,
7+
antialiased=True, shading='flat', **kwargs)
8+
9+
is removed and replaced by the new signature ::
10+
11+
def __init__(coordinates, *, antialiased=True, shading='flat', **kwargs)
12+
13+
In particular:
14+
15+
- The *coordinates* argument must now be a (M, N, 2) array-like. Previously,
16+
the grid shape was separately specified as (*meshHeight* + 1, *meshWidth* +
17+
1) and *coordinates* could be an array-like of any shape with M * N * 2
18+
elements.
19+
- All parameters except *coordinates* are keyword-only now.

lib/matplotlib/collections.py

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
line segments).
1010
"""
1111

12-
import inspect
1312
import math
1413
from numbers import Number
1514
import warnings
@@ -1952,33 +1951,13 @@ class QuadMesh(Collection):
19521951
.. (0, meshWidth), (1, 0), (1, 1), and so on.
19531952
"""
19541953

1955-
def __init__(self, *args, **kwargs):
1956-
# signature deprecation since="3.5": Change to new signature after the
1957-
# deprecation has expired. Also remove setting __init__.__signature__,
1958-
# and remove the Notes from the docstring.
1959-
params = _api.select_matching_signature(
1960-
[
1961-
lambda meshWidth, meshHeight, coordinates, antialiased=True,
1962-
shading='flat', **kwargs: locals(),
1963-
lambda coordinates, antialiased=True, shading='flat', **kwargs:
1964-
locals()
1965-
],
1966-
*args, **kwargs).values()
1967-
*old_w_h, coords, antialiased, shading, kwargs = params
1968-
if old_w_h: # The old signature matched.
1969-
_api.warn_deprecated(
1970-
"3.5",
1971-
message="This usage of Quadmesh is deprecated: Parameters "
1972-
"meshWidth and meshHeights will be removed; "
1973-
"coordinates must be 2D; all parameters except "
1974-
"coordinates will be keyword-only.")
1975-
w, h = old_w_h
1976-
coords = np.asarray(coords, np.float64).reshape((h + 1, w + 1, 2))
1954+
def __init__(self, coordinates, *, antialiased=True, shading='flat',
1955+
**kwargs):
19771956
kwargs.setdefault("pickradius", 0)
19781957
# end of signature deprecation code
19791958

1980-
_api.check_shape((None, None, 2), coordinates=coords)
1981-
self._coordinates = coords
1959+
_api.check_shape((None, None, 2), coordinates=coordinates)
1960+
self._coordinates = coordinates
19821961
self._antialiased = antialiased
19831962
self._shading = shading
19841963
self._bbox = transforms.Bbox.unit()
@@ -1988,11 +1967,6 @@ def __init__(self, *args, **kwargs):
19881967
super().__init__(**kwargs)
19891968
self.set_mouseover(False)
19901969

1991-
# Only needed during signature deprecation
1992-
__init__.__signature__ = inspect.signature(
1993-
lambda self, coordinates, *,
1994-
antialiased=True, shading='flat', pickradius=0, **kwargs: None)
1995-
19961970
def get_paths(self):
19971971
if self._paths is None:
19981972
self.set_paths()
@@ -2036,11 +2010,10 @@ def set_array(self, A):
20362010
faulty_data = True
20372011

20382012
if misshapen_data:
2039-
_api.warn_deprecated(
2040-
"3.5", message=f"For X ({width}) and Y ({height}) "
2041-
f"with {self._shading} shading, the expected shape of "
2042-
f"A is ({h}, {w}). Passing A ({A.shape}) is deprecated "
2043-
"since %(since)s and will become an error %(removal)s.")
2013+
raise ValueError(
2014+
f"For X ({width}) and Y ({height}) with {self._shading} "
2015+
f"shading, the expected shape of A is ({h}, {w}), not "
2016+
f"{A.shape}")
20442017

20452018
if faulty_data:
20462019
raise TypeError(

lib/matplotlib/tests/test_collections.py

Lines changed: 4 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
import matplotlib.path as mpath
1313
import matplotlib.transforms as mtransforms
1414
from matplotlib.collections import (Collection, LineCollection,
15-
EventCollection, PolyCollection,
16-
QuadMesh)
15+
EventCollection, PolyCollection)
1716
from matplotlib.testing.decorators import check_figures_equal, image_comparison
18-
from matplotlib._api.deprecation import MatplotlibDeprecationWarning
1917

2018

2119
def generate_EventCollection_plot():
@@ -811,77 +809,6 @@ def test_autolim_with_zeros(transform, expected):
811809
np.testing.assert_allclose(ax.get_xlim(), expected)
812810

813811

814-
@pytest.mark.parametrize('flat_ref, kwargs', [
815-
(True, {}),
816-
(False, {}),
817-
(True, dict(antialiased=False)),
818-
(False, dict(transform='__initialization_delayed__')),
819-
])
820-
@check_figures_equal(extensions=['png'])
821-
def test_quadmesh_deprecated_signature(
822-
fig_test, fig_ref, flat_ref, kwargs):
823-
# test that the new and old quadmesh signature produce the same results
824-
# remove when the old QuadMesh.__init__ signature expires (v3.5+2)
825-
x = [0, 1, 2, 3.]
826-
y = [1, 2, 3.]
827-
X, Y = np.meshgrid(x, y)
828-
X += 0.2 * Y
829-
coords = np.stack([X, Y], axis=-1)
830-
assert coords.shape == (3, 4, 2)
831-
C = np.linspace(0, 2, 6).reshape(2, 3)
832-
833-
ax = fig_test.add_subplot()
834-
ax.set(xlim=(0, 5), ylim=(0, 4))
835-
if 'transform' in kwargs:
836-
kwargs['transform'] = mtransforms.Affine2D().scale(1.2) + ax.transData
837-
qmesh = QuadMesh(coords, **kwargs)
838-
qmesh.set_array(C)
839-
ax.add_collection(qmesh)
840-
assert qmesh._shading == 'flat'
841-
842-
ax = fig_ref.add_subplot()
843-
ax.set(xlim=(0, 5), ylim=(0, 4))
844-
if 'transform' in kwargs:
845-
kwargs['transform'] = mtransforms.Affine2D().scale(1.2) + ax.transData
846-
with pytest.warns(MatplotlibDeprecationWarning):
847-
qmesh = QuadMesh(4 - 1, 3 - 1,
848-
coords.copy().reshape(-1, 2) if flat_ref else coords,
849-
**kwargs)
850-
qmesh.set_array(C.flatten() if flat_ref else C)
851-
ax.add_collection(qmesh)
852-
assert qmesh._shading == 'flat'
853-
854-
855-
@check_figures_equal(extensions=['png'])
856-
def test_quadmesh_deprecated_positional(fig_test, fig_ref):
857-
# test that positional parameters are still accepted with the old signature
858-
# and work correctly
859-
# remove when the old QuadMesh.__init__ signature expires (v3.5+2)
860-
from matplotlib.collections import QuadMesh
861-
862-
x = [0, 1, 2, 3.]
863-
y = [1, 2, 3.]
864-
X, Y = np.meshgrid(x, y)
865-
X += 0.2 * Y
866-
coords = np.stack([X, Y], axis=-1)
867-
assert coords.shape == (3, 4, 2)
868-
C = np.linspace(0, 2, 12).reshape(3, 4)
869-
870-
ax = fig_test.add_subplot()
871-
ax.set(xlim=(0, 5), ylim=(0, 4))
872-
qmesh = QuadMesh(coords, antialiased=False, shading='gouraud')
873-
qmesh.set_array(C)
874-
ax.add_collection(qmesh)
875-
876-
ax = fig_ref.add_subplot()
877-
ax.set(xlim=(0, 5), ylim=(0, 4))
878-
with pytest.warns(MatplotlibDeprecationWarning):
879-
qmesh = QuadMesh(4 - 1, 3 - 1, coords.copy().reshape(-1, 2),
880-
False, 'gouraud')
881-
qmesh.set_array(C)
882-
ax.add_collection(qmesh)
883-
884-
885812
def test_quadmesh_set_array_validation():
886813
x = np.arange(11)
887814
y = np.arange(8)
@@ -890,7 +817,9 @@ def test_quadmesh_set_array_validation():
890817
coll = ax.pcolormesh(x, y, z)
891818

892819
# Test deprecated warning when faulty shape is passed.
893-
with pytest.warns(MatplotlibDeprecationWarning):
820+
with pytest.raises(ValueError, match=r"For X \(11\) and Y \(8\) with flat "
821+
r"shading, the expected shape of A is \(7, 10\), not "
822+
r"\(10, 7\)"):
894823
coll.set_array(z.reshape(10, 7))
895824

896825
z = np.arange(54).reshape((6, 9))

0 commit comments

Comments
 (0)
0