Skip to content

Commit

Permalink
DEP: Deprecate use of axis=MAXDIMS instead of axis=None (#20920)
Browse files Browse the repository at this point in the history
* added warning for axis=32

* corrected version to 1.23

* added tests for deprecation

* added newline EOF

* added newline EOF fix

* MAINT: Fixup deprecation text and add release note fragment

Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
  • Loading branch information
saswatpp and seberg committed May 20, 2022
1 parent 05d9001 commit ae8b9ce
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/release/upcoming_changes/20920.deprecation.rst
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 9 additions & 0 deletions numpy/core/src/multiarray/conversion_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions numpy/core/tests/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1208,3 +1208,11 @@ class NoFinalize(np.ndarray):
__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))

0 comments on commit ae8b9ce

Please sign in to comment.