-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
WARN: more direct warning ticklabels #26401
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
So the failed tests bring up a use case for This PR checks for an empty list for tick labels, and short circuits to NullFormatter. However, we should probably decide how we want to do this properly. I believe we did this #20047 (ping @timhoffm) and perhaps needs a bit of a rethink. |
314785e
to
b0c11c4
Compare
Flake8 is failing for E721 on a bunch of code I didn't change. I guess a new version of flake8 (doesn't fail locally) |
I have opened #26414 for those |
b0c11c4
to
dc667de
Compare
if isinstance(locator, mticker.FixedLocator): | ||
if not labels: | ||
# eg labels=[]: | ||
formatter = mticker.NullFormatter() |
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 does not have an effect if you return on the next line. formatter
is only used in lines 2005ff.
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.
Obviously, this is untested. You can add a test that there is no warning using
with warnings.catch_warnings():
warnings.simplefilter("error")
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.
Oops thanks I knew there was a reason to not do that.
It is tested, but the old code ends up being used
I'll move to draft as I'm away for a few days
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.
Is the warning filter necessary, since we run with warnings as errors in general? C.f. the test added at #26300.
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.
It's not necessary but prevents the same warning appearing with two different syntaxes.
Since #26414 is in, you can rebase to fix flake8. |
lib/matplotlib/axis.py
Outdated
locs = self.get_majorticklocs() | ||
ticks = self.get_major_ticks(len(locs)) | ||
with warnings.catch_warnings(): | ||
warnings.filterwarnings("ignore", message="FixedFormatter should only ") |
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.
Let's be more explicit:
warnings.filterwarnings("ignore", message="FixedFormatter should only ") | |
warnings.filterwarnings( | |
"ignore", | |
message="FixedFormatter should only be used together with FixedLocator") |
Also, I'm tempted to move this in to be only around set_..._formatter
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.
Repeat the filter twice? Doesn't seem necessary, though it does make it more obvious what call is getting the filter.
if isinstance(locator, mticker.FixedLocator): | ||
if not labels: | ||
# eg labels=[]: | ||
formatter = mticker.NullFormatter() |
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.
Obviously, this is untested. You can add a test that there is no warning using
with warnings.catch_warnings():
warnings.simplefilter("error")
dc667de
to
c472067
Compare
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 looks good to me.
I agree with Tim's suggestions, but leaving an approval to expedite merging once fixed.
~Ooops yes I forgot to address those yet. Please let me fix before merging. ~ Should be fine now |
c472067
to
871f0e4
Compare
871f0e4
to
dd2e6f8
Compare
PR summary
Closes #26398
This now warns with
PR checklist