summaryrefslogtreecommitdiff
path: root/numpy/random
diff options
context:
space:
mode:
authorWenjamin Petrenko <wenjamin.petrenko@yandex.ru>2018-08-18 23:03:11 +0300
committerWenjamin Petrenko <wenjamin.petrenko@yandex.ru>2018-08-18 23:03:11 +0300
commitefd47971b8d778263cb12ffe42fb89edcb75b765 (patch)
tree6096784f4dc57df714f554cd150b47adff7ec599 /numpy/random
parent3026928b86b12543e9e4738ed91bc2a2cd6cb07f (diff)
downloadnumpy-efd47971b8d778263cb12ffe42fb89edcb75b765.tar.gz
BUG: Make `random.shuffle` work on 1-D instances of `ndarray` subclasses
Closes #11442.
Diffstat (limited to 'numpy/random')
-rw-r--r--numpy/random/mtrand/mtrand.pyx5
-rw-r--r--numpy/random/tests/test_random.py4
2 files changed, 6 insertions, 3 deletions
diff --git a/numpy/random/mtrand/mtrand.pyx b/numpy/random/mtrand/mtrand.pyx
index 04d6c6615..f83693e4e 100644
--- a/numpy/random/mtrand/mtrand.pyx
+++ b/numpy/random/mtrand/mtrand.pyx
@@ -4836,9 +4836,8 @@ cdef class RandomState:
self._shuffle_raw(n, sizeof(npy_intp), stride, x_ptr, buf_ptr)
else:
self._shuffle_raw(n, itemsize, stride, x_ptr, buf_ptr)
- elif isinstance(x, np.ndarray) and x.ndim > 1 and x.size:
- # Multidimensional ndarrays require a bounce buffer.
- buf = np.empty_like(x[0])
+ elif isinstance(x, np.ndarray) and x.ndim and x.size:
+ buf = np.empty_like(x[0,...])
with self.lock:
for i in reversed(range(1, n)):
j = rk_interval(i, self.internal_state)
diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py
index 2e0885024..06250bc22 100644
--- a/numpy/random/tests/test_random.py
+++ b/numpy/random/tests/test_random.py
@@ -467,6 +467,10 @@ class TestRandomDist(object):
lambda x: [(i, i) for i in x],
lambda x: np.asarray([[i, i] for i in x]),
lambda x: np.vstack([x, x]).T,
+ # gh-11442
+ lambda x: (np.asarray([(i, i) for i in x],
+ [("a", int), ("b", int)])
+ .view(np.recarray)),
# gh-4270
lambda x: np.asarray([(i, i) for i in x],
[("a", object, 1),