-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix floating point inaccuracies in axes limits; partial work on offset value selection #5768
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
Conversation
Doesn't this imply not displaying all of the data? Or am I missing something? |
The |
d327e74
to
4fd8a4e
Compare
Sorry, please ignore the second part of the original PR message (now edited). This was a left-over of when I thought the xlims were set independently of the ticks. I have also now melded the two commits together as they don't really make sense independently. Regarding |
@@ -168,6 +169,15 @@ | |||
long = int | |||
|
|||
|
|||
# Work around numpy/numpy#6127. | |||
def divmod(x, y): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be private (leading underscore), shouldn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not listed in __all__
, just like a bunch of other functions in the same module (closeto
, decade_{up,down}
, nearest_long
, etc.) which are not prefixed by an underscore but still arguably private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on your argument, we would never use underscores. There are two reasons for using one here:
- With its present name, this function is shadowing a builtin.
- It is a workaround for a bug. Some time after the bug is fixed, we will want to remove this function. If it has an underscore, we don't need to go through a deprecation process, or argue about whether to do so.
Also, I see that divmod is used in 3 other modules; is there reason to use this version in those locations as well? If so, then it could be put in cbook.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am with @efiring, please add an underscore. There are parts of mpl that pre-date the 'underscore means private' convention in python.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A quick grep through all other calls to divmod in the codebase suggests that they are always called either with integer arguments (in which case there's no bug) or with (nontrivial) array arguments (in which case the fix I used is not enough). So I'll just leave it here (as _divmod
) for now.
The ternary-if has also been fixed.
I'm a bit confused by the Travis failure only for 2.7. Everything passes fine for me (https://travis-ci.org/anntzer/matplotlib/builds/99672606), and Appveyor also seems happy. Thoughts? |
It's a random failure not related to your work see #5647 (this was the test__EventCollection__set_linestyle.test again) I have restarted the test |
Apart from my inline comments, this looks like a nice improvement. Thanks for taking it on. |
4fd8a4e
to
846fde4
Compare
|
||
def bin_boundaries(self, vmin, vmax): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to go through a deprecation cycle for bin_boundaries
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. Can we avoid that simply by renaming _raw_ticks back to bin_boundaries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand, we have been saying for a while we want to reduce the size of the public API and this is part of the internal details of how the MaxN locator works so it should be private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note tha the behavior of _raw_ticks
is slightly different from bin_boundaries
(namely it handles properly floating-point inaccuracies), so given that strict backwards compatibility has been broken I think it's a good opportunity to make it private. If you prefer I can leave the (now unused) old implementation of bin_boundaries
in, with a deprecation warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bug fix (handling floating point better) would not in itself require a name change or deprecation, but I'm perfectly happy with the new private name. To be on the safe side, a deprecation cycle of the old name would be a good idea. (I thought it was being used elsewhere, but I haven't found any such instances.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restored bin_boundaries
with a deprecation warning since v2.0.
846fde4
to
dae0b87
Compare
Ok. Thanks for confirming. |
This is a real nice refinement of a detail that's been broken for a very long time. Thanks for taking this on. |
❤️ pep8 ======================================================================
FAIL: matplotlib.tests.test_coding_standards.test_pep8_conformance_installed_files
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/travis/build/matplotlib/matplotlib/venv/lib/python3.5/site-packages/nose/case.py", line 198, in runTest
self.test(*self.arg)
File "/home/travis/build/matplotlib/matplotlib/lib/matplotlib/tests/test_coding_standards.py", line 249, in test_pep8_conformance_installed_files
expected_bad_files=expected_bad_files)
File "/home/travis/build/matplotlib/matplotlib/lib/matplotlib/tests/test_coding_standards.py", line 143, in assert_pep8_conformance
assert_equal(result.total_errors, 0, msg)
AssertionError: 1 != 0 : Found code syntax errors (and warnings):
/home/travis/build/matplotlib/matplotlib/lib/matplotlib/ticker.py:1405:80: E501 line too long (80 > 79 characters)
---------------------------------------------------------------------- |
plt.plot([-.1, .2]) used to pick (in round numbers mode) [-.1, .25] as ylims due to floating point inaccuracies; change it to pick [-.1, .2] (up to floating point inaccuracies). Support for the (unused and deprecated-in-comment) "trim" keyword argument has been dropped as the way ticks are picked has changed. Many test images have changed! Implementation notes: - A bug in numpy's implementation of divmod (numpy/numpy#6127) is worked around. - The implementation of scale_range has also been cleaned. See matplotlib#5767, matplotlib#5738.
dae0b87
to
e67c7fc
Compare
Fixed and rebased. |
IMHO this is ready for merge (Needs a rebase which I did in https://github.com/jenshnielsen/matplotlib/tree/tighter-axes-limits) but otherwise looks good It would be nice to fix issues with numpy 1.11 which this should do. So the question is should we backport this to 2.x or 1.5.x? |
Can you PR the rebase to my branch? |
For the record this was merged via #6192 (which is just a rebase onto master of the time) |
(1)
plt.plot([-.1, .2])
used to pick (in round numbers mode)[-.1, .25]
asylims due to floating point inaccuracies; change it to pick
[-.1, .2]
(up to floating point inaccuracies).
Note that this requires working around a bug in numpy's implementation
of divmod (numpy/numpy#6127).
Many test images have changed!
See #5767.
The following part is incorrect and only left for reference purposes, please ignore.
This implies dropping the (unused and deprecated-in-comment)
"trim" keyword argument.
Also slightly clean up the implementation of scale_range.
Initial work on #5738.