File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525
2626"""Define functions for patching NumPy with MKL-based NumPy interface."""
2727
28+ import warnings
2829from contextlib import ContextDecorator
2930from threading import Lock , local
3031
@@ -85,11 +86,12 @@ def do_restore(self, verbose=False):
8586 with self ._lock :
8687 local_count = getattr (self ._tls , "local_count" , 0 )
8788 if local_count <= 0 :
88- if verbose :
89- print (
90- "Warning: restore_numpy_random called more times than "
91- "patch_numpy_random in this thread."
92- )
89+ warnings .warn (
90+ "restore_numpy_random called more times than "
91+ "patch_numpy_random in this thread." ,
92+ RuntimeWarning ,
93+ stacklevel = 2 ,
94+ )
9395 return
9496 self ._tls .local_count -= 1
9597 self ._patch_count -= 1
Original file line number Diff line number Diff line change 2424# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525
2626import numpy as np
27+ import pytest
2728
2829import mkl_random
2930import mkl_random .interfaces .numpy_random as _nrand
@@ -103,3 +104,10 @@ def test_patch_reentrant():
103104 finally :
104105 while mkl_random .is_patched ():
105106 mkl_random .restore_numpy_random ()
107+
108+
109+ def test_patch_warning ():
110+ if mkl_random .is_patched ():
111+ pytest .skip ("This test should not be run with a pre-patched NumPy." )
112+ with pytest .warns (RuntimeWarning , match = "restore_numpy_random*" ):
113+ mkl_random .restore_numpy_random ()
You can’t perform that action at this time.
0 commit comments