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.
doesn't need the else. Also, I'd invert this and flag the special case
if size <= 0:
return return 2**31 - 1There was a problem hiding this comment.
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.09375There was a problem hiding this comment.
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.
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.
I also find the if else statement clearer.
There was a problem hiding this comment.
shrugs wasn't gonna put up a fight
| return int(np.floor(length / size)) | ||
| if size > 0: | ||
| return int(np.floor(length / size)) | ||
| 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. |
lib/matplotlib/tests/test_axes.py
Outdated
|
|
||
|
|
||
| @cleanup | ||
| def test_size0_ticks(): |
There was a problem hiding this comment.
can you name this test_tick_space_size_0 so it refers to the function being tested?
There was a problem hiding this comment.
:) LGTM, just waiting for the tests to clear
|
👍 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.pyin_raw_ticks.pyin a minimization, it is sufficient to just return a 'big' number. The full traceback we are seeing in the xonsh test suite is,