Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitd2ee3d5

Browse files
authored
Merge pull request#21741 from jakelishman/fix/do_3d_projection-deprecation
Reduce do_3d_projection deprecation warnings in external artists
2 parentsf06543e +53e124b commitd2ee3d5

File tree

2 files changed

+79
-15
lines changed

2 files changed

+79
-15
lines changed

‎lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
fromcollectionsimportdefaultdict
1414
importfunctools
15+
importinspect
1516
importitertools
1617
importmath
1718
fromnumbersimportIntegral
@@ -412,24 +413,27 @@ def do_3d_projection(artist):
412413
Call `do_3d_projection` on an *artist*, and warn if passing
413414
*renderer*.
414415
415-
For our Artists, never pass *renderer*. Forexternal Artists,
416-
in lieu of more complicated signature parsing, always pass
417-
*renderer* and raise a warning.
416+
Attempt to bind the empty signature first, soexternal Artists
417+
can avoid the deprecation warning if they support the new
418+
calling convention.
418419
"""
419-
420-
ifartist.__module__=='mpl_toolkits.mplot3d.art3d':
421-
# Our 3D Artists have deprecated the renderer parameter, so
422-
# avoid passing it to them; call this directly once the
423-
# deprecation has expired.
420+
try:
421+
signature=inspect.signature(artist.do_3d_projection)
422+
signature.bind()
423+
# ValueError if `inspect.signature` cannot provide a signature
424+
# and TypeError if the binding fails or the object does not
425+
# appear to be callable - the next call will then re-raise.
426+
except (ValueError,TypeError):
427+
_api.warn_deprecated(
428+
"3.4",
429+
message="The 'renderer' parameter of "
430+
"do_3d_projection() was deprecated in Matplotlib "
431+
"%(since)s and will be removed %(removal)s.")
432+
returnartist.do_3d_projection(renderer)
433+
else:
434+
# Call this directly once the deprecation period expires.
424435
returnartist.do_3d_projection()
425436

426-
_api.warn_deprecated(
427-
"3.4",
428-
message="The 'renderer' parameter of "
429-
"do_3d_projection() was deprecated in Matplotlib "
430-
"%(since)s and will be removed %(removal)s.")
431-
returnartist.do_3d_projection(renderer)
432-
433437
collections_and_patches= (
434438
artistforartistinself._children
435439
ifisinstance(artist, (mcoll.Collection,mpatches.Patch))

‎lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,3 +1711,63 @@ def test_view_init_vertical_axis(
17111711
tickdir_expected=tickdirs_expected[i]
17121712
tickdir_actual=axis._get_tickdir()
17131713
np.testing.assert_array_equal(tickdir_expected,tickdir_actual)
1714+
1715+
1716+
deftest_do_3d_projection_renderer_deprecation_warn_on_argument():
1717+
"""
1718+
Test that an external artist with an old-style calling convention raises
1719+
a suitable deprecation warning.
1720+
"""
1721+
classDummyPatch(art3d.Patch3D):
1722+
defdo_3d_projection(self,renderer):
1723+
return0
1724+
1725+
defdraw(self,renderer):
1726+
pass
1727+
1728+
fig=plt.figure()
1729+
ax=fig.add_subplot(111,projection='3d')
1730+
artist=DummyPatch()
1731+
ax.add_artist(artist)
1732+
1733+
match=r"The 'renderer' parameter of do_3d_projection\(\) was deprecated"
1734+
withpytest.warns(MatplotlibDeprecationWarning,match=match):
1735+
fig.canvas.draw()
1736+
1737+
1738+
deftest_do_3d_projection_renderer_deprecation_nowarn_on_optional_argument():
1739+
"""
1740+
Test that an external artist with a calling convention compatible with
1741+
both v3.3 and v3.4 does not raise a deprecation warning.
1742+
"""
1743+
classDummyPatch(art3d.Patch3D):
1744+
defdo_3d_projection(self,renderer=None):
1745+
return0
1746+
1747+
defdraw(self,renderer):
1748+
pass
1749+
1750+
fig=plt.figure()
1751+
ax=fig.add_subplot(111,projection='3d')
1752+
artist=DummyPatch()
1753+
ax.add_artist(artist)
1754+
fig.canvas.draw()
1755+
1756+
1757+
deftest_do_3d_projection_renderer_deprecation_nowarn_on_no_argument():
1758+
"""
1759+
Test that an external artist with a calling convention compatible with
1760+
only v3.4 does not raise a deprecation warning.
1761+
"""
1762+
classDummyPatch(art3d.Patch3D):
1763+
defdo_3d_projection(self):
1764+
return0
1765+
1766+
defdraw(self,renderer):
1767+
pass
1768+
1769+
fig=plt.figure()
1770+
ax=fig.add_subplot(111,projection='3d')
1771+
artist=DummyPatch()
1772+
ax.add_artist(artist)
1773+
fig.canvas.draw()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp