Skip to content

Check for non-finite axis limits placed on converted_limit #8474

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 5 commits into from
Apr 14, 2017

Conversation

nvedant07
Copy link

In addition to my previous PR ( #8022 ), this one places the check in the _validate_axes_limits() function in /lib/mpl_toolkits/mplot3d/axes3d.py on the converted limits rather than on the limits passed to the function

@nvedant07
Copy link
Author

@QuLogic please take a look

@WeatherGod
Copy link
Member

Hold on a second here... why isn't this method in the base class? Is the check different in the Axes class? I just did a quick looking around at the other PRs related to this one, and they don't seem to do the check in the same way. I am confused.

@nvedant07
Copy link
Author

In the _AxesBase class (defined in lib/matplotlib/axes/_base.py), these checks are defined in the function set_xlim() and set_ylim() itself. For cleaner code @phobson suggested moving these checks to a single function. Are you saying I should moving this function to _base.py as well?

@QuLogic
Copy link
Member

QuLogic commented Apr 13, 2017

Yes, I was going to suggest the same thing; move implementation into the base class and use it there as well.

@nvedant07
Copy link
Author

@WeatherGod @QuLogic moved it to the Base class and replaced the checks there with calls to _validate_axis_limits()

@WeatherGod
Copy link
Member

I just noticed that the 3d limit functions now converts the limit twice. I don't think we have any tests that applies units for 3d axes, so this wouldn't have been noticed in the previous PR.

def _validate_axis_limits(self, limit, convert):
"""
Raise ValueError if specified axis limits are infinite.

Copy link
Member

Choose a reason for hiding this comment

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

The method name is a bit misleading. It validates the converted limit. Also, the docstring doesn't say that it returns anything useful, nor that None can be an input.

Copy link
Author

Choose a reason for hiding this comment

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

I'll change the name to _validate_converted_limits . Should I change the docstring to """ Raise ValueError if converted limits are non-finite.
Note that this functions also accepts None as a limit argument.
Returns : limit value after call to convert_xunits() or convert_yunits() or convert_zunits()""" ?

Copy link
Member

Choose a reason for hiding this comment

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

Name is good. A slight tweak to that docstring,
"Returns : The limit value after call to convert(), or None if limit is None."

raise ValueError("Specified x limits must be finite; "
"instead, found: (%s, %s)" % (left, right))
left = self._validate_axis_limits(left, self.convert_xunits)
right = self._validate_axis_limits(right, self.convert_xunits)
Copy link
Member

Choose a reason for hiding this comment

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

This is so much cleaner! Thank you for this!

Copy link
Author

Choose a reason for hiding this comment

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

Your welcome :)

@nvedant07
Copy link
Author

I checked the 3d functions, set_xlim3d() and set_zlim3d() convert once. set_ylim3d() converts twice, my bad. Should I open another PR for that?

@WeatherGod
Copy link
Member

Fix it here in this PR. It is relevant to what you are fixing up.

@nvedant07
Copy link
Author

@WeatherGod pushed the suggested changes. Please take a look.

Copy link
Member

@WeatherGod WeatherGod left a comment

Choose a reason for hiding this comment

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

Just a couple of typos.

One thing that we lose with this overall change that was nice is the exception message saying which axis was problematic; it also said what the original limits were. I think the trade-off is fine since we can figure out the problematic axis by looking at the traceback, and debugging can get us the values.

bottom = self._validate_axis_limits(bottom, self.convert_yunits)
top = self._validate_axis_limits(top, self.convert_yunits)
bottom = self._validate_converted_limits(bottom, self.convert_yunits)
top = self._validate_converted_limits(top, self.convert_yunits)
Copy link
Member

Choose a reason for hiding this comment

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

convert_yunits --> convert_zunits

"""
Raise ValueError if converted limits are non-finite.

Note that this functions also accepts None as a limit argument.
Copy link
Member

Choose a reason for hiding this comment

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

functions --> function

@nvedant07
Copy link
Author

Fixed. Thanks!

Copy link
Member

@phobson phobson left a comment

Choose a reason for hiding this comment

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

More lines removed than added: I love it! I'll wait for the CI and @WeatherGod to change his review status before merging.

@WeatherGod
Copy link
Member

Will merge once Travis and friends are done. Thanks for bearing with me, and sorry for not noticing these issues in the previous PRs.

@nvedant07
Copy link
Author

Not an issue and thank you too for helping me :)

@phobson phobson added this to the 2.1 (next point release) milestone Apr 14, 2017
@phobson phobson merged commit 1c0b96c into matplotlib:master Apr 14, 2017
@nvedant07 nvedant07 deleted the infinite_limits branch April 18, 2017 14:51
@anntzer anntzer mentioned this pull request Oct 11, 2017
6 tasks
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.

5 participants