diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-02-08 22:05:11 +0000 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-02-20 22:03:05 +0000 |
commit | 370b6506f128460371484a50c813d66e64582f44 (patch) | |
tree | 31470f73a17e41608865d900228796800c4bb988 /numpy/ma/extras.py | |
parent | 763589d5adbda6230b30ba054cda7206dd14d379 (diff) | |
download | numpy-370b6506f128460371484a50c813d66e64582f44.tar.gz |
MAINT: Use normalize_axis_index in all python axis checking
As a result, some exceptions change from ValueError to IndexError
This also changes the exception types raised in places where
normalize_axis_index is not quite appropriate
Diffstat (limited to 'numpy/ma/extras.py')
-rw-r--r-- | numpy/ma/extras.py | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py index 29a15633d..7149b525b 100644 --- a/numpy/ma/extras.py +++ b/numpy/ma/extras.py @@ -36,6 +36,7 @@ from .core import ( import numpy as np from numpy import ndarray, array as nxarray import numpy.core.umath as umath +from numpy.core.multiarray import normalize_axis_index from numpy.lib.function_base import _ureduce from numpy.lib.index_tricks import AxisConcatenator @@ -380,11 +381,7 @@ def apply_along_axis(func1d, axis, arr, *args, **kwargs): """ arr = array(arr, copy=False, subok=True) nd = arr.ndim - if axis < 0: - axis += nd - if (axis >= nd): - raise ValueError("axis must be less than arr.ndim; axis=%d, rank=%d." - % (axis, nd)) + axis = normalize_axis_index(axis, nd) ind = [0] * (nd - 1) i = np.zeros(nd, 'O') indlist = list(range(nd)) @@ -717,8 +714,8 @@ def _median(a, axis=None, out=None, overwrite_input=False): if axis is None: axis = 0 - elif axis < 0: - axis += asorted.ndim + else: + axis = normalize_axis_index(axis, asorted.ndim) if asorted.ndim == 1: counts = count(asorted) |