diff options
author | mattip <matti.picus@gmail.com> | 2018-08-07 13:04:12 -0700 |
---|---|---|
committer | mattip <matti.picus@gmail.com> | 2019-03-29 12:29:29 +0300 |
commit | 44a788b9ed45b42d270590663f7cddb191b17f8d (patch) | |
tree | 631d12f90b924f7feffa8ab0c4c09128f3f17aef /numpy/lib/tests/test_index_tricks.py | |
parent | db5fcc8e5834a5f36a1043da898f76562d5475ae (diff) | |
download | numpy-44a788b9ed45b42d270590663f7cddb191b17f8d.tar.gz |
BUG: raise on empty sequence input to unravel_index, ravel_index_multi; clarify error msg
Diffstat (limited to 'numpy/lib/tests/test_index_tricks.py')
-rw-r--r-- | numpy/lib/tests/test_index_tricks.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_index_tricks.py b/numpy/lib/tests/test_index_tricks.py index 3246f68ff..028bba37d 100644 --- a/numpy/lib/tests/test_index_tricks.py +++ b/numpy/lib/tests/test_index_tricks.py @@ -77,6 +77,26 @@ class TestRavelUnravelIndex(object): [[3, 6, 6], [4, 5, 1]]) assert_equal(np.unravel_index(1621, (6, 7, 8, 9)), [3, 1, 4, 1]) + def test_empty_indices(self): + msg1 = 'indices must be integral: the provided empty sequence was' + msg2 = 'only int indices permitted' + assert_raises_regex(TypeError, msg1, np.unravel_index, [], (10, 3, 5)) + assert_raises_regex(TypeError, msg1, np.unravel_index, (), (10, 3, 5)) + assert_raises_regex(TypeError, msg2, np.unravel_index, np.array([]), + (10, 3, 5)) + assert_equal(np.unravel_index(np.array([],dtype=int), (10, 3, 5)), + [[], [], []]) + assert_raises_regex(TypeError, msg1, np.ravel_multi_index, ([], []), + (10, 3)) + assert_raises_regex(TypeError, msg1, np.ravel_multi_index, ([], ['abc']), + (10, 3)) + assert_raises_regex(TypeError, msg2, np.ravel_multi_index, + (np.array([]), np.array([])), (5, 3)) + assert_equal(np.ravel_multi_index( + (np.array([], dtype=int), np.array([], dtype=int)), (5, 3)), []) + assert_equal(np.ravel_multi_index(np.array([[], []], dtype=int), + (5, 3)), []) + def test_big_indices(self): # ravel_multi_index for big indices (issue #7546) if np.intp == np.int64: |