summaryrefslogtreecommitdiff
path: root/numpy/lib/function_base.py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-03-26 10:38:28 +0100
committerEric Wieser <wieser.eric@gmail.com>2017-03-28 20:44:42 +0100
commitefa1bd2c0de6cd9c07b410002f2e1c0bae8cf385 (patch)
tree7506958775539df3cca2df402a4eebb9df65bb38 /numpy/lib/function_base.py
parentcd01f01e9238bf3d4d42613d804e06d35b94b48f (diff)
downloadnumpy-efa1bd2c0de6cd9c07b410002f2e1c0bae8cf385.tar.gz
MAINT: Reuse _validate_axis in np.gradient
This also means that its axis argument invokes operator.index like others do. _validate_axis currently accepts lists of axes, which is a bug.
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r--numpy/lib/function_base.py15
1 files changed, 2 insertions, 13 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index cc0e8feeb..2a8a13caa 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -1679,21 +1679,10 @@ def gradient(f, *varargs, **kwargs):
axes = kwargs.pop('axis', None)
if axes is None:
axes = tuple(range(N))
- # check axes to have correct type and no duplicate entries
- if isinstance(axes, int):
- axes = (axes,)
- if not isinstance(axes, tuple):
- raise TypeError("A tuple of integers or a single integer is required")
-
- # normalize axis values:
- axes = tuple(x + N if x < 0 else x for x in axes)
- if max(axes) >= N or min(axes) < 0:
- raise ValueError("'axis' entry is out of bounds")
+ else:
+ axes = _nx._validate_axis(axes, N)
len_axes = len(axes)
- if len(set(axes)) != len_axes:
- raise ValueError("duplicate value in 'axis'")
-
n = len(varargs)
if n == 0:
dx = [1.0] * len_axes