-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Improve reprs of transforms. #9421
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
Conversation
3603921
to
6960534
Compare
Instead of re-indenting in every parent, you could define |
I actually had an original implementation that did that, but I think it's better not to do so, because I'd prefer keeping the format string available for (... some day) pass it down to float formatting (à la numpy/numpy#5543), rather than overloading it for what is mostly internal use. TBH I don't think the performance of reindenting every parent is a real issue... |
I added the same sort of fancy string formats to the transforms in other projections. |
lib/matplotlib/projections/geo.py
Outdated
@@ -268,6 +267,11 @@ def __init__(self, resolution): | ||
Transform.__init__(self) | ||
self._resolution = resolution | ||
|
||
def __str__(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't these be provided by a mixin class? transform_path_non_affine also looks repeated across, haven't checked if other methods are too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly; I wasn't really looking for things to refactor, but I'm sure there's a lot of repetition in there.
I was also wondering if maybe we should def __repr__(self): return str(self)
in some parent class instead of __repr__ = __str__
in every subclass?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. Want to push it?
lib/matplotlib/projections/polar.py
Outdated
def __str__(self): | ||
return ("{}(\n" | ||
"{},\n" | ||
" use_rmin={},\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a slightly preference for this string not to be indented, or remove the explicit spaces and call indent_str for use_rmin too (either way). The idea was to make the source layout "look like" the final result. Same comment throughout.
Where is this at? I was just looking at some Transforms, and their |
I pushed the whitespace fix, the |
I tested the import numpy as np
import matplotlib.pyplot as plt
fig, axs = plt.subplots()
axs.plot(np.arange(10))
la = axs.set_xlabel('Test')
print(la.get_transform()) and I got:
Are there enough tests of the geo-transform code to make sure this refactor is OK? |
I'd assume yes (and it's really just moving common code to a base class), if not that means more tests are needed anyways... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add a whats_new for this?
Is there a straight forward way to at least smoke-test the reprs? |
done (the whatsnew) I think numpy is going to (finally) change their floating point reprs (for the better) numpy/numpy#9941 so unless we construct exactly the right transform to only use integer values we'll (soon) have some trouble getting stable outputs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very helpful
|
aad58ce
to
710ed64
Compare
Hey, I'm supposed to be the rst police :) |
This patch should make debugging the transform a bit stack easier, by changing, for example, the repr of the transform of a line created with `plot([1, 2])` from CompositeGenericTransform(TransformWrapper(BlendedAffine2D(IdentityTransform(),IdentityTransform())), CompositeGenericTransform(BboxTransformFrom(TransformedBbox(Bbox([[-0.05, 0.95], [1.05, 2.05]]), TransformWrapper(BlendedAffine2D(IdentityTransform(),IdentityTransform())))), BboxTransformTo(TransformedBbox(Bbox([[0.125, 0.10999999999999999], [0.9, 0.88]]), BboxTransformTo(TransformedBbox(Bbox([[0.0, 0.0], [6.4, 4.8]]), Affine2D(array([[ 100., 0., 0.], [ 0., 100., 0.], [ 0., 0., 1.]])))))))) to CompositeGenericTransform( TransformWrapper( BlendedAffine2D( IdentityTransform(), IdentityTransform())), CompositeGenericTransform( BboxTransformFrom( TransformedBbox( Bbox(x0=-0.05, y0=0.95, x1=1.05, y1=2.05), TransformWrapper( BlendedAffine2D( IdentityTransform(), IdentityTransform())))), BboxTransformTo( TransformedBbox( Bbox(x0=0.125, y0=0.10999999999999999, x1=0.9, y1=0.88), BboxTransformTo( TransformedBbox( Bbox(x0=0.0, y0=0.0, x1=6.4, y1=4.8), Affine2D( [[ 100. 0. 0.] [ 0. 100. 0.] [ 0. 0. 1.]]))))))) This will, of course, invalidate code that relied on the exact strs, but what can you do.
710ed64
to
dbefd27
Compare
I was just saving you clicking into the test failure - you are still definitely the rst enforcer! |
This patch should make debugging the transform a bit stack easier, by
changing, for example, the repr of the transform of a line created with
plot([1, 2])
fromto
This will, of course, invalidate code that relied on the exact strs, but
what can you do.
PR Summary
PR Checklist