Added axis limit check for non-finite values#7744
Added axis limit check for non-finite values#7744tacaswell merged 2 commits intomatplotlib:masterfrom
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
|
tacaswell
left a comment
There was a problem hiding this comment.
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. 👍 |
| ax.bar(0, 1, bottom=range(4), width=1, orientation='horizontal') | ||
|
|
||
|
|
||
| def test_invalid_axis_limits(): |
There was a problem hiding this comment.
One last thing, could a @cleanup decorator go above this line. Otherwise looks good!
| 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.
'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.
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.
Same comment here, but also, 'bottom' should come before 'top'.
lib/matplotlib/axes/_base.py
Outdated
| (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.
Still need to swap top and bottom.
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
ValueErrorif non-finite values likenp.nanornp.infare passed as arguments toset_xlimorset_ylim.