Skip to content

Commit

Permalink
Merge pull request #146 from ev-br/np2.0
Browse files Browse the repository at this point in the history
MAINT: Adapt to NumPy 2.0
  • Loading branch information
ev-br authored Apr 5, 2024
2 parents 2af7ffa + f025c9a commit 1b411f7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions scpdt/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion scpdt/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 1b411f7

Please sign in to comment.