-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Added axis limit check for non-finite values #7744
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
Should this raise a warning instead of an error? Currently invalid limits on a log axis raises a warning (#7367), which I think is best. Either way either a warning or error should be raised consistently. |
Yeah, that sounds like the better approach. Passing an invalid value to |
Current coverage is 62.12% (diff: 100%)@@ master #7744 diff @@
==========================================
Files 174 174
Lines 56028 56032 +4
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 34805 34808 +3
- Misses 21223 21224 +1
Partials 0 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.
Docs and code are now out of sync.
The consensus in #7460 seemed to be in favor of errors, not warnings. It seems that warnings either just annoy people (because they are doing the thing for a good reason) or are ignored. I think this will still re-set the limits, which was the original complaint. |
Please note #7733 (comment). |
e5cc8e1
to
22387cc
Compare
I've looked over the discussion on #7733 and related issues. Still a bit confused on how to proceed. I think the issues are somewhat unrelated in that the solution for #7735 - letting invalid values pass through - is actually the cause of the issue this PR addresses (#7460). I've reset back to the commit that raises errors instead of warnings. |
22387cc
to
d633b8a
Compare
Rebased. 👍 |
@@ -4931,3 +4931,15 @@ def test_bar_single_height(): | |||
ax.bar(range(4), 1) | |||
# Check that a horizontal chart with one width works | |||
ax.bar(0, 1, bottom=range(4), width=1, orientation='horizontal') | |||
|
|||
|
|||
def test_invalid_axis_limits(): |
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.
One last thing, could a @cleanup
decorator go above this line. Otherwise looks good!
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.
Not needed on current master
.
lib/matplotlib/axes/_base.py
Outdated
if ((left is not None and not np.isfinite(left)) or | ||
(right is not None and not np.isfinite(right))): | ||
raise ValueError("xlim limits must be finite. " | ||
"instead, found: (%s, %s)" % (left, right)) |
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.
'xlim limits' is a bit redundant. Also, 'instead' comes after a period so should be capitalized. Something like 'Specified x limits must be finite; instead found: (%s, %s)'.
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.
Alright, sounds good. That redundancy bothered me too, but I couldn't think of the right verbiage to describe the warning. Thanks!
lib/matplotlib/axes/_base.py
Outdated
if ((top is not None and not np.isfinite(top)) or | ||
(bottom is not None and not np.isfinite(bottom))): | ||
raise ValueError("ylim limits must be finite. " | ||
"instead, found: (%s, %s)" % (top, bottom)) |
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.
Same comment here, but also, 'bottom' should come before 'top'.
lib/matplotlib/axes/_base.py
Outdated
@@ -3176,7 +3176,7 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw): | |||
|
|||
if ((top is not None and not np.isfinite(top)) or | |||
(bottom is not None and not np.isfinite(bottom))): | |||
raise ValueError("ylim limits must be finite. " | |||
raise ValueError("Specified y limits must be finite; " | |||
"instead, found: (%s, %s)" % (top, bottom)) |
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.
Still need to swap top
and bottom
.
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.
Whoops, my bad.
dbe5a42
to
14e543f
Compare
14e543f
to
a52177a
Compare
@tacaswell To what documentation are you referring in your review? Can it be dismissed? |
Ping @tacaswell? |
Addresses #7460.
Raises a
ValueError
if non-finite values likenp.nan
ornp.inf
are passed as arguments toset_xlim
orset_ylim
.