diff options
| -rw-r--r-- | doc/release/upcoming_changes/20920.deprecation.rst | 3 | ||||
| -rw-r--r-- | numpy/core/src/multiarray/conversion_utils.c | 9 | ||||
| -rw-r--r-- | numpy/core/tests/test_deprecations.py | 8 |
3 files changed, 20 insertions, 0 deletions
diff --git a/doc/release/upcoming_changes/20920.deprecation.rst b/doc/release/upcoming_changes/20920.deprecation.rst new file mode 100644 index 000000000..69194e6be --- /dev/null +++ b/doc/release/upcoming_changes/20920.deprecation.rst @@ -0,0 +1,3 @@ +* Using ``axis=32`` (``axis=np.MAXDIMS``) in many cases had the + same meaning as ``axis=None``. This is deprecated and ``axis=None`` + must be used instead. diff --git a/numpy/core/src/multiarray/conversion_utils.c b/numpy/core/src/multiarray/conversion_utils.c index 6859b557c..96afb6c00 100644 --- a/numpy/core/src/multiarray/conversion_utils.c +++ b/numpy/core/src/multiarray/conversion_utils.c @@ -332,6 +332,15 @@ PyArray_AxisConverter(PyObject *obj, int *axis) if (error_converting(*axis)) { return NPY_FAIL; } + if (*axis == NPY_MAXDIMS){ + /* NumPy 1.23, 2022-05-19 */ + if (DEPRECATE("Using `axis=32` (MAXDIMS) is deprecated. " + "32/MAXDIMS had the same meaning as `axis=None` which " + "should be used instead. " + "(Deprecated NumPy 1.23)") < 0) { + return NPY_FAIL; + } + } } return NPY_SUCCEED; } diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py index 3dd60de91..5ab72bdaf 100644 --- a/numpy/core/tests/test_deprecations.py +++ b/numpy/core/tests/test_deprecations.py @@ -1208,3 +1208,11 @@ class TestArrayFinalizeNone(_DeprecationTestCase): __array_finalize__ = None self.assert_deprecated(lambda: np.array(1).view(NoFinalize)) + +class TestAxisNotMAXDIMS(_DeprecationTestCase): + # Deprecated 2022-01-08, NumPy 1.23 + message = r"Using `axis=32` \(MAXDIMS\) is deprecated" + + def test_deprecated(self): + a = np.zeros((1,)*32) + self.assert_deprecated(lambda: np.repeat(a, 1, axis=np.MAXDIMS)) |
