Skip to content

Fix: decouple annotation xy from mutable inputs (swev-id: matplotlib__matplotlib-26466)#74

Open
casey-brooks wants to merge 1 commit intomatplotlib__matplotlib-26466from
fix/annotate-xy-mutable-286
Open

Fix: decouple annotation xy from mutable inputs (swev-id: matplotlib__matplotlib-26466)#74
casey-brooks wants to merge 1 commit intomatplotlib__matplotlib-26466from
fix/annotate-xy-mutable-286

Conversation

@casey-brooks
Copy link

Closes #72

Summary

  • tuple-copy annotation xy in _AnnotationBase.__init__
  • tuple-copy OffsetFrom reference coordinates for consistency
  • add mutation regression tests and an Agg reproduction script

Reproduction

  1. Run python doc/devel/examples/repro_annotate_xy_mutability.py
  2. On affected builds the "After mutation" log shows annotation pixels and xytext following the mutated NumPy/list sources instead of the original coordinates (Agg backend).

Observed: annotation and text offset drift to the mutated values even though no setter was called.
Expected: annotation remains tied to its original coordinates regardless of external mutations.

Testing

  • MPLBACKEND=Agg PYTHONPATH=/workspace/matplotlib/lib 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 PYTEST_ADDOPTS='-W ignore::DeprecationWarning' .venv/bin/pytest lib/matplotlib/tests/test_text.py -q -k "annotation_xy_numpy_source_mutation_no_effect or annotation_xytext_numpy_source_mutation_no_effect or annotation_xy_list_source_mutation_no_effect or offsetfrom_ref_coord_numpy_mutation_no_effect"

Notes

  • Functional bug; no stack trace was reported.
  • CI should not be manually triggered.

@casey-brooks casey-brooks requested a review from a team December 25, 2025 13:41
@casey-brooks casey-brooks force-pushed the fix/annotate-xy-mutable-286 branch from 28b8afb to af2351b Compare December 25, 2025 13:42
@casey-brooks
Copy link
Author

Local verification

  • Tests: MPLBACKEND=Agg PYTHONPATH=/workspace/matplotlib/lib 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 PYTEST_ADDOPTS='-W ignore::DeprecationWarning' .venv/bin/pytest lib/matplotlib/tests/test_text.py -q -k "annotation_xy_numpy_source_mutation_no_effect or annotation_xytext_numpy_source_mutation_no_effect or annotation_xy_list_source_mutation_no_effect or offsetfrom_ref_coord_numpy_mutation_no_effect" → 4 passed, 115 deselected
  • Lint: .venv/bin/flake8 lib/matplotlib/text.py lib/matplotlib/tests/test_text.py doc/devel/examples/repro_annotate_xy_mutability.py → no issues

Copy link

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great: tuple-copying the annotation anchors fixes the mutable input regression and the new tests cover NumPy and list sources, plus OffsetFrom is now hardened. Thanks for the thorough repro script as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants