From 24960daf3e326591047eb099af840da6e95d0910 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Sun, 19 Feb 2017 13:12:30 +0000 Subject: BUG: Preserve types of empty arrays when known Fixes regression in #5805 --- numpy/lib/tests/test_index_tricks.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'numpy/lib/tests/test_index_tricks.py') diff --git a/numpy/lib/tests/test_index_tricks.py b/numpy/lib/tests/test_index_tricks.py index d9fa1f43e..e645114ab 100644 --- a/numpy/lib/tests/test_index_tricks.py +++ b/numpy/lib/tests/test_index_tricks.py @@ -198,11 +198,16 @@ class TestIndexExpression(TestCase): class TestIx_(TestCase): def test_regression_1(self): - # Test empty inputs create ouputs of indexing type, gh-5804 - # Test both lists and arrays - for func in (range, np.arange): - a, = np.ix_(func(0)) - assert_equal(a.dtype, np.intp) + # Test empty untyped inputs create ouputs of indexing type, gh-5804 + a, = np.ix_(range(0)) + assert_equal(a.dtype, np.intp) + + a, = np.ix_([]) + assert_equal(a.dtype, np.intp) + + # but if the type is specified, don't change it + a, = np.ix_(np.array([], dtype=np.float32)) + assert_equal(a.dtype, np.float32) def test_shape_and_dtype(self): sizes = (4, 5, 3, 2) -- cgit v1.2.1 From 44a788b9ed45b42d270590663f7cddb191b17f8d Mon Sep 17 00:00:00 2001 From: mattip Date: Tue, 7 Aug 2018 13:04:12 -0700 Subject: BUG: raise on empty sequence input to unravel_index, ravel_index_multi; clarify error msg --- numpy/lib/tests/test_index_tricks.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'numpy/lib/tests/test_index_tricks.py') 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: -- cgit v1.2.1 From f16c558fc3c3b57c4f2a93a80a778746ddd2f8ef Mon Sep 17 00:00:00 2001 From: psschand Date: Thu, 2 May 2019 06:06:30 +0530 Subject: BUG: fix unravel_index when dimension is greater than 'intp' The PR is: gh13439 Closes gh-9538 --- numpy/lib/tests/test_index_tricks.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'numpy/lib/tests/test_index_tricks.py') diff --git a/numpy/lib/tests/test_index_tricks.py b/numpy/lib/tests/test_index_tricks.py index e687e2f54..2f7e97831 100644 --- a/numpy/lib/tests/test_index_tricks.py +++ b/numpy/lib/tests/test_index_tricks.py @@ -106,6 +106,9 @@ class TestRavelUnravelIndex(object): np.ravel_multi_index(arr, (41, 7, 120, 36, 2706, 8, 6)), [5627771580, 117259570957]) + # test unravel_index for big indices (issue #9538) + assert_raises(ValueError, np.unravel_index, 1, (2**32-1, 2**31+1)) + # test overflow checking for too big array (issue #7546) dummy_arr = ([0],[0]) half_max = np.iinfo(np.intp).max // 2 -- cgit v1.2.1