Skip to content

Don't assume transform is valid on access to matrix. - #14840

Merged
tacaswell merged 3 commits into
matplotlib:masterfrom
djdt:remove_get_matrix_invalid
Aug 12, 2019
Merged

tacaswell merged 3 commits into
matplotlib:masterfrom
djdt:remove_get_matrix_invalid

Conversation

@djdt

@djdt djdt commented Jul 18, 2019

Copy link
Copy Markdown
Contributor

PR Summary

Accessing the matrix of an Affine2D transform via get_matrix sets _invalid to 0.
This can cause the transform returned by inverted() to be incorrect if the matrix is accessed between a transform and the call to inverted().
Another possible fix would be to check if invalid and set _inverted to None and _invalid to 0.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@dstansby

Copy link
Copy Markdown
Member

It looks like this breaks some of the tests. Could you give an example script that needs this fix to work?

@djdt

djdt commented Jul 18, 2019

Copy link
Copy Markdown
Contributor Author

Currently this will fail, as will any other functions that internally use get_matrix.

import numpy as np
from matplotlib.transforms import Affine2D


point = [1.0, 1.0]
t = Affine2D.identity()

# Transform of inverted transform returns same point, True
print(np.all(point == t.transform(t.inverted().transform(point))))

# Apply a translation, the current transform is declared invalid
t.translate(1.0, 1.0)

# The inverse is correctly updated, True
print(np.all(point == t.transform(t.inverted().transform(point))))

# Apply a translation, the current transform is declared invalid
t.translate(1.0, 1.0)
# Access to the original transform incorrectly clears invalidation
t2 = t.frozen()

# The inverse transform is never updated, False
print(np.all(point == t.transform(t.inverted().transform(point))))

@timhoffm

Copy link
Copy Markdown
Member

The appveyor failure is due to the regression in pandas 0.25.0 (#14861). @djdt can you please rebase on master, which includes a fix for this.

@djdt
djdt force-pushed the remove_get_matrix_invalid branch from af100b9 to c04a641 Compare July 24, 2019 06:08
@djdt

djdt commented Aug 3, 2019

Copy link
Copy Markdown
Contributor Author

@timhoffm done

@timhoffm

timhoffm commented Aug 8, 2019

Copy link
Copy Markdown
Member

Can you please add a test for this? I assume #14840 (comment) can be turned into one.

@tacaswell tacaswell added this to the v3.2.0 milestone Aug 12, 2019
@tacaswell
tacaswell merged commit 2b31002 into matplotlib:master Aug 12, 2019
@tacaswell

Copy link
Copy Markdown
Member

Thank you @djdt ! Hopefully we will hear from you again!

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.

5 participants