Make all transforms copiable (and thus scales, too).#19281
Conversation
e62d61e to
007afce
Compare
jklymak
left a comment
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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?
|
I agree tests are needed. I'll work on these in the coming days... |
f9f8d41 to
3a63e5e
Compare
|
Now with tests... |
3a63e5e to
7b48c86
Compare
jklymak
left a comment
There was a problem hiding this comment.
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....
7b48c86 to
b12eb12
Compare
| def test_scale_deepcopy(): | ||
| sc = mscale.LogScale(axis='x', base=10) | ||
| sc2 = copy.deepcopy(sc) | ||
| assert str(sc.get_transform()) == str(sc2.get_transform()) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
yes (although this revealed the need to separately implement deepcopy for transforms that just return self in frozen()).
There was a problem hiding this comment.
👍 The test found an implementation flaw. It's working 😄
b12eb12 to
921e945
Compare
PR Summary
Closes #18119; more general than #18126?
PR Checklist
pytestpasses).flake8on changed files to check).flake8-docstringsand runflake8 --docstring-convention=all).doc/users/next_whats_new/(follow instructions in README.rst there).doc/api/next_api_changes/(follow instructions in README.rst there).