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

Skip to content

Make all transforms copiable (and thus scales, too). #19281

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 1 commit into from
Jan 17, 2021

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jan 12, 2021

PR Summary

Closes #18119; more general than #18126?

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

AFAICS the tests do not test the behavioral difference between copy and deepcopy. The specific behavior of both should be exercised in the tests.

@anntzer anntzer force-pushed the copiable-transforms branch from e62d61e to 007afce Compare January 12, 2021 15:47
Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

This looks like it would be good if it is robust. I'm still not clear what is going on well enough to review it though - what happens when people start using these copies in the wild? Also, what is the difference with transform.frozen()?

# propagate back to `c`, i.e. we need to clear the parents of `a1`.
other._parents = {}
# If `c = a + b; c1 = deepcopy(c)`, this creates a separate tree
# (`c1 = a1 + b1`) so nothing needs to be done.
Copy link
Member

Choose a reason for hiding this comment

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

OK, so with a deepcopy the tranform is frozen, or at least to the point where someone would need to dig out the children? Does the copy.deepcopy above really copy the children over?

@anntzer
Copy link
Contributor Author

anntzer commented Jan 12, 2021

I agree tests are needed. I'll work on these in the coming days...

@jklymak jklymak marked this pull request as draft January 12, 2021 20:40
@anntzer anntzer force-pushed the copiable-transforms branch 2 times, most recently from f9f8d41 to 3a63e5e Compare January 15, 2021 10:35
@anntzer
Copy link
Contributor Author

anntzer commented Jan 15, 2021

Now with tests...

@anntzer anntzer marked this pull request as ready for review January 15, 2021 10:35
@anntzer anntzer force-pushed the copiable-transforms branch from 3a63e5e to 7b48c86 Compare January 16, 2021 21:08
Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

This seems fine to me. Has the desired effect of making norms copy-able. I don't think it will have any negative consequences for end-users, though I don't now all the ways our users might use transforms....

@anntzer anntzer force-pushed the copiable-transforms branch from 7b48c86 to b12eb12 Compare January 16, 2021 23:23
def test_scale_deepcopy():
sc = mscale.LogScale(axis='x', base=10)
sc2 = copy.deepcopy(sc)
assert str(sc.get_transform()) == str(sc2.get_transform())
Copy link
Member

Choose a reason for hiding this comment

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

As a rough check that there is no shared state, I'd add

assert sc._transform is not sc2._transform

or, if you're uncomfortable with testing private attributes:

assert sc.get_transform() is not sc2.get_transform()

But personally, I'd test the internal state here, because get_transform() could be written to return copies, so that testing get_transform() include an additional assumption.

Copy link
Contributor Author

@anntzer anntzer Jan 17, 2021

Choose a reason for hiding this comment

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

yes (although this revealed the need to separately implement deepcopy for transforms that just return self in frozen()).

Copy link
Member

Choose a reason for hiding this comment

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

👍 The test found an implementation flaw. It's working 😄

@anntzer anntzer force-pushed the copiable-transforms branch from b12eb12 to 921e945 Compare January 17, 2021 17:22
@timhoffm timhoffm added this to the v3.4.0 milestone Jan 17, 2021
@timhoffm timhoffm merged commit f72adc4 into matplotlib:master Jan 17, 2021
@anntzer anntzer deleted the copiable-transforms branch January 17, 2021 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can no longer deepcopy LogNorm objects on master
3 participants