diff --git a/mindspore/numpy/utils.py b/mindspore/numpy/utils.py index 0beed45580e..1c3db5ca64e 100644 --- a/mindspore/numpy/utils.py +++ b/mindspore/numpy/utils.py @@ -78,7 +78,7 @@ def _check_axes_range(axes, ndim): f"Lower bound {low} and upper bound {up} of axes are not allowed.") if isinstance(axes, int): if axes < low or axes > up: - raise TypeError( + raise ValueError( f"axis {axes} is out of bounds for tensor of dimension {ndim}.") return axes if axes >= 0 else axes + ndim new_axes = [] @@ -87,7 +87,7 @@ def _check_axes_range(axes, ndim): raise TypeError( f"int in tuple or list expected, but got {type(item)}.") if item < low or item > up: - raise TypeError( + raise ValueError( f"axis {item} in {axes} is out of bounds for tensor of dimension {ndim}.") new_axes.append(item if item >= 0 else item + ndim) return tuple(new_axes) diff --git a/tests/ut/python/numpy_native/test_array_ops.py b/tests/ut/python/numpy_native/test_array_ops.py index 84ae4e08bb9..51613b9ee69 100644 --- a/tests/ut/python/numpy_native/test_array_ops.py +++ b/tests/ut/python/numpy_native/test_array_ops.py @@ -582,7 +582,7 @@ def test_asarray_exception(): def test_swapaxes_exception(): - with pytest.raises(TypeError): + with pytest.raises(ValueError): mnp.swapaxes(mnp.ones((3, 3)), 1, 10)