Skip to content
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

Unit tests fail with numpy 1.19 and matplotlib 3.3.0 #26

Closed
bnavigator opened this issue Jul 21, 2020 · 6 comments
Closed

Unit tests fail with numpy 1.19 and matplotlib 3.3.0 #26

bnavigator opened this issue Jul 21, 2020 · 6 comments

Comments

@bnavigator
Copy link

There are comparison failures for formatted coordinates and a non iterable LineCollection

numpy 1.19.0
matplotlib 3.3.0
(system packages on openSUSE Tumbleweed)

[   38s] + pytest-3.8 --ignore=_build.python2 --ignore=_build.python3 --ignore=_build.pypy3 -v
[   38s] ============================= test session starts ==============================
[   38s] platform linux -- Python 3.8.3, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 -- /usr/bin/python3
[   38s] cachedir: .pytest_cache
[   38s] rootdir: /home/abuild/rpmbuild/BUILD/mplcursors-0.3, inifile: setup.cfg
[   39s] collecting ... collected 70 items
[   39s] 
[   39s] tests/test_mplcursors.py::test_containerartist PASSED                    [  1%]
[   39s] tests/test_mplcursors.py::test_selection_identity_comparison PASSED      [  2%]
[   39s] tests/test_mplcursors.py::test_degenerate_inputs PASSED                  [  4%]
[   39s] tests/test_mplcursors.py::test_line[Axes.plot] PASSED                    [  5%]
[   40s] tests/test_mplcursors.py::test_line[Axes.fill] PASSED                    [  7%]
[   40s] tests/test_mplcursors.py::test_scatter[<lambda>] PASSED                  [  8%]
[   40s] tests/test_mplcursors.py::test_scatter[Axes.scatter] PASSED              [ 10%]
[   40s] tests/test_mplcursors.py::test_scatter_text FAILED                       [ 11%]
[   40s] tests/test_mplcursors.py::test_steps_index PASSED                        [ 12%]
[   40s] tests/test_mplcursors.py::test_steps_pre PASSED                          [ 14%]
[   41s] tests/test_mplcursors.py::test_steps_mid PASSED                          [ 15%]
[   41s] tests/test_mplcursors.py::test_steps_post PASSED                         [ 17%]
[   41s] tests/test_mplcursors.py::test_line_single_point[-] PASSED               [ 18%]
[   41s] tests/test_mplcursors.py::test_line_single_point[o] PASSED               [ 20%]
[   41s] tests/test_mplcursors.py::test_nan[plot_args0-click0-targets0] PASSED    [ 21%]
[   41s] tests/test_mplcursors.py::test_nan[plot_args1-click1-targets1] PASSED    [ 22%]
[   41s] tests/test_mplcursors.py::test_nan[plot_args2-click2-targets2] PASSED    [ 24%]
[   41s] tests/test_mplcursors.py::test_repeated_point PASSED                     [ 25%]
[   42s] tests/test_mplcursors.py::test_image[lower] FAILED                       [ 27%]
[   43s] tests/test_mplcursors.py::test_image[upper] FAILED                       [ 28%]
[   44s] tests/test_mplcursors.py::test_image_rgb PASSED                          [ 30%]
[   44s] tests/test_mplcursors.py::test_image_subclass PASSED                     [ 31%]
[   45s] tests/test_mplcursors.py::test_linecollection PASSED                     [ 32%]
[   45s] tests/test_mplcursors.py::test_patchcollection PASSED                    [ 34%]
[   45s] tests/test_mplcursors.py::test_quiver_and_barbs[Axes.quiver] FAILED      [ 35%]
[   45s] tests/test_mplcursors.py::test_quiver_and_barbs[Axes.barbs] PASSED       [ 37%]
[   45s] tests/test_mplcursors.py::test_bar[Axes.bar-order0] PASSED               [ 38%]
[   45s] tests/test_mplcursors.py::test_bar[Axes.barh-order1] PASSED              [ 40%]
[   46s] tests/test_mplcursors.py::test_errorbar FAILED                           [ 41%]
[   46s] tests/test_mplcursors.py::test_dataless_errorbar PASSED                  [ 42%]
[   46s] tests/test_mplcursors.py::test_stem FAILED                               [ 44%]
[   46s] tests/test_mplcursors.py::test_misc_artists[<lambda>-False] PASSED       [ 45%]
[   46s] tests/test_mplcursors.py::test_misc_artists[<lambda>-True] PASSED        [ 47%]
[   48s] tests/test_mplcursors.py::test_indexless_projections PASSED              [ 48%]
[   48s] tests/test_mplcursors.py::test_cropped_by_axes PASSED                    [ 50%]
[   54s] tests/test_mplcursors.py::test_move[Axes.plot] PASSED                    [ 51%]
[   60s] tests/test_mplcursors.py::test_move[Axes.scatter] PASSED                 [ 52%]
[   66s] tests/test_mplcursors.py::test_move[Axes.errorbar] PASSED                [ 54%]
[   66s] tests/test_mplcursors.py::test_hover PASSED                              [ 55%]
[   67s] tests/test_mplcursors.py::test_highlight[Axes.plot] PASSED               [ 57%]
[   67s] tests/test_mplcursors.py::test_highlight[Axes.scatter] PASSED            [ 58%]
[   67s] tests/test_mplcursors.py::test_misc_artists_highlight PASSED             [ 60%]
[   67s] tests/test_mplcursors.py::test_callback PASSED                           [ 61%]
[   68s] tests/test_mplcursors.py::test_remove_while_adding PASSED                [ 62%]
[   68s] tests/test_mplcursors.py::test_no_duplicate PASSED                       [ 64%]
[   69s] tests/test_mplcursors.py::test_remove_multiple_overlapping PASSED        [ 65%]
[   69s] tests/test_mplcursors.py::test_autoalign PASSED                          [ 67%]
[   69s] tests/test_mplcursors.py::test_drag PASSED                               [ 68%]
[   69s] tests/test_mplcursors.py::test_removed_artist PASSED                     [ 70%]
[   69s] tests/test_mplcursors.py::test_remove_cursor PASSED                      [ 71%]
[   71s] tests/test_mplcursors.py::test_keys PASSED                               [ 72%]
[   71s] tests/test_mplcursors.py::test_convenience PASSED                        [ 74%]
[   71s] tests/test_mplcursors.py::test_invalid_args PASSED                       [ 75%]
[   71s] tests/test_mplcursors.py::test_multiple_figures PASSED                   [ 77%]
[   71s] tests/test_mplcursors.py::test_gc PASSED                                 [ 78%]
[   72s] tests/test_mplcursors.py::test_example[examples/change_popup_color.py] PASSED [ 80%]
[   73s] tests/test_mplcursors.py::test_example[examples/highlight.py] PASSED     [ 81%]
[   73s] tests/test_mplcursors.py::test_example[examples/nondraggable.py] PASSED  [ 82%]
[   74s] tests/test_mplcursors.py::test_example[examples/scatter.py] PASSED       [ 84%]
[   74s] tests/test_mplcursors.py::test_example[examples/image.py] PASSED         [ 85%]
[   75s] tests/test_mplcursors.py::test_example[examples/bar.py] PASSED           [ 87%]
[   75s] tests/test_mplcursors.py::test_example[examples/labeled_points.py] PASSED [ 88%]
[   76s] tests/test_mplcursors.py::test_example[examples/basic.py] PASSED         [ 90%]
[   77s] tests/test_mplcursors.py::test_example[examples/date.py] PASSED          [ 91%]
[   77s] tests/test_mplcursors.py::test_example[examples/keyboard_shortcuts.py] PASSED [ 92%]
[   78s] tests/test_mplcursors.py::test_example[examples/hover.py] PASSED         [ 94%]
[   78s] tests/test_mplcursors.py::test_example[examples/artist_labels.py] PASSED [ 95%]
[   79s] tests/test_mplcursors.py::test_example[examples/contour.py] PASSED       [ 97%]
[   79s] tests/test_mplcursors.py::test_example[examples/step.py] PASSED          [ 98%]
[   80s] tests/test_mplcursors.py::test_example[examples/paired_highlight.py] PASSED [100%]
[   80s] 
[   80s] =================================== FAILURES ===================================
[   80s] ______________________________ test_scatter_text _______________________________
[   80s] 
[   80s] ax = <AxesSubplot:>
[   80s] 
[   80s]     def test_scatter_text(ax):
[   80s]         ax.scatter([0, 1], [0, 1], c=[2, 3])
[   80s]         cursor = mplcursors.cursor()
[   80s]         _process_event("__mouse_click__", ax, (0, 0), 1)
[   80s] >       assert cursor.selections[0].annotation.get_text() == "x=0\ny=0\n[2]"
[   80s] E       AssertionError: assert 'x=0.000\ny=0.000\n[2.000]' == 'x=0\ny=0\n[2]'
[   80s] E         - x=0
[   80s] E         - y=0
[   80s] E         - [2]
[   80s] E         + x=0.000
[   80s] E         + y=0.000
[   80s] E         + [2.000]
[   80s] 
[   80s] tests/test_mplcursors.py:166: AssertionError
[   80s] ______________________________ test_image[lower] _______________________________
[   80s] 
[   80s] ax = <AxesSubplot:>, origin = 'lower'
[   80s] 
[   80s]     @pytest.mark.parametrize("origin", ["lower", "upper"])
[   80s]     def test_image(ax, origin):
[   80s]         array = np.arange(6).reshape((3, 2))
[   80s]         ax.imshow(array, origin=origin)
[   80s]     
[   80s]         cursor = mplcursors.cursor()
[   80s]         # Annotation text includes image value.
[   80s]         _process_event("__mouse_click__", ax, (.25, .25), 1)
[   80s]         sel, = cursor.selections
[   80s]         assert (_parse_annotation(sel, r"x=(.*)\ny=(.*)\n\[0\]")
[   80s]                 == approx((.25, .25)))
[   80s]         # Moving around.
[   80s]         _process_event("key_press_event", ax, (.123, .456), "shift+right")
[   80s]         sel, = cursor.selections
[   80s] >       assert sel.annotation.get_text() == "x=1\ny=0\n[1]"
[   80s] E       AssertionError: assert 'x=1.000\ny=0.000\n[1]' == 'x=1\ny=0\n[1]'
[   80s] E         - x=1
[   80s] E         - y=0
[   80s] E         + x=1.000
[   80s] E         + y=0.000
[   80s] E           [1]
[   80s] 
[   80s] tests/test_mplcursors.py:268: AssertionError
[   80s] ______________________________ test_image[upper] _______________________________
[   80s] 
[   80s] ax = <AxesSubplot:>, origin = 'upper'
[   80s] 
[   80s]     @pytest.mark.parametrize("origin", ["lower", "upper"])
[   80s]     def test_image(ax, origin):
[   80s]         array = np.arange(6).reshape((3, 2))
[   80s]         ax.imshow(array, origin=origin)
[   80s]     
[   80s]         cursor = mplcursors.cursor()
[   80s]         # Annotation text includes image value.
[   80s]         _process_event("__mouse_click__", ax, (.25, .25), 1)
[   80s]         sel, = cursor.selections
[   80s]         assert (_parse_annotation(sel, r"x=(.*)\ny=(.*)\n\[0\]")
[   80s]                 == approx((.25, .25)))
[   80s]         # Moving around.
[   80s]         _process_event("key_press_event", ax, (.123, .456), "shift+right")
[   80s]         sel, = cursor.selections
[   80s] >       assert sel.annotation.get_text() == "x=1\ny=0\n[1]"
[   80s] E       AssertionError: assert 'x=1.000\ny=0.000\n[1]' == 'x=1\ny=0\n[1]'
[   80s] E         - x=1
[   80s] E         - y=0
[   80s] E         + x=1.000
[   80s] E         + y=0.000
[   80s] E           [1]
[   80s] 
[   80s] tests/test_mplcursors.py:268: AssertionError
[   80s] ______________________ test_quiver_and_barbs[Axes.quiver] ______________________
[   80s] 
[   80s] ax = <AxesSubplot:>, plotter = <function Axes.quiver at 0x7fc85b317550>
[   80s] 
[   80s]     @pytest.mark.parametrize("plotter", [Axes.quiver, Axes.barbs])
[   80s]     def test_quiver_and_barbs(ax, plotter):
[   80s]         plotter(ax, range(3), range(3))
[   80s]         cursor = mplcursors.cursor()
[   80s]         _process_event("__mouse_click__", ax, (.5, 0), 1)
[   80s]         assert len(cursor.selections) == 0
[   80s]         _process_event("__mouse_click__", ax, (1, 0), 1)
[   80s] >       assert cursor.selections[0].annotation.get_text() == "x=1\ny=0\n(1, 1)"
[   80s] E       AssertionError: assert 'x=1.000\ny=0.0000\n(1, 1)' == 'x=1\ny=0\n(1, 1)'
[   80s] E         - x=1
[   80s] E         - y=0
[   80s] E         + x=1.000
[   80s] E         + y=0.0000
[   80s] E           (1, 1)
[   80s] 
[   80s] tests/test_mplcursors.py:342: AssertionError
[   80s] ________________________________ test_errorbar _________________________________
[   80s] 
[   80s] ax = <AxesSubplot:>
[   80s] 
[   80s]     def test_errorbar(ax):
[   80s]         ax.errorbar(range(2), range(2), [(1, 1), (1, 2)])
[   80s]         cursor = mplcursors.cursor()
[   80s]         assert len(cursor.artists) == 1
[   80s]         _process_event("__mouse_click__", ax, (0, 2), 1)
[   80s]         assert len(cursor.selections) == 0
[   80s]         _process_event("__mouse_click__", ax, (.5, .5), 1)
[   80s]         assert cursor.selections[0].target == approx((.5, .5))
[   80s]         assert (_parse_annotation(cursor.selections[0], "x=(.*)\ny=(.*)")
[   80s]                 == approx((.5, .5)))
[   80s]         _process_event("__mouse_click__", ax, (0, 1), 1)
[   80s]         assert cursor.selections[0].target == approx((0, 0))
[   80s] >       assert cursor.selections[0].annotation.get_text() == "x=0\ny=$0\\pm1$"
[   80s] E       AssertionError: assert 'x=0.000\ny=$....00}^{+1.00}$' == 'x=0\ny=$0\\pm1$'
[   80s] E         - x=0
[   80s] E         - y=$0\pm1$
[   80s] E         + x=0.000
[   80s] E         + y=$0.00_{+−1.00}^{+1.00}$
[   80s] 
[   80s] tests/test_mplcursors.py:370: AssertionError
[   80s] __________________________________ test_stem ___________________________________
[   80s] 
[   80s] ax = <AxesSubplot:>
[   80s] 
[   80s]     def test_stem(ax):
[   80s]         with pytest.warns(None):  # stem use_line_collection API change.
[   80s]             ax.stem([1, 2, 3])
[   80s]         cursor = mplcursors.cursor()
[   80s]         assert len(cursor.artists) == 1
[   80s] >       _process_event("__mouse_click__", ax, (.5, .5), 1)
[   80s] 
[   80s] tests/test_mplcursors.py:390: 
[   80s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   80s] tests/test_mplcursors.py:63: in _process_event
[   80s]     _process_event("button_press_event", ax, coords, *args)
[   80s] tests/test_mplcursors.py:74: in _process_event
[   80s]     ax.figure.canvas.callbacks.process(name, event)
[   80s] /usr/lib64/python3.8/site-packages/matplotlib/cbook/__init__.py:224: in process
[   80s]     func(*args, **kwargs)
[   80s] ../../BUILDROOT/python-mplcursors-0.3-11.1.x86_64/usr/lib/python3.8/site-packages/mplcursors/_mplcursors.py:485: in _nonhover_handler
[   80s]     self._on_select_button_press(event)
[   80s] ../../BUILDROOT/python-mplcursors-0.3-11.1.x86_64/usr/lib/python3.8/site-packages/mplcursors/_mplcursors.py:520: in _on_select_button_press
[   80s]     pi = _pick_info.compute_pick(artist, per_axes_event[artist.axes])
[   80s] /usr/lib64/python3.8/functools.py:875: in wrapper
[   80s]     return dispatch(args[0].__class__)(*args, **kw)
[   80s] ../../BUILDROOT/python-mplcursors-0.3-11.1.x86_64/usr/lib/python3.8/site-packages/mplcursors/_pick_info.py:419: in _
[   80s]     return compute_pick(artist.container, event)
[   80s] /usr/lib64/python3.8/functools.py:875: in wrapper
[   80s]     return dispatch(args[0].__class__)(*args, **kw)
[   80s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   80s] 
[   80s] container = <StemContainer object of 3 artists>
[   80s] event = <matplotlib.backend_bases.MouseEvent object at 0x7fc85b0b03d0>
[   80s] 
[   80s]     @compute_pick.register(StemContainer)
[   80s]     def _(container, event):
[   80s]         sel = compute_pick(container.markerline, event)
[   80s]         if sel:
[   80s]             return sel
[   80s]         idx_sel = min(filter(lambda idx_sel: idx_sel[1] is not None,
[   80s]                              ((idx, compute_pick(line, event))
[   80s] >                             for idx, line in enumerate(container.stemlines))),
[   80s]                       key=lambda idx_sel: idx_sel[1].dist, default=None)
[   80s] E       TypeError: 'LineCollection' object is not iterable
[   80s] 
[   80s] ../../BUILDROOT/python-mplcursors-0.3-11.1.x86_64/usr/lib/python3.8/site-packages/mplcursors/_pick_info.py:469: TypeError
[   80s] =========================== short test summary info ============================
[   80s] FAILED tests/test_mplcursors.py::test_scatter_text - AssertionError: assert '...
[   80s] FAILED tests/test_mplcursors.py::test_image[lower] - AssertionError: assert '...
[   80s] FAILED tests/test_mplcursors.py::test_image[upper] - AssertionError: assert '...
[   80s] FAILED tests/test_mplcursors.py::test_quiver_and_barbs[Axes.quiver] - Asserti...
[   80s] FAILED tests/test_mplcursors.py::test_errorbar - AssertionError: assert 'x=0....
[   80s] FAILED tests/test_mplcursors.py::test_stem - TypeError: 'LineCollection' obje...
[   80s] ======================== 6 failed, 64 passed in 41.68s =====
@anntzer
Copy link
Owner

anntzer commented Jul 21, 2020

This should all be fixed as of master. Can you confirm?

@bnavigator
Copy link
Author

Yes you are correct. Latest master daba5f3 passes all unit tests.

Sorry, I looked into the closed issues and PRs but did not skim the commit history.

Are you going to make a release soon or should I try to backport the relevant commits to 0.3?

@anntzer
Copy link
Owner

anntzer commented Jul 21, 2020

I'll wait a bit for setuptools to figure out what they want to do with pypa/setuptools#2259.

@bnavigator
Copy link
Author

Hmm, I applied b12a791 but I still get the following error on i586 only (!?)

[  156s] =================================== FAILURES ===================================
[  156s] ________________________________ test_image_rgb ________________________________
[  156s] 
[  156s] ax = <AxesSubplot:>
[  156s] 
[  156s]     def test_image_rgb(ax):
[  156s]         ax.imshow([[[.1, .2, .3], [.4, .5, .6]]])
[  156s]         cursor = mplcursors.cursor()
[  156s]         _process_event("__mouse_click__", ax, (0, 0), 1)
[  156s]         sel, = cursor.selections
[  156s] >       assert _parse_annotation(
[  156s]             sel, r"x=(.*)\ny=(.*)\n\[0.1, 0.2, 0.3\]") == approx((0, 0))
[  156s] 
[  156s] tests/test_mplcursors.py:299: 
[  156s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[  156s] 
[  156s] sel = Selection(artist=<matplotlib.image.AxesImage object at 0xad4f0f10>, target=AttrArray([4.16333634e-17, 1.62337662e-03]), dist=0, annotation=Text(-15, 15, 'x=4.e−17\ny=0.002\n[0.1, 0.2, 0.3]'), extras=[])
[  156s] regex = 'x=(.*)\\ny=(.*)\\n\\[0.1, 0.2, 0.3\\]'
[  156s] 
[  156s]     def _parse_annotation(sel, regex):
[  156s]         result = re.fullmatch(regex, sel.annotation.get_text())
[  156s]         assert result, \
[  156s]             "{!r} doesn't match {!r}".format(sel.annotation.get_text(), regex)
[  156s] >       return tuple(map(float, result.groups()))
[  156s] E       ValueError: could not convert string to float: '4.e−17'
[  156s] 
[  156s] tests/test_mplcursors.py:91: ValueError

@anntzer
Copy link
Owner

anntzer commented Jul 21, 2020

does

diff --git i/tests/test_mplcursors.py w/tests/test_mplcursors.py
index 2f53f14..940eb13 100644
--- i/tests/test_mplcursors.py
+++ w/tests/test_mplcursors.py
@@ -26,6 +26,7 @@ approx = functools.partial(pytest.approx, abs=1e-2)
 
 @pytest.fixture
 def fig():
+    plt.rcParams["axes.unicode_minus"] = False
     fig = plt.figure(1)
     fig.canvas.callbacks.exception_handler = None
     return fig

help?

@bnavigator
Copy link
Author

bnavigator commented Jul 21, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants