From 5d77c7446661bb7f7ab358081031bd1a7bddb747 Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Fri, 8 Mar 2024 16:50:30 +0300 Subject: [PATCH 1/2] MAINT: numpy 2.0 moved VisibleDeprecationWarning --- scpdt/impl.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scpdt/impl.py b/scpdt/impl.py index 9524874..3fcea7a 100644 --- a/scpdt/impl.py +++ b/scpdt/impl.py @@ -8,6 +8,13 @@ from . import util +## shim numpy 1.x vs 2.0 +if np.__version__ < "2": + VisibleDeprecationWarning = np.VisibleDeprecationWarning +else: + VisibleDeprecationWarning = np.exceptions.VisibleDeprecationWarning + + # Register the optionflag to skip whole blocks, i.e. # sequences of Examples without an intervening text. SKIPBLOCK = doctest.register_optionflag('SKIPBLOCK') @@ -254,7 +261,7 @@ def check_output(self, want, got, optionflags): with warnings.catch_warnings(): # NumPy's ragged array deprecation of np.array([1, (2, 3)]); # also array abbreviations: try `np.diag(np.arange(1000))` - warnings.simplefilter('ignore', np.VisibleDeprecationWarning) + warnings.simplefilter('ignore', VisibleDeprecationWarning) a_want = eval(want, dict(ns)) a_got = eval(got, dict(ns)) @@ -329,7 +336,7 @@ def _do_check(self, want, got): pass with warnings.catch_warnings(): # NumPy's ragged array deprecation of np.array([1, (2, 3)]) - warnings.simplefilter('ignore', np.VisibleDeprecationWarning) + warnings.simplefilter('ignore', VisibleDeprecationWarning) # This line is the crux of the whole thing. The rest is mostly scaffolding. result = np.allclose(want, got, atol=self.atol, rtol=self.rtol) From f025c9af836e69d500b0d0497d261129d6901e37 Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Fri, 5 Apr 2024 12:09:12 +0300 Subject: [PATCH 2/2] BUG: fix the MPL filter for MPL 3.8.4 In that MPL version (numpy 2.0 compatible?), the text of the user warning has changed into UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown --- scpdt/util.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scpdt/util.py b/scpdt/util.py index 97e6209..7885b14 100644 --- a/scpdt/util.py +++ b/scpdt/util.py @@ -27,8 +27,9 @@ def matplotlib_make_nongui(): try: # Matplotlib issues UserWarnings on plt.show() with a non-GUI backend, # Filter them out. + # UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown with warnings.catch_warnings(): - warnings.filterwarnings("ignore", "Matplotlib", UserWarning) + warnings.filterwarnings("ignore", "FigureCanvasAgg", UserWarning) yield backend finally: if backend: