-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Allow zero sized ticks #7959
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
Allow zero sized ticks #7959
Conversation
Can you please add (py.test) tests? |
can you please point me where there are similar tests? I know nothing about testing mpl these days. thanks! |
return int(np.floor(length / size)) | ||
if size > 0: | ||
return int(np.floor(length / size)) | ||
else: |
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.
doesn't need the else. Also, I'd invert this and flag the special case
if size <= 0:
return return 2**31 - 1
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.
For what it is worth, keeping the else clause is about 10% faster. The order shouldn't matter and doesn't affect timings that I have noticed.
scopatz@artemis ~ $ def f(x):
`·.,¸,.·*¯`·.,¸,.·* if x:
`·.,¸,.·*¯`·.,¸,.·* return 42
`·.,¸,.·*¯`·.,¸,.·* else:
`·.,¸,.·*¯`·.,¸,.·* return 0
`·.,¸,.·*¯`·.,¸,.·*
`·.,¸,.·*¯`·.,¸,.·*
scopatz@artemis ~ $ def g(x):
`·.,¸,.·*¯`·.,¸,.·* if x:
`·.,¸,.·*¯`·.,¸,.·* return 42
`·.,¸,.·*¯`·.,¸,.·* return 0
`·.,¸,.·*¯`·.,¸,.·*
scopatz@artemis ~ $ timeit! f(True)
10000000 loops, best of 3: 57.6 ns per loop
scopatz@artemis ~ $ timeit! g(True)
10000000 loops, best of 3: 63.6 ns per loop
scopatz@artemis ~ $ timeit! f(False)
10000000 loops, best of 3: 58 ns per loop
scopatz@artemis ~ $ timeit! g(False)
10000000 loops, best of 3: 64 ns per loop
scopatz@artemis ~ $ 1 - (58.0/64)
0.09375
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 know order doesn't matter, I just think from a clarity/maintance point of view the special case should be in the if.
Though now I'm wondering if there's a way to modify int(np.floor(length/size))
such that it'll catch the size<=0 case
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 is probably a bit of apples and oranges since I find the way I wrote it clearest. I looked around for something in numpy that would cast infinities to integers better, but I didn't come up with anything.
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.
shrugs
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 also find the if else statement clearer.
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.
shrugs wasn't gonna put up a fight
return int(np.floor(length / size)) | ||
if size > 0: | ||
return int(np.floor(length / size)) | ||
else: |
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.
same, don't need else
:/ ugh, unfortunately there are no tests for axis, so at least as a first pass maybe test that savefig now behaves as expected. Savefig tests are in test_backend_ps.py but the fix should maybe be in base if it applies everywhere. |
Hi @scopatz |
Thanks @NelleV! I have added a minimal test that reproduces the issue. Let me know if this needs anything else. |
@@ -2341,6 +2341,16 @@ def test_manage_xticks(): | ||
assert_array_equal(old_xlim, new_xlim) | ||
|
||
|
||
@cleanup | ||
def test_size0_ticks(): |
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.
can you name this test_tick_space_size_0
so it refers to the function being tested?
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.
done.
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.
:) LGTM, just waiting for the tests to clear
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.
Thanks @scopatz !
👍 Looks good, thanks @scopatz |
Thanks All! |
backported to v2.0.x as 729d219 |
Woops, sorry for missing the backport and thanks for picking it up. |
This addresses an issue with savefig() when there are no ticks present. In axis.py,
if
size == 0
, then the this will be effectively,int(np.floor(np.infty))
which fails on integer conversion with,Since this is directly used in
ticker.py
in_raw_ticks.py
in a minimization, it is sufficient to just return a 'big' number. The full traceback we are seeing in the xonsh test suite is,