Skip to content

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

Merged
QuLogic merged 1 commit into
matplotlib:masterfrom
tacaswell:fix_invalid_figsize
May 23, 2017
Merged

QuLogic merged 1 commit into
matplotlib:masterfrom
tacaswell:fix_invalid_figsize

Conversation

@tacaswell

@tacaswell tacaswell commented May 20, 2017 •

Copy link
Copy Markdown
Member

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
Comment thread lib/matplotlib/figure.py Outdated
frameon = rcParams['figure.frameon']

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

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread lib/matplotlib/figure.py Outdated
if h is None:
w, h = w

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

Copy link
Copy Markdown
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
Comment thread lib/matplotlib/figure.py
if h is None:
w, h = w

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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