File mplcursors-10b553e-mpl3.9-pytest8.patch of Package python-mplcursors
From 10b553e7a430f69c1da16e9279c44dd665fd3787 Mon Sep 17 00:00:00 2001
From: Antony Lee <anntzer.lee@gmail.com>
Date: Mon, 8 Apr 2024 11:58:04 +0200
Subject: [PATCH] Fixes for mpl 3.9, pytest 8, GHA node.js 20.
---
##.github/workflows/build.yml | 19 ++++++++++---------
##CHANGELOG.rst | 5 +++++
##pyproject.toml | 2 +-
src/mplcursors/_pick_info.py | 23 ++++++++++++++---------
tests/test_mplcursors.py | 17 ++++-------------
5 files changed, 34 insertions(+), 32 deletions(-)
--- a/src/mplcursors/_pick_info.py
+++ b/src/mplcursors/_pick_info.py
@@ -19,6 +19,7 @@
from matplotlib.backend_bases import RendererBase
from matplotlib.collections import (
LineCollection, PatchCollection, PathCollection)
+from matplotlib.colorbar import Colorbar
from matplotlib.container import BarContainer, ErrorbarContainer, StemContainer
from matplotlib.figure import Figure
from matplotlib.image import AxesImage
@@ -513,14 +514,18 @@ def wrapper(*args, **kwargs):
return wrapper
-def _format_coord_unspaced(ax, xy):
- # Un-space-pad, remove empty coordinates from the output of
- # `format_{x,y}data`, and rejoin with newlines.
- return "\n".join(
- line for line, empty in zip(
- re.split(",? +", ax.format_coord(*xy)),
- itertools.chain(["x=", "y=", "z="], itertools.repeat(None)))
- if line != empty).rstrip()
+def _format_coord_unspaced(ax, pos):
+ # This used to directly post-process the output of format_coord(), but got
+ # switched to handling special projections separately due to the change in
+ # formatting for rectilinear coordinates.
+ if ax.name == "polar":
+ return ax.format_coord(*pos).replace(", ", "\n")
+ elif ax.name == "3d": # Need to retrieve the actual line data coordinates.
+ warnings.warn("3d coordinates not supported yet")
+ return ""
+ else:
+ x, y = pos
+ return f"x={ax.format_xdata(x)}\ny={ax.format_ydata(y)}"
@functools.singledispatch
@@ -547,7 +552,7 @@ def _format_scalarmappable_value(artist, idx): # matplotlib/matplotlib#12473.
if not artist.colorbar:
fig = Figure()
ax = fig.subplots()
- artist.colorbar = fig.colorbar(artist, cax=ax)
+ artist.colorbar = Colorbar(ax, artist)
# This hack updates the ticks without actually paying the cost of
# drawing (RendererBase.draw_path raises NotImplementedError).
try:
diff --git a/tests/test_mplcursors.py b/tests/test_mplcursors.py
index 2ff52fa..0beeeca 100644
--- a/tests/test_mplcursors.py
+++ b/tests/test_mplcursors.py
@@ -1,3 +1,4 @@
+from contextlib import ExitStack
import copy
import functools
import gc
@@ -46,12 +47,6 @@ def cleanup():
plt.close("all")
-def _internal_warnings(record):
- return [
- warning for warning in record
- if Path(mplcursors.__file__).parent in Path(warning.filename).parents]
-
-
def _process_event(name, ax, coords, *args):
ax.viewLim # unstale viewLim.
if name == "__mouse_click__":
@@ -244,9 +239,7 @@ def test_nan(ax, plot_args, click, targets):
def test_repeated_point(ax):
ax.plot([0, 1, 1, 2], [0, 1, 1, 2])
cursor = mplcursors.cursor()
- with pytest.warns(None) as record:
- _process_event("__mouse_click__", ax, (.5, .5), 1)
- assert not _internal_warnings(record)
+ _process_event("__mouse_click__", ax, (.5, .5), 1) # Should not warn.
@pytest.mark.parametrize("origin", ["lower", "upper"])
@@ -388,8 +381,7 @@ def test_dataless_errorbar(ax):
def test_stem(ax):
try: # stem use_line_collection API change.
- with pytest.warns(None):
- ax.stem([1, 2, 3], use_line_collection=True)
+ ax.stem([1, 2, 3], use_line_collection=True)
except TypeError:
ax.stem([1, 2, 3])
cursor = mplcursors.cursor()
@@ -409,10 +401,9 @@ def test_stem(ax):
def test_misc_artists(ax, plotter, warns):
plotter(ax)
cursor = mplcursors.cursor()
- with pytest.warns(None) as record:
+ with pytest.warns(UserWarning) if warns else ExitStack():
_process_event("__mouse_click__", ax, (.5, .5), 1)
assert len(cursor.selections) == 0
- assert len(_internal_warnings(record)) == warns
def test_indexless_projections(fig):