Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Raise error if argument to xlim is invalid, e.g., nan #7460

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

Closed
anntzer opened this issue Nov 15, 2016 · 11 comments
Closed

Raise error if argument to xlim is invalid, e.g., nan #7460

anntzer opened this issue Nov 15, 2016 · 11 comments
Labels
Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
Milestone

Comments

@anntzer
Copy link
Contributor

anntzer commented Nov 15, 2016

As of 2.0b4, passing nan as a limit to xlim seems to reset both limits to (-0.001, 0.001) (try e.g. with plt.plot([0, 1]); plt.xlim(right=np.nan)). I think this should either error, or, more usefully, be interpreted as None (i.e. leave that limit as is). (For extra points, we can also bikeshed what passing inf to xlim should mean.)

The main use case would be when the xlim is read from some float context (e.g. from an array) where you can easily store nan but not None.

@tacaswell
Copy link
Member

Biased toward erroring, using np.nan as a stand in for None seems a bit too clever and surprising, but am open to be talked into it.

From git-blame, I think that this behavior has been long standing (e356a15 in 2008 from @efiring )

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Nov 15, 2016
@NelleV
Copy link
Member

NelleV commented Nov 15, 2016

So your suggestion is to raise an error?

@NelleV
Copy link
Member

NelleV commented Nov 15, 2016

(I'd raise an error…)

@tacaswell
Copy link
Member

That seems to be 1.5 votes to error.

@efiring
Copy link
Member

efiring commented Nov 20, 2016

Make that 2.5.

@anntzer
Copy link
Contributor Author

anntzer commented Nov 20, 2016

I'm fine with making it an error too. Same with inf?

@efiring
Copy link
Member

efiring commented Nov 20, 2016

Yes. Sounds like an np.isfinite check is in order.

@efiring efiring changed the title let xlim(left=np.nan, right=...) be synonymous to xlim(left=None, right=...) Raise error if argument to xlim is invalid, e.g., nan Nov 27, 2016
@efiring efiring added Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues new-contributor-friendly labels Nov 27, 2016
@bcongdon
Copy link
Contributor

bcongdon commented Jan 4, 2017

Working on this now. It looks like np.isfinite raises an error if you pass it something non-numeric, like a date.

Do we need the full np.isfinite check, or can we just reject np.nan and np.inf values?

@efiring
Copy link
Member

efiring commented Jan 4, 2017

I think you can handle that by putting the check after the calls to convert_xunits; I think that np.isfinite should be safe there.

@tacaswell
Copy link
Member

We now have 3 PRs for this!

QuLogic added a commit that referenced this issue Apr 13, 2017
Fixed Issue #7460: Raised an error if argument to xlim is invalid
@QuLogic QuLogic closed this as completed Apr 13, 2017
@QuLogic
Copy link
Member

QuLogic commented Apr 13, 2017

Closed by #7744 and #8022.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
Projects
None yet
Development

No branches or pull requests

6 participants