summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2021-02-18 19:34:51 -0600
committerSebastian Berg <sebastian@sipsolutions.net>2021-02-19 11:10:45 -0600
commit60e82e19df952ec13272afe6bf345ac21442ce8e (patch)
tree53f4c236ad9890528487d80ea2b1ffdae7df411a /numpy
parent740a8cf8c103e4e329021802af007295261b0da2 (diff)
downloadnumpy-60e82e19df952ec13272afe6bf345ac21442ce8e.tar.gz
BUG: fix stacklevel in warning within random.shuffle
Cython does _not_ add a new stacklevel (at least at this time), so `stacklevel=1` (or ommiting it) is, maybe surprisingly, correct.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/random/_generator.pyx11
-rw-r--r--numpy/random/mtrand.pyx11
2 files changed, 12 insertions, 10 deletions
diff --git a/numpy/random/_generator.pyx b/numpy/random/_generator.pyx
index a7d98e2ed..8d440d4f7 100644
--- a/numpy/random/_generator.pyx
+++ b/numpy/random/_generator.pyx
@@ -4445,11 +4445,12 @@ cdef class Generator:
if not isinstance(x, Sequence):
# See gh-18206. We may decide to deprecate here in the future.
warnings.warn(
- "`x` isn't a recognized object; `shuffle` is not guaranteed "
- "to behave correctly. E.g., non-numpy array/tensor objects "
- "with view semantics may contain duplicates after shuffling.",
- UserWarning, stacklevel=2
- )
+ f"you are shuffling a '{type(x).__name__}' object "
+ "which is not a subclass of 'Sequence'; "
+ "`shuffle` is not guaranteed to behave correctly. "
+ "E.g., non-numpy array/tensor objects with view semantics "
+ "may contain duplicates after shuffling.",
+ UserWarning, stacklevel=1) # Cython does not add a level
if axis != 0:
raise NotImplementedError("Axis argument is only supported "
diff --git a/numpy/random/mtrand.pyx b/numpy/random/mtrand.pyx
index df8d7e380..a7436aa39 100644
--- a/numpy/random/mtrand.pyx
+++ b/numpy/random/mtrand.pyx
@@ -4476,11 +4476,12 @@ cdef class RandomState:
if not isinstance(x, Sequence):
# See gh-18206. We may decide to deprecate here in the future.
warnings.warn(
- "`x` isn't a recognized object; `shuffle` is not guaranteed "
- "to behave correctly. E.g., non-numpy array/tensor objects "
- "with view semantics may contain duplicates after shuffling.",
- UserWarning, stacklevel=2
- )
+ f"you are shuffling a '{type(x).__name__}' object "
+ "which is not a subclass of 'Sequence'; "
+ "`shuffle` is not guaranteed to behave correctly. "
+ "E.g., non-numpy array/tensor objects with view semantics "
+ "may contain duplicates after shuffling.",
+ UserWarning, stacklevel=1) # Cython does not add a level
with self.lock:
for i in reversed(range(1, n)):