Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 12, 2019

Conversation

djdt
Copy link
Contributor

@djdt djdt commented Jul 18, 2019

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
Member

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

@djdt
Copy link
Contributor Author

djdt commented Jul 18, 2019

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
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
Copy link
Contributor Author

djdt commented Aug 3, 2019

@timhoffm done

@timhoffm
Copy link
Member

timhoffm commented Aug 8, 2019

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
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