WARN: more direct warning ticklabels#26401
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.
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.
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.
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.
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.
It's not necessary but prevents the same warning appearing with two different syntaxes.
|
Since #26414 is in, you can rebase to fix flake8. |
| 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.
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.
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.
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
tacaswell
left a comment
There was a problem hiding this comment.
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