Skip to content

Simplify check for tight-bbox finiteness. #13427

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
Feb 18, 2019

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Feb 13, 2019

0 < bbox.width < np.inf is as explicit as bbox.width != 0 and np.isfinite(bbox.width), shorter, and faster (not that it is a
bottleneck, though). (It works because bboxes are oriented to have
nonnegative widths and heights.)

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

for a in [self.label, self.offsetText]:
bbox = a.get_window_extent(renderer)
if (np.isfinite(bbox.width) and np.isfinite(bbox.height) and
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this finiteness check is redundant with the one below

timhoffm
timhoffm previously approved these changes Feb 13, 2019
@@ -4335,8 +4335,7 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
for a in bbox_artists:
bbox = a.get_tightbbox(renderer)
if (bbox is not None and
(bbox.width != 0 or bbox.height != 0) and
np.isfinite(bbox.width) and np.isfinite(bbox.height)):
0 < bbox.width < np.inf and 0 < bbox.height < np.inf):
Copy link
Member

Choose a reason for hiding this comment

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

Optional, but might be easier to read when wrapping the height check to a separate line.

@@ -1152,20 +1152,15 @@ def get_tightbbox(self, renderer):
self.offsetText.set_text(self.major.formatter.get_offset())

bb = []
Copy link
Member

Choose a reason for hiding this comment

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

While we're at it, could be renamed to bboxes. Optional.

@anntzer
Copy link
Contributor Author

anntzer commented Feb 14, 2019

both comments handled

@jklymak
Copy link
Member

jklymak commented Feb 14, 2019

Is it worth doing bboxes = cbook.valid_bboxes(bboxes)?

@tacaswell
Copy link
Member

The values can be np.nan and

In [33]: np.nan < np.inf
Out[33]: False

See #13426

@timhoffm timhoffm dismissed their stale review February 14, 2019 05:53

Does not work.

@anntzer
Copy link
Contributor Author

anntzer commented Feb 14, 2019

But... that's the point here: these are places that check width != 0 and isfinite(width) so return False for nan, and 0 < width < inf also return False for nan.
(in fact I noticed this while reviewing #13426)

`0 < bbox.width < np.inf` is as explicit as `bbox.width != 0 and
np.isfinite(bbox.width)`, shorter, and faster (not that it is a
bottleneck, though).  (It works because bboxes are oriented to have
nonnegative widths and heights.)
@tacaswell
Copy link
Member

🐑 Sorry, was sleepy and got confused about the polarity we were looking at here.

@tacaswell tacaswell added this to the v3.1.0 milestone Feb 14, 2019
@tacaswell tacaswell merged commit a33422b into matplotlib:master Feb 18, 2019
@tacaswell
Copy link
Member

Thanks @anntzer

@anntzer anntzer deleted the isfinite branch February 18, 2019 19:00
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.

4 participants