summaryrefslogtreecommitdiff
path: root/numpy/random/tests
diff options
context:
space:
mode:
authorKevin Sheppard <kevin.k.sheppard@gmail.com>2018-10-05 12:15:04 +0100
committerKevin Sheppard <kevin.k.sheppard@gmail.com>2018-10-10 00:34:39 +0100
commitec69d79693c1dbc98e35f7eafe67b8832fb969d1 (patch)
tree966494857f352d5fca6a5ee766633bf8bd652101 /numpy/random/tests
parent8a560b91cf9304fded4abfd9ca0f579e72711a5c (diff)
downloadnumpy-ec69d79693c1dbc98e35f7eafe67b8832fb969d1.tar.gz
BUG: Fix in-place permutation
Alter test to check if arrays are the same to avoid in-place of some array-like objects closes #11975
Diffstat (limited to 'numpy/random/tests')
-rw-r--r--numpy/random/tests/test_regression.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/numpy/random/tests/test_regression.py b/numpy/random/tests/test_regression.py
index 3b4b4ed40..ca9bbbc71 100644
--- a/numpy/random/tests/test_regression.py
+++ b/numpy/random/tests/test_regression.py
@@ -133,3 +133,25 @@ class TestRegression(object):
# Force Garbage Collection - should not segfault.
import gc
gc.collect()
+
+ def test_permutation_subclass(self):
+ class N(np.ndarray):
+ pass
+
+ np.random.seed(1)
+ orig = np.arange(3).view(N)
+ perm = np.random.permutation(orig)
+ assert_array_equal(perm, np.array([0, 2, 1]))
+ assert_array_equal(orig, np.arange(3).view(N))
+
+ class M(object):
+ a = np.arange(5)
+
+ def __array__(self):
+ return self.a
+
+ np.random.seed(1)
+ m = M()
+ perm = np.random.permutation(m)
+ assert_array_equal(perm, np.array([2, 1, 4, 0, 3]))
+ assert_array_equal(m.__array__(), np.arange(5))