Skip to content

Make rounding behavior consistent #7573

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 3 commits into from
Dec 6, 2016
Merged

Conversation

dopplershift
Copy link
Contributor

The behavior of the builtin round() function changed between python 2 and 3. There are a few places in our code base that use it, resulting in occasional pixel jumps in things like text positioning; this makes image tests have needless noise. The easy solution is to use numpy's round everywhere to give us consistent behavior (and behavior which matches python 3's.) It looks like this had been done in some places, but not these last few.

I also removed an implementation of round() in the TkAgg backend which was unused. Some may consider this an API break, so I'm open to eliminating this commit or making TkAgg's an alias to numpy's.

There's absolutely no reason to have our own implementation of this.
@dopplershift dopplershift added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Dec 5, 2016
@dopplershift dopplershift added this to the 2.0 (style change major release) milestone Dec 5, 2016
@NelleV
Copy link
Member

NelleV commented Dec 6, 2016

I'm fine with the change, but this is really not release critical and should really not delay the release (which is what release critical means).

@tacaswell
Copy link
Member

I am a bit disappointed that this does not break any tests.

Removing round from tkagg seems ok to me, people should not be relying on that, would not hurt to add an API change note.

@dopplershift
Copy link
Contributor Author

I was pretty flabbergasted about the lack of any test failures here. I have a case I can add for the agg renderer's draw_text() method if you like.

I'll add an API change note.

@tacaswell
Copy link
Member

I wonder if the tests that should be failing are the ones that have slightly higher tolerances now?

@efiring
Copy link
Member

efiring commented Dec 6, 2016

The two tests for which I raised the tolerance were failing only on Windows, and their tolerances are nonzero only on Windows.

@dopplershift
Copy link
Contributor Author

It was only for dpi in the ~300 range for me to get images that actually showed a difference, at least for my test. Also, don't most of our image tests turn off the text for better consistency. It's possible that's not nearly so necessary with this change.

@dopplershift dopplershift changed the title Make rounding behavior consistent [MRG + 1]Make rounding behavior consistent Dec 6, 2016
@@ -27,7 +27,7 @@ def __init__(self, dates, fmt='%Y-%m-%d'):

def __call__(self, x, pos=0):
'Return the label for time x at position pos'
ind = int(round(x))
Copy link
Member

Choose a reason for hiding this comment

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

Do you mind if I push to your branch to change the import of numpy to follow the standards?

@NelleV
Copy link
Member

NelleV commented Dec 6, 2016

LGTM 👍
Let me know for the numpy stuff - I can also just create a brand new PR for that.

@NelleV NelleV changed the title [MRG + 1]Make rounding behavior consistent [MRG + 2] Make rounding behavior consistent Dec 6, 2016
The behavior of the builtin round() function changed between python 2
and 3. Use numpy's, which matches python 3's, so that we have consistent
rounding behavior between python versions. This helps keep image test
results (here or downstream) consistent between python versions.
@dopplershift
Copy link
Contributor Author

@NelleV I went ahead and updated the numpy import in that example.

@efiring efiring changed the title [MRG + 2] Make rounding behavior consistent Make rounding behavior consistent Dec 6, 2016
@efiring efiring merged commit cb6964d into matplotlib:v2.x Dec 6, 2016
@dopplershift dopplershift deleted the fix-round branch December 6, 2016 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants