diff options
author | Matti Picus <matti.picus@gmail.com> | 2019-04-18 15:17:08 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-18 15:17:08 +0300 |
commit | 842970f1aaa710b31ebd27427035b58b265e55a8 (patch) | |
tree | d3a7cddccdc5d28263dc4600624ffae6c3c23674 /numpy/lib/tests/test_index_tricks.py | |
parent | 0fd5f2506bf2f41b023392c945312e5a1a3eb819 (diff) | |
parent | 4ed097bbd6c07af9a81f310a10654f73a2a19d9c (diff) | |
download | numpy-842970f1aaa710b31ebd27427035b58b265e55a8.tar.gz |
Merge pull request #11684 from mattip/unravel_index-empty
BUG: Raise when unravel_index, ravel_multi_index are given empty input
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: |