summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2021-02-11 13:23:39 +0200
committerGitHub <noreply@github.com>2021-02-11 13:23:39 +0200
commit871009f6415a2f588230e2e36bc9dbe751698ee1 (patch)
tree6cd0142c44556c712fc4b560c4dec18885c59359
parent6d8956e46026b68a4c2a50f1aab0c4f36a46053d (diff)
parent5345da834d8b09356f26494b39b7b93f945733fd (diff)
downloadnumpy-871009f6415a2f588230e2e36bc9dbe751698ee1.tar.gz
Merge pull request #18392 from bashtage/shuffle-ragged
BUG: Remove check in shuffle for non-ndarrays
-rw-r--r--numpy/random/_generator.pyx4
-rw-r--r--numpy/random/tests/test_generator_mt19937.py8
2 files changed, 11 insertions, 1 deletions
diff --git a/numpy/random/_generator.pyx b/numpy/random/_generator.pyx
index 1c4689a70..9673bc6f4 100644
--- a/numpy/random/_generator.pyx
+++ b/numpy/random/_generator.pyx
@@ -4398,7 +4398,9 @@ cdef class Generator:
char* x_ptr
char* buf_ptr
- axis = normalize_axis_index(axis, np.ndim(x))
+ if isinstance(x, np.ndarray):
+ # Only call ndim on ndarrays, see GH 18142
+ axis = normalize_axis_index(axis, np.ndim(x))
if type(x) is np.ndarray and x.ndim == 1 and x.size:
# Fast, statically typed path: shuffle the underlying buffer.
diff --git a/numpy/random/tests/test_generator_mt19937.py b/numpy/random/tests/test_generator_mt19937.py
index 47c81584c..d68bcd38b 100644
--- a/numpy/random/tests/test_generator_mt19937.py
+++ b/numpy/random/tests/test_generator_mt19937.py
@@ -2526,3 +2526,11 @@ def test_broadcast_size_scalar():
random.normal(mu, sigma, size=3)
with pytest.raises(ValueError):
random.normal(mu, sigma, size=2)
+
+
+def test_ragged_shuffle():
+ # GH 18142
+ seq = [[], [], 1]
+ gen = Generator(MT19937(0))
+ assert_no_warnings(gen.shuffle, seq)
+ assert seq == [1, [], []]