summaryrefslogtreecommitdiff
path: root/numpy/core/tests
diff options
context:
space:
mode:
authorsgasse <sgasse@users.noreply.github.com>2020-03-25 22:01:47 +0100
committersgasse <sgasse@users.noreply.github.com>2020-03-26 19:21:45 +0100
commit36dd1b36474d9a6e46c86f708b9a62efa0a7309a (patch)
tree0a54058d8a277c4d2b6251abeb3c11145e292284 /numpy/core/tests
parent68439794b84836f43ec389be0e702ff64ee76d44 (diff)
downloadnumpy-36dd1b36474d9a6e46c86f708b9a62efa0a7309a.tar.gz
BUG: Fix IndexError for illegal axis in np.mean
Catch IndexError in _count_reduce_items used in np.mean and np.var for illegal axis and reraise as AxisError, see gh-15817.
Diffstat (limited to 'numpy/core/tests')
-rw-r--r--numpy/core/tests/test_multiarray.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 7b3397795..c893ec7ac 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -5489,6 +5489,12 @@ class TestStats:
# of float32.
assert_(_mean(np.ones(100000, dtype='float16')) == 1)
+ def test_mean_axis_error(self):
+ # Ensure that AxisError is raised instead of IndexError when axis is
+ # out of bounds, see gh-15817.
+ with assert_raises(np.core._exceptions.AxisError):
+ np.arange(10).mean(axis=2)
+
def test_var_values(self):
for mat in [self.rmat, self.cmat, self.omat]:
for axis in [0, 1, None]:
@@ -5531,6 +5537,12 @@ class TestStats:
cmat_swapped = cmat.astype(cmat.dtype.newbyteorder())
assert_almost_equal(cmat.var(), cmat_swapped.var())
+ def test_var_axis_error(self):
+ # Ensure that AxisError is raised instead of IndexError when axis is
+ # out of bounds, see gh-15817.
+ with assert_raises(np.core._exceptions.AxisError):
+ np.arange(10).var(axis=2)
+
def test_std_values(self):
for mat in [self.rmat, self.cmat, self.omat]:
for axis in [0, 1, None]: