-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Better choice of offset-text. #5785
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Tests cases courtesy of @WeatherGod. Slightly improved numerical accuracy.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -682,34 +682,38 @@ def _compute_offset(self): | |
lmin, lmax = locs.min(), locs.max() | ||
# min, max comparing absolute values (we want division to round towards | ||
# zero so we work on absolute values). | ||
abs_min, abs_max = sorted(map(abs, [lmin, lmax])) | ||
# Only use offset if there are at least two ticks, every tick has the | ||
# same sign, and if the span is small compared to the absolute values. | ||
if (lmin == lmax or lmin <= 0 <= lmax or | ||
(abs_max - abs_min) / abs_max >= 1e-2): | ||
abs_min, abs_max = sorted([abs(float(lmin)), abs(float(lmax))]) | ||
# Only use offset if there are at least two ticks and every tick has | ||
# the same sign. | ||
if lmin == lmax or lmin <= 0 <= lmax: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can move this section above the absolute values to short-circuit a little earlier. |
||
self.offset = 0 | ||
return | ||
sign = math.copysign(1, lmin) | ||
# What is the smallest power of ten such that abs_min and abs_max are | ||
# equal up to that precision? | ||
oom = 10 ** int(math.log10(abs_max) + 1) | ||
# Note: Internally using oom instead of 10 ** oom avoids some numerical | ||
# accuracy issues. | ||
oom = math.ceil(math.log10(abs_max)) | ||
while True: | ||
if abs_min // oom != abs_max // oom: | ||
oom *= 10 | ||
if abs_min // 10 ** oom != abs_max // 10 ** oom: | ||
oom += 1 | ||
break | ||
oom /= 10 | ||
if (abs_max - abs_min) / oom <= 1e-2: | ||
oom -= 1 | ||
if (abs_max - abs_min) / 10 ** oom <= 1e-2: | ||
# Handle the case of straddling a multiple of a large power of ten | ||
# (relative to the span). | ||
# What is the smallest power of ten such that abs_min and abs_max | ||
# at most 1 apart? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/at/are at/ |
||
oom = 10 ** int(math.log10(abs_max) + 1) | ||
oom = math.ceil(math.log10(abs_max)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of re-calculating this (which is maybe expensive?), can you just increase There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Assuming you won't get an infinite loop somehow...) |
||
while True: | ||
if abs_max // oom - abs_min // oom > 1: | ||
oom *= 10 | ||
if abs_max // 10 ** oom - abs_min // 10 ** oom > 1: | ||
oom += 1 | ||
break | ||
oom /= 10 | ||
self.offset = sign * (abs_max // oom) * oom | ||
oom -= 1 | ||
# Only use offset if it saves at least two significant digits. | ||
self.offset = (sign * (abs_max // 10 ** oom) * 10 ** oom | ||
if abs_max // 10 ** oom >= 10 | ||
else 0) | ||
|
||
def _set_orderOfMagnitude(self, range): | ||
# if scientific notation is to be used, find the appropriate exponent | ||
|
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 think all but two test cases are
left < right
; would it also make sense to yield in the reverse order? Also, I don't think there are any tests forleft == right
(though I don't see why that won't work correctly.)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 don't really think I need to support left == right because I don't see how this can ever happen. Other issues handled in new (rebased) commit.
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.
Well, your code does check for the
left == right
case, so it's good so codify what the expected behaviour is in that case. I think the default locators would avoid this situation, but I'm not sure about user-created locators.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.
Sure. I'll wait for #6022 to be merged in so that the tests are actuall run.
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.
updated.