diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-02-13 15:38:54 +0000 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-02-13 15:38:54 +0000 |
commit | 61640a849557c4460101875fd9657b3c8aaccb6d (patch) | |
tree | ccf9a6954ea50d0b518d1c282ab2e0071afc2a8d /numpy/lib/tests/test_shape_base.py | |
parent | ee40ff69127fee94e7e3103445729024e7b3de21 (diff) | |
download | numpy-61640a849557c4460101875fd9657b3c8aaccb6d.tar.gz |
BUG: Don't leak internal exceptions when given an empty array
Fixes #7454
Diffstat (limited to 'numpy/lib/tests/test_shape_base.py')
-rw-r--r-- | numpy/lib/tests/test_shape_base.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_shape_base.py b/numpy/lib/tests/test_shape_base.py index 530472a9b..8bdf3d3da 100644 --- a/numpy/lib/tests/test_shape_base.py +++ b/numpy/lib/tests/test_shape_base.py @@ -140,6 +140,25 @@ class TestApplyAlongAxis(TestCase): res = np.apply_along_axis(sample_1d, 1, np.array([[1, 2], [3, 4]])) assert_array_equal(res, np.array([[2, 1], [4, 3]])) + def test_empty(self): + # can't apply_along_axis when there's no chance to call the function + def never_call(x): + assert_(False) # should never be reached + + a = np.empty((0, 0)) + assert_raises(ValueError, np.apply_along_axis, never_call, 0, a) + assert_raises(ValueError, np.apply_along_axis, never_call, 1, a) + + # but it's sometimes ok with some non-zero dimensions + def empty_to_1(x): + assert_(len(x) == 0) + return 1 + + a = np.empty((10, 0)) + actual = np.apply_along_axis(empty_to_1, 1, a) + assert_equal(actual, np.ones(10)) + assert_raises(ValueError, np.apply_along_axis, empty_to_1, 0, a) + class TestApplyOverAxes(TestCase): def test_simple(self): |