diff options
author | Tyler Reddy <tyler.je.reddy@gmail.com> | 2021-02-01 18:03:04 -0700 |
---|---|---|
committer | Tyler Reddy <tyler.je.reddy@gmail.com> | 2021-02-01 18:03:04 -0700 |
commit | 389b8a75a2792da258440acea1dabcc79620ba8b (patch) | |
tree | b26621a9cb08ffdc346ba2d635008264e75775f3 | |
parent | 044550d603b0d7bbe201d703354dd4857bb3606d (diff) | |
download | numpy-treddy_issue_18273.tar.gz |
MAINT: PR 18282 revisionstreddy_issue_18273
* based on reviewer feedback, instead of explicitly
supporting `memoryview` shuffling via `asarray()`, support
the shuffling implicitly by using `Sequence` instead
of `MutableSequence`
-rw-r--r-- | numpy/random/_generator.pyx | 7 | ||||
-rw-r--r-- | numpy/random/mtrand.pyx | 7 |
2 files changed, 4 insertions, 10 deletions
diff --git a/numpy/random/_generator.pyx b/numpy/random/_generator.pyx index 297642940..1c4689a70 100644 --- a/numpy/random/_generator.pyx +++ b/numpy/random/_generator.pyx @@ -2,7 +2,7 @@ #cython: wraparound=False, nonecheck=False, boundscheck=False, cdivision=True, language_level=3 import operator import warnings -from collections.abc import MutableSequence +from collections.abc import Sequence from cpython.pycapsule cimport PyCapsule_IsValid, PyCapsule_GetPointer from cpython cimport (Py_INCREF, PyFloat_AsDouble) @@ -4398,9 +4398,6 @@ cdef class Generator: char* x_ptr char* buf_ptr - if isinstance(x, memoryview): - x = np.asarray(x) - axis = normalize_axis_index(axis, np.ndim(x)) if type(x) is np.ndarray and x.ndim == 1 and x.size: @@ -4443,7 +4440,7 @@ cdef class Generator: x[i] = buf else: # Untyped path. - if not isinstance(x, MutableSequence): + 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 " diff --git a/numpy/random/mtrand.pyx b/numpy/random/mtrand.pyx index daab2c6f1..df8d7e380 100644 --- a/numpy/random/mtrand.pyx +++ b/numpy/random/mtrand.pyx @@ -2,7 +2,7 @@ #cython: wraparound=False, nonecheck=False, boundscheck=False, cdivision=True, language_level=3 import operator import warnings -from collections.abc import MutableSequence +from collections.abc import Sequence import numpy as np @@ -4436,9 +4436,6 @@ cdef class RandomState: char* x_ptr char* buf_ptr - if isinstance(x, memoryview): - x = np.asarray(x) - if type(x) is np.ndarray and x.ndim == 1 and x.size: # Fast, statically typed path: shuffle the underlying buffer. # Only for non-empty, 1d objects of class ndarray (subclasses such @@ -4476,7 +4473,7 @@ cdef class RandomState: x[i] = buf else: # Untyped path. - if not isinstance(x, MutableSequence): + 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 " |