summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/_methods.py2
-rw-r--r--numpy/core/tests/test_multiarray.py12
2 files changed, 13 insertions, 1 deletions
diff --git a/numpy/core/_methods.py b/numpy/core/_methods.py
index 6785683a3..86ddf4d17 100644
--- a/numpy/core/_methods.py
+++ b/numpy/core/_methods.py
@@ -63,7 +63,7 @@ def _count_reduce_items(arr, axis):
axis = (axis,)
items = 1
for ax in axis:
- items *= arr.shape[ax]
+ items *= arr.shape[mu.normalize_axis_index(ax, arr.ndim)]
return items
# Numpy 1.17.0, 2019-02-24
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]: