Added axis limit check for non-finite values #7744

Merged
merged 2 commits into from Mar 7, 2017

Conversation

Projects
None yet
6 participants
Contributor

bcongdon commented Jan 5, 2017

Addresses #7460.

Raises a ValueError if non-finite values like np.nan or np.inf are passed as arguments to set_xlim or set_ylim.

Contributor

dstansby commented Jan 5, 2017

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.

Contributor

bcongdon commented Jan 5, 2017 edited

Yeah, that sounds like the better approach. Passing an invalid value to plt.xlim results in unexpected behavior, but a plot can still be drawn.

codecov-io commented Jan 5, 2017 edited

Current coverage is 62.12% (diff: 100%)

Merging #7744 into master will increase coverage by <.01%

@@             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          

Powered by Codecov. Last update 015d8d5...e5cc8e1

tacaswell added this to the 2.1 (next point release) milestone Jan 7, 2017

@tacaswell

Docs and code are now out of sync.

Owner

tacaswell commented Jan 7, 2017

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.

Contributor

anntzer commented Jan 13, 2017

Please note #7733 (comment).

Contributor

bcongdon commented Jan 20, 2017

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.

Contributor

dstansby commented Feb 5, 2017

I think the consensus is to raise an error, which sounds good to me (see #7460). @bcongdon could you rebase this on to the current master branch? Otherwise it looks good to go.

@bcongdon bcongdon Added set_xlim and set_ylim check for non-finite limit values
d633b8a
Contributor

bcongdon commented Feb 5, 2017

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():
@dstansby

dstansby Feb 5, 2017

Contributor

One last thing, could a @cleanup decorator go above this line. Otherwise looks good!

@QuLogic

QuLogic Feb 5, 2017

Member

Not needed on current master.

lib/matplotlib/axes/_base.py
+ 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))
@QuLogic

QuLogic Feb 5, 2017

Member

'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)'.

@bcongdon

bcongdon Feb 6, 2017

Contributor

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
+ 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))
@QuLogic

QuLogic Feb 5, 2017

Member

Same comment here, but also, 'bottom' should come before 'top'.

lib/matplotlib/axes/_base.py
@@ -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))
@QuLogic

QuLogic Feb 6, 2017

Member

Still need to swap top and bottom.

@bcongdon

bcongdon Feb 6, 2017

Contributor

Whoops, my bad.

@bcongdon bcongdon Cleaned up invalid axis limit warning text
a52177a

Not needed on master.

Member

QuLogic commented Feb 6, 2017

@tacaswell To what documentation are you referring in your review? Can it be dismissed?

QuLogic changed the title from Added axis limit check for non-finite values to [MRG+1] Added axis limit check for non-finite values Feb 26, 2017

Member

QuLogic commented Feb 26, 2017

Ping @tacaswell?

@tacaswell tacaswell merged commit 1d45c08 into matplotlib:master Mar 7, 2017

4 checks passed

codecov/patch 100% of diff hit (target 68.69%)
Details
codecov/project 69% (+0.3%) compared to 91261e7
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

QuLogic changed the title from [MRG+1] Added axis limit check for non-finite values to Added axis limit check for non-finite values Mar 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment