swev-id: matplotlib__matplotlib-24627 - detach artist parents after cla/clf#49
swev-id: matplotlib__matplotlib-24627 - detach artist parents after cla/clf#49casey-brooks wants to merge 1 commit intomatplotlib__matplotlib-24627from
Conversation
noa-lucent
left a comment
There was a problem hiding this comment.
[major] lib/matplotlib/axes.py:L4865 rewrites back to the pre-3.x implementation. The current signature is . Dropping the flexible positional handling, horizontal stems, and the LineCollection fast path is a huge backwards-incompatible regression and will break real callers and our own tests. Please keep the existing implementation and only change the minimal code needed for the fix.
Refs: #45 Task: 271
5fc50ce to
9526c66
Compare
noa-lucent
left a comment
There was a problem hiding this comment.
[major] The regression noted previously persists. lib/matplotlib/axes.py still replaces the current Axes.stem implementation with the legacy pre-3.x version, removing the modern signature (def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0, label=None, use_line_collection=True, orientation='vertical')), the horizontal orientation support, and the LineCollection fast path. This is a breaking change for existing callers and fails our Agg tests. Please restore the modern implementation and apply only the minimal changes needed to clear artist parents.
noa-lucent
left a comment
There was a problem hiding this comment.
Thanks for addressing the regression risk. Clearing now calls remove() on the axes’ legend and children before resetting the bookkeeping lists, and Figure.clear removes axes and figure-level artists via their remove() hooks, so attached artists drop their axes/figure references. The new Agg regression tests cover the CLA/CLF scenarios that previously failed. Looks good to me.
Summary
Axes.clear()removes child artists viaremove()so previously attached artists drop theiraxesFigure.clear()to remove axes and figure-level artists before resetting lists so.axes/.figurereferences are clearedcla()andclf()covering legends, images, and a colorbar-backed axesObserved failure (before fix)
Reproduction
Edge Cases & Verification
.axes/.figurereferences.LD_LIBRARY_PATH=/root/.nix-profile/lib:/nix/store/qipd93x9gjyiygqk673rd2ssnf8y7jj0-gcc-14.3.0-lib/lib:/nix/store/f8w1i7yisixb9hivzbk0l4ixmf67fjqr-gcc-14.3.0-libgcc/lib:/nix/store/62yvg9afjvmwa8z17arn4giqmjzg2xd2-glibc-2.40-66/lib PYTHONPATH=/workspace/matplotlib/lib MPLBACKEND=Agg .venv/bin/pytest lib/matplotlib/tests/test_artist.py::test_cla_unsets_artist_axes lib/matplotlib/tests/test_artist.py::test_clf_unsets_figure_and_axes_parents.venv/bin/flake8 lib/matplotlib/axes/_base.py lib/matplotlib/figure.py lib/matplotlib/tests/test_artist.py