Skip to content

Commit ae8b9ce

Browse files
saswatppseberg
andauthored
DEP: Deprecate use of axis=MAXDIMS instead of axis=None (numpy#20920)
* 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 <[email protected]>
1 parent 05d9001 commit ae8b9ce

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* Using ``axis=32`` (``axis=np.MAXDIMS``) in many cases had the
2+
same meaning as ``axis=None``. This is deprecated and ``axis=None``
3+
must be used instead.

numpy/core/src/multiarray/conversion_utils.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,15 @@ PyArray_AxisConverter(PyObject *obj, int *axis)
332332
if (error_converting(*axis)) {
333333
return NPY_FAIL;
334334
}
335+
if (*axis == NPY_MAXDIMS){
336+
/* NumPy 1.23, 2022-05-19 */
337+
if (DEPRECATE("Using `axis=32` (MAXDIMS) is deprecated. "
338+
"32/MAXDIMS had the same meaning as `axis=None` which "
339+
"should be used instead. "
340+
"(Deprecated NumPy 1.23)") < 0) {
341+
return NPY_FAIL;
342+
}
343+
}
335344
}
336345
return NPY_SUCCEED;
337346
}

numpy/core/tests/test_deprecations.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,3 +1208,11 @@ class NoFinalize(np.ndarray):
12081208
__array_finalize__ = None
12091209

12101210
self.assert_deprecated(lambda: np.array(1).view(NoFinalize))
1211+
1212+
class TestAxisNotMAXDIMS(_DeprecationTestCase):
1213+
# Deprecated 2022-01-08, NumPy 1.23
1214+
message = r"Using `axis=32` \(MAXDIMS\) is deprecated"
1215+
1216+
def test_deprecated(self):
1217+
a = np.zeros((1,)*32)
1218+
self.assert_deprecated(lambda: np.repeat(a, 1, axis=np.MAXDIMS))

0 commit comments

Comments
 (0)