8000 MAINT: Give a more helpful error for bad axis specifications. · numpy/numpy@270ae2c · GitHub
[go: up one dir, main page]

Skip to content

Commit 270ae2c

Browse files
committed
MAINT: Give a more helpful error for bad axis specifications.
This specifically addresses passing things like axis=[0,1] which gave an error message that an int was required. The real error was that if the axis isn't None or a tuple, it was simply wraped in a tuple, so the ufunc that is eventually called ended up with a list. The error message is matches that in core/src/multiarray/conversion_utils.c::PyArray_ConvertMultiAxis.
1 parent df9db6e commit 270ae2c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

numpy/linalg/linalg.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,10 @@ def norm(x, ord=None, axis=None, keepdims=False):
20742074
if axis is None:
20752075
axis = tuple(range(nd))
20762076
elif not isinstance(axis, tuple):
2077+
try:
2078+
axis = int(axis)
2079+
except:
2080+
raise TypeError("'axis' must be None, an integer or a tuple of integers")
20772081
axis = (axis,)
20782082

20792083
if len(axis) == 1:

0 commit comments

Comments
 (0)
0