-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Avoid dividing by zero in AutoMinorLocator (fixes #8804) #9465
Avoid dividing by zero in AutoMinorLocator (fixes #8804) #9465
Conversation
lib/matplotlib/ticker.py
Outdated
@@ -2545,7 +2545,7 @@ def __call__(self): | |||
if vmin > vmax: | |||
vmin, vmax = vmax, vmin | |||
|
|||
if len(majorlocs) > 0: | |||
if len(majorlocs) >= 2: |
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 just do an early return []
around line 2522 instead of having to handle this case throughout the function?
f51fa53
to
44677ff
Compare
@anntzer An early return is now performed. I also extended a bit the dedicated test. |
lib/matplotlib/ticker.py
Outdated
@@ -2524,7 +2524,7 @@ def __call__(self): | |||
# TODO: Figure out a way to still be able to display minor | |||
# ticks without two major ticks visible. For now, just display | |||
# no ticks at all. | |||
majorstep = 0 | |||
return [] | |||
|
|||
if self.ndivs is None: | |||
if majorstep == 0: |
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 think this can go away too now?
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.
Indeed... I was a bit too quick.
44677ff
to
3418d96
Compare
Address @anntzer's last comment (about removing now unnecessary code) and rebased. (The new test was kept unmodified and is still passing) |
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.
conditional on tests
Thanks @afvincent ! |
Backport PR #9465 on branch v2.1.x
PR Summary
Get rid of 2
DivisionByZero
warnings by performing a proper early return, which prevents the case noticed by @ffteja in #8804 from happening.PR Checklist