Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
MNT: revert contour deprecations
Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com>
  • Loading branch information
jklymak and rcomer committed Oct 26, 2023
commit e9a102f090d91dae6745b7f6313ecc6040def959
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/deprecations/27088-JK.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Deprecations removed in ``contour``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

``contour.allsegs``, ``contour.allkinds``, and ``contour.find_nearest_contour`` are no
longer marked for deprecation.
9 changes: 4 additions & 5 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,12 +930,12 @@ def __init__(self, ax, *args,
", ".join(map(repr, kwargs))
)

allsegs = _api.deprecated("3.8", pending=True)(property(lambda self: [
allsegs = property(lambda self: [
[subp.vertices for subp in p._iter_connected_components()]
for p in self.get_paths()]))
allkinds = _api.deprecated("3.8", pending=True)(property(lambda self: [
for p in self.get_paths()])
allkinds = property(lambda self: [
[subp.codes for subp in p._iter_connected_components()]
for p in self.get_paths()]))
for p in self.get_paths()])
tcolors = _api.deprecated("3.8")(property(lambda self: [
(tuple(rgba),) for rgba in self.to_rgba(self.cvalues, self.alpha)]))
tlinewidths = _api.deprecated("3.8")(property(lambda self: [
Expand Down Expand Up @@ -1389,7 +1389,6 @@ def _find_nearest_contour(self, xy, indices=None):

return idx_level_min, idx_vtx_min, proj_min

@_api.deprecated("3.8")
def find_nearest_contour(self, x, y, indices=None, pixel=True):
"""
Find the point in the contour plot that is closest to ``(x, y)``.
Expand Down
32 changes: 12 additions & 20 deletions lib/matplotlib/tests/test_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,23 +530,19 @@ def test_find_nearest_contour():
img = np.exp(-np.pi * (np.sum((xy - 5)**2, 0)/5.**2))
cs = plt.contour(img, 10)

with pytest.warns(mpl._api.MatplotlibDeprecationWarning):
nearest_contour = cs.find_nearest_contour(1, 1, pixel=False)
nearest_contour = cs.find_nearest_contour(1, 1, pixel=False)
expected_nearest = (1, 0, 33, 1.965966, 1.965966, 1.866183)
assert_array_almost_equal(nearest_contour, expected_nearest)

with pytest.warns(mpl._api.MatplotlibDeprecationWarning):
nearest_contour = cs.find_nearest_contour(8, 1, pixel=False)
nearest_contour = cs.find_nearest_contour(8, 1, pixel=False)
expected_nearest = (1, 0, 5, 7.550173, 1.587542, 0.547550)
assert_array_almost_equal(nearest_contour, expected_nearest)

with pytest.warns(mpl._api.MatplotlibDeprecationWarning):
nearest_contour = cs.find_nearest_contour(2, 5, pixel=False)
nearest_contour = cs.find_nearest_contour(2, 5, pixel=False)
expected_nearest = (3, 0, 21, 1.884384, 5.023335, 0.013911)
assert_array_almost_equal(nearest_contour, expected_nearest)

with pytest.warns(mpl._api.MatplotlibDeprecationWarning):
nearest_contour = cs.find_nearest_contour(2, 5, indices=(5, 7), pixel=False)
nearest_contour = cs.find_nearest_contour(2, 5, indices=(5, 7), pixel=False)
expected_nearest = (5, 0, 16, 2.628202, 5.0, 0.394638)
assert_array_almost_equal(nearest_contour, expected_nearest)

Expand All @@ -556,16 +552,13 @@ def test_find_nearest_contour_no_filled():
img = np.exp(-np.pi * (np.sum((xy - 5)**2, 0)/5.**2))
cs = plt.contourf(img, 10)

with pytest.warns(mpl._api.MatplotlibDeprecationWarning), \
pytest.raises(ValueError, match="Method does not support filled contours"):
with pytest.raises(ValueError, match="Method does not support filled contours"):
cs.find_nearest_contour(1, 1, pixel=False)

with pytest.warns(mpl._api.MatplotlibDeprecationWarning), \
pytest.raises(ValueError, match="Method does not support filled contours"):
with pytest.raises(ValueError, match="Method does not support filled contours"):
cs.find_nearest_contour(1, 10, indices=(5, 7), pixel=False)

with pytest.warns(mpl._api.MatplotlibDeprecationWarning), \
pytest.raises(ValueError, match="Method does not support filled contours"):
with pytest.raises(ValueError, match="Method does not support filled contours"):
cs.find_nearest_contour(2, 5, indices=(2, 7), pixel=True)


Expand Down Expand Up @@ -825,12 +818,11 @@ def test_allsegs_allkinds():

cs = plt.contour(x, y, z, levels=[0, 0.5])

# Expect two levels, first with 5 segments and the second with 4.
with pytest.warns(PendingDeprecationWarning, match="all"):
for result in [cs.allsegs, cs.allkinds]:
assert len(result) == 2
assert len(result[0]) == 5
assert len(result[1]) == 4
# Expect two levels, the first with 5 segments and the second with 4.
for result in [cs.allsegs, cs.allkinds]:
assert len(result) == 2
assert len(result[0]) == 5
assert len(result[1]) == 4


def test_deprecated_apis():
Expand Down