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

Skip to content

FIX: fail early for non-finite figure sizes #8647

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

Merged
merged 1 commit into from
May 23, 2017

Conversation

tacaswell
Copy link
Member

@tacaswell tacaswell commented May 20, 2017

Closes #8640

PR Summary

If passed non-finite values to figure size or add_axes, raise immediately rather than at draw time.

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant

@tacaswell tacaswell added this to the 2.1 (next point release) milestone May 20, 2017
@@ -325,6 +325,10 @@ def __init__(self,
frameon = rcParams['figure.frameon']

self.bbox_inches = Bbox.from_bounds(0, 0, *figsize)
if not all(np.isfinite(_) for _ in figsize):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not check this before the expense of creating a Bbox (not that I know if that's a very large expense or not)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just write np.isfinite(figsize).all() (and similarly below): the ufunc will cast the input to an ndarray.

@@ -710,7 +714,9 @@ def set_size_inches(self, w, h=None, forward=True):
# argument, so unpack them
if h is None:
w, h = w

if not all(np.isfinite(_) for _ in (h, w)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really picky, but it's kind of weird to have it be h, w when everything around it is w, h.

@tacaswell tacaswell force-pushed the fix_invalid_figsize branch from bef16b4 to a4999ac Compare May 22, 2017 03:40
@@ -710,7 +714,9 @@ def set_size_inches(self, w, h=None, forward=True):
# argument, so unpack them
if h is None:
w, h = w

if not all(np.isfinite(_) for _ in (w, h)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np.isfinite([w, h]).all()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not convinced going through numpy is better in this case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds fair

@QuLogic QuLogic merged commit 62e8084 into matplotlib:master May 23, 2017
@tacaswell tacaswell deleted the fix_invalid_figsize branch May 23, 2017 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Creating axes and figures with NaN sizes should raise errors earlier
3 participants