Browse Source

fix Wrong TypeError in numpy_native

tags/v1.1.0
wangrao 5 years ago
parent
commit
2fb3f0ef4f
2 changed files with 3 additions and 3 deletions
  1. +2
    -2
      mindspore/numpy/utils.py
  2. +1
    -1
      tests/ut/python/numpy_native/test_array_ops.py

+ 2
- 2
mindspore/numpy/utils.py View File

@@ -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)


+ 1
- 1
tests/ut/python/numpy_native/test_array_ops.py View File

@@ -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)




Loading…
Cancel
Save