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 1edae7b

Browse filesBrowse files
authored
Merge pull request #28492 from greglucas/expire-polyquadmesh-dep
MNT: Remove PolyQuadMesh deprecations
2 parents db87995 + c5967e0 commit 1edae7b
Copy full SHA for 1edae7b

File tree

3 files changed

+10
-53
lines changed
Filter options

3 files changed

+10
-53
lines changed
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The ``PolyQuadMesh`` class requires full 2D arrays of values
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Previously, if a masked array was input, the list of polygons within the collection
5+
would shrink to the size of valid polygons and users were required to keep track of
6+
which polygons were drawn and call ``set_array()`` with the smaller "compressed"
7+
array size. Passing the "compressed" and flattened array values will no longer
8+
work and the full 2D array of values (including the mask) should be passed
9+
to `.PolyQuadMesh.set_array`.

‎lib/matplotlib/collections.py

Copy file name to clipboardExpand all lines: lib/matplotlib/collections.py
+1-48Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,14 +2252,8 @@ class PolyQuadMesh(_MeshData, PolyCollection):
22522252
"""
22532253

22542254
def __init__(self, coordinates, **kwargs):
2255-
# We need to keep track of whether we are using deprecated compression
2256-
# Update it after the initializers
2257-
self._deprecated_compression = False
22582255
super().__init__(coordinates=coordinates)
22592256
PolyCollection.__init__(self, verts=[], **kwargs)
2260-
# Store this during the compression deprecation period
2261-
self._original_mask = ~self._get_unmasked_polys()
2262-
self._deprecated_compression = np.any(self._original_mask)
22632257
# Setting the verts updates the paths of the PolyCollection
22642258
# This is called after the initializers to make sure the kwargs
22652259
# have all been processed and available for the masking calculations
@@ -2272,14 +2266,7 @@ def _get_unmasked_polys(self):
22722266

22732267
# We want the shape of the polygon, which is the corner of each X/Y array
22742268
mask = (mask[0:-1, 0:-1] | mask[1:, 1:] | mask[0:-1, 1:] | mask[1:, 0:-1])
2275-
2276-
if (getattr(self, "_deprecated_compression", False) and
2277-
np.any(self._original_mask)):
2278-
return ~(mask | self._original_mask)
2279-
# Take account of the array data too, temporarily avoiding
2280-
# the compression warning and resetting the variable after the call
2281-
with cbook._setattr_cm(self, _deprecated_compression=False):
2282-
arr = self.get_array()
2269+
arr = self.get_array()
22832270
if arr is not None:
22842271
arr = np.ma.getmaskarray(arr)
22852272
if arr.ndim == 3:
@@ -2335,42 +2322,8 @@ def get_facecolor(self):
23352322
def set_array(self, A):
23362323
# docstring inherited
23372324
prev_unmask = self._get_unmasked_polys()
2338-
# MPL <3.8 compressed the mask, so we need to handle flattened 1d input
2339-
# until the deprecation expires, also only warning when there are masked
2340-
# elements and thus compression occurring.
2341-
if self._deprecated_compression and np.ndim(A) == 1:
2342-
_api.warn_deprecated("3.8", message="Setting a PolyQuadMesh array using "
2343-
"the compressed values is deprecated. "
2344-
"Pass the full 2D shape of the original array "
2345-
f"{prev_unmask.shape} including the masked elements.")
2346-
Afull = np.empty(self._original_mask.shape)
2347-
Afull[~self._original_mask] = A
2348-
# We also want to update the mask with any potential
2349-
# new masked elements that came in. But, we don't want
2350-
# to update any of the compression from the original
2351-
mask = self._original_mask.copy()
2352-
mask[~self._original_mask] |= np.ma.getmask(A)
2353-
A = np.ma.array(Afull, mask=mask)
2354-
return super().set_array(A)
2355-
self._deprecated_compression = False
23562325
super().set_array(A)
23572326
# If the mask has changed at all we need to update
23582327
# the set of Polys that we are drawing
23592328
if not np.array_equal(prev_unmask, self._get_unmasked_polys()):
23602329
self._set_unmasked_verts()
2361-
2362-
def get_array(self):
2363-
# docstring inherited
2364-
# Can remove this entire function once the deprecation period ends
2365-
A = super().get_array()
2366-
if A is None:
2367-
return
2368-
if self._deprecated_compression and np.any(np.ma.getmask(A)):
2369-
_api.warn_deprecated("3.8", message=(
2370-
"Getting the array from a PolyQuadMesh will return the full "
2371-
"array in the future (uncompressed). To get this behavior now "
2372-
"set the PolyQuadMesh with a 2D array .set_array(data2d)."))
2373-
# Setting an array of a polycollection required
2374-
# compressing the array
2375-
return np.ma.compressed(A)
2376-
return A

‎lib/matplotlib/tests/test_collections.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_collections.py
-5Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -965,11 +965,6 @@ def test_polyquadmesh_masked_vertices_array():
965965
# Poly version should have the same facecolors as the end of the quadmesh
966966
assert_array_equal(quadmesh_fc, polymesh.get_facecolor())
967967

968-
# Setting array with 1D compressed values is deprecated
969-
with pytest.warns(mpl.MatplotlibDeprecationWarning,
970-
match="Setting a PolyQuadMesh"):
971-
polymesh.set_array(np.ones(5))
972-
973968
# We should also be able to call set_array with a new mask and get
974969
# updated polys
975970
# Remove mask, should add all polys back

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.