diff options
author | Matti Picus <matti.picus@gmail.com> | 2020-03-27 16:18:04 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-27 16:18:04 +0300 |
commit | 2582c681082e6c2c74d424e255afa8efefa4f899 (patch) | |
tree | 1c698615697a225bd1c82036febbf725a20adaa7 /numpy/core/tests | |
parent | 1cb387128f66895b42c19578ccd60c34649de988 (diff) | |
parent | 36dd1b36474d9a6e46c86f708b9a62efa0a7309a (diff) | |
download | numpy-2582c681082e6c2c74d424e255afa8efefa4f899.tar.gz |
Merge pull request #15836 from sgasse/axis_np_mean
BUG: Fix IndexError for illegal axis in np.mean
Diffstat (limited to 'numpy/core/tests')
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 1637f6651..0d035388d 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]: |