8000 ENH: Better error message for invalid axis · numpy/numpy@4e54717 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4e54717

Browse files
committed
ENH: Better error message for invalid axis
xref GH7915 Currently, writing array.max(axis=[0, 1]) doesn't mention you can use a tuple for the axis argument -- it just says "an integer is required".
1 parent 9506037 commit 4e54717

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

numpy/core/src/multiarray/conversion_utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ PyArray_ConvertMultiAxis(PyObject *axis_in, int ndim, npy_bool *out_axis_flags)
289289
memset(out_axis_flags, 0, ndim);
290290

291291
axis = PyArray_PyIntAsInt_ErrMsg(axis_in,
292-
"an integer is required for the axis");
292+
"an integer or tuple is required for the axis");
293293
axis_orig = axis;
294294

295295
if (error_converting(axis)) {

numpy/core/tests/test_ufunc.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from numpy.core.test_rational import rational, test_add, test_add_rationals
88
from numpy.testing import (
99
TestCase, run_module_suite, assert_, assert_equal, assert_raises,
10-
assert_array_equal, assert_almost_equal, assert_array_almost_equal,
11-
assert_no_warnings
10+
assert_raises_regex, assert_array_equal, assert_almost_equal,
11+
assert_array_almost_equal, assert_no_warnings
1212
)
1313

1414

@@ -1197,6 +1197,7 @@ def test_reduce_arguments(self):
11971197
assert_raises(TypeError, f, d, axis="invalid")
11981198
assert_raises(TypeError, f, d, axis="invalid", dtype=None,
11991199
keepdims=True)
1200+
assert_raises_regex(TypeError, "integer or tuple", f, d, axis=[0])
12001201
# invalid dtype
12011202
assert_raises(TypeError, f, d, 0, "invalid")
12021203
assert_raises(TypeError, f, d, dtype="invalid")
@@ -1212,7 +1213,7 @@ def test_reduce_arguments(self):
12121213
assert_raises(TypeError, f, d, 0, keepdims="invalid", dtype="invalid",
12131214
out=None)
12141215

1215-
# invalid keyord
1216+
# invalid keyword
12161217
assert_raises(TypeError, f, d, axis=0, dtype=None, invalid=0)
12171218
assert_raises(TypeError, f, d, invalid=0)
12181219
assert_raises(TypeError, f, d, 0, keepdims=True, invalid="invalid",

0 commit comments

Comments
 (0)
0