summaryrefslogtreecommitdiff
path: root/numpy/lib/arraysetops.py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2018-01-31 09:38:14 -0800
committerEric Wieser <wieser.eric@gmail.com>2018-02-03 11:36:30 -0800
commitef70f13177a53266fd8547da6e00bc252a057893 (patch)
treeb836e830ac216985e27c3f6e63e582df2bbab91c /numpy/lib/arraysetops.py
parent2854d508d1c6d211f2ce99e8747eda1cb427a78a (diff)
downloadnumpy-ef70f13177a53266fd8547da6e00bc252a057893.tar.gz
MAINT: Use AxisError in swapaxes
Diffstat (limited to 'numpy/lib/arraysetops.py')
-rw-r--r--numpy/lib/arraysetops.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py
index e6ff5bf38..7b103ef3e 100644
--- a/numpy/lib/arraysetops.py
+++ b/numpy/lib/arraysetops.py
@@ -223,10 +223,12 @@ def unique(ar, return_index=False, return_inverse=False,
ret = _unique1d(ar, return_index, return_inverse, return_counts)
return _unpack_tuple(ret)
- if not (-ar.ndim <= axis < ar.ndim):
- raise ValueError('Invalid axis kwarg specified for unique')
+ try:
+ ar = np.swapaxes(ar, axis, 0)
+ except np.AxisError:
+ # this removes the "axis1" or "axis2" prefix from the error message
+ raise np.AxisError(axis, ar.ndim)
- ar = np.swapaxes(ar, axis, 0)
orig_shape, orig_dtype = ar.shape, ar.dtype
# Must reshape to a contiguous 2D array for this to work...
ar = ar.reshape(orig_shape[0], -1)