summaryrefslogtreecommitdiff
path: root/numpy/random/tests
diff options
context:
space:
mode:
authorwarren <warren.weckesser@gmail.com>2021-12-18 11:43:50 -0500
committerwarren <warren.weckesser@gmail.com>2021-12-18 13:45:56 -0500
commit29761eb8c2102ae50a164a1e57cdfefebb18143f (patch)
tree43a51c3049ec70078ea13b9e3bad0ab1e98b98fe /numpy/random/tests
parent0302205105161c6bbae5d45fe4e7a5a624f0dbf4 (diff)
downloadnumpy-29761eb8c2102ae50a164a1e57cdfefebb18143f.tar.gz
BUG: random: Check 'writeable' flag in 'shuffle' and 'permuted'.
Diffstat (limited to 'numpy/random/tests')
-rw-r--r--numpy/random/tests/test_generator_mt19937.py13
-rw-r--r--numpy/random/tests/test_random.py6
2 files changed, 19 insertions, 0 deletions
diff --git a/numpy/random/tests/test_generator_mt19937.py b/numpy/random/tests/test_generator_mt19937.py
index e5411b8ef..e16a82973 100644
--- a/numpy/random/tests/test_generator_mt19937.py
+++ b/numpy/random/tests/test_generator_mt19937.py
@@ -1020,6 +1020,13 @@ class TestRandomDist:
arr = np.ones((3, 2))
assert_raises(np.AxisError, random.shuffle, arr, 2)
+ def test_shuffle_not_writeable(self):
+ random = Generator(MT19937(self.seed))
+ a = np.zeros(5)
+ a.flags.writeable = False
+ with pytest.raises(ValueError, match='read-only'):
+ random.shuffle(a)
+
def test_permutation(self):
random = Generator(MT19937(self.seed))
alist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
@@ -1116,6 +1123,12 @@ class TestRandomDist:
with pytest.raises(TypeError, match='Cannot cast'):
random.permuted(x, axis=1, out=out)
+ def test_permuted_not_writeable(self):
+ x = np.zeros((2, 5))
+ x.flags.writeable = False
+ with pytest.raises(ValueError, match='read-only'):
+ random.permuted(x, axis=1, out=x)
+
def test_beta(self):
random = Generator(MT19937(self.seed))
actual = random.beta(.1, .9, size=(3, 2))
diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py
index 6a584a511..773b63653 100644
--- a/numpy/random/tests/test_random.py
+++ b/numpy/random/tests/test_random.py
@@ -564,6 +564,12 @@ class TestRandomDist:
rng.shuffle(a)
assert_equal(np.asarray(a), [4, 1, 0, 3, 2])
+ def test_shuffle_not_writeable(self):
+ a = np.zeros(3)
+ a.flags.writeable = False
+ with pytest.raises(ValueError, match='read-only'):
+ np.random.shuffle(a)
+
def test_beta(self):
np.random.seed(self.seed)
actual = np.random.beta(.1, .9, size=(3, 2))