summaryrefslogtreecommitdiff
path: root/numpy/lib/tests
diff options
context:
space:
mode:
authorMarten van Kerkwijk <mhvk@astro.utoronto.ca>2017-02-18 11:03:37 -0500
committerGitHub <noreply@github.com>2017-02-18 11:03:37 -0500
commit86bf869ef831e0f2165a97c057c5661fc8b5dbf7 (patch)
tree5b4d68925ea49624efe0074d87bae1523813896a /numpy/lib/tests
parentd55f40b1e48d5a5fbed80e00a140c9db6e19732f (diff)
parent61640a849557c4460101875fd9657b3c8aaccb6d (diff)
downloadnumpy-86bf869ef831e0f2165a97c057c5661fc8b5dbf7.tar.gz
Merge pull request #8614 from eric-wieser/apply_along_axis-empty
BUG: Don't leak internal exceptions when given an empty array
Diffstat (limited to 'numpy/lib/tests')
-rw-r--r--numpy/lib/tests/test_shape_base.py19
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):