From 370b6506f128460371484a50c813d66e64582f44 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Wed, 8 Feb 2017 22:05:11 +0000 Subject: 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 --- numpy/ma/extras.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'numpy/ma/extras.py') 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) -- cgit v1.2.1