Skip to content

Commit d10d17e

Browse files
committed
API: add deprecation for np.dtype(a), restore np.dtype(unicode) and add missing release note files
1 parent c294f1a commit d10d17e

8 files changed

Lines changed: 34 additions & 1 deletion

File tree

‎doc/release/upcoming_changes/24376.python_removal.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* ``np.recfromcsv`` and ``recfromtxt`` are now only available from ``np.lib.npyio``.
3939

4040
* ``np.issctype``, ``np.maximum_sctype``, ``np.obj2sctype``, ``np.sctype2char``,
41-
``np.sctypeDict``, ``np.sctypes``, ``np.issubsctype`` were all removed from the
41+
``np.sctypes``, ``np.issubsctype`` were all removed from the
4242
main namespace without replacement, as they where niche members.
4343

4444
* Deprecated ``np.deprecate`` and ``np.deprecate_with_doc`` has been removed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Seven data type aliases have been removed from ``np.dtype(alias)`` search:
2+
``int0``, ``uint0``, ``void0``, ``object0``, ``str0``, ``bytes0`` and ``bool8``.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
``diagonal`` and ``trace`` for `numpy.linalg`
2+
---------------------------------------------
3+
4+
`numpy.linalg.diagonal` and `numpy.linalg.trace` have been
5+
added, which are Array API compatible variants of `numpy.diagonal`
6+
and `numpy.trace`. They differ in the default axis selection
7+
which define 2-D sub-arrays.

‎numpy/core/_type_aliases.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"long": "int_",
7070
"ulong": "uint",
7171
"str": "str_",
72+
"unicode": "str_",
7273
}
7374

7475
for k, v in _extra_aliases.items():

‎numpy/core/include/numpy/ndarraytypes.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ enum NPY_TYPECHAR {
112112
NPY_CLONGDOUBLELTR = 'G',
113113
NPY_OBJECTLTR = 'O',
114114
NPY_STRINGLTR = 'S',
115+
NPY_DEPRECATED_STRINGLTR2 = 'a',
115116
NPY_UNICODELTR = 'U',
116117
NPY_VOIDLTR = 'V',
117118
NPY_DATETIMELTR = 'M',

‎numpy/core/src/multiarray/conversion_utils.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,15 @@ PyArray_TypestrConvert(int itemsize, int gentype)
13001300
newtype = NPY_STRING;
13011301
break;
13021302

1303+
case NPY_DEPRECATED_STRINGLTR2:
1304+
{
1305+
DEPRECATE(
1306+
"Data type alias `a` was removed in NumPy 2.0. "
1307+
"Use `S` alias instead."
1308+
);
1309+
}
1310+
break;
1311+
13031312
case NPY_UNICODELTR:
13041313
newtype = NPY_UNICODE;
13051314
break;

‎numpy/core/src/multiarray/descriptor.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,6 +1855,13 @@ _convert_from_str(PyObject *obj, int align)
18551855
"without a digit at the end.", obj);
18561856
return NULL;
18571857
}
1858+
if (strcmp(type, "a") == 0) {
1859+
PyErr_Format(PyExc_TypeError,
1860+
"Data type alias `a` was removed in NumPy 2.0. "
1861+
"Use `S` alias instead.", obj);
1862+
return NULL;
1863+
}
1864+
18581865
goto fail;
18591866
}
18601867

‎numpy/core/tests/test_dtype.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ def test_expired_dtypes_with_bad_bytesize(self):
142142
np.dtype("object0")
143143
with pytest.raises(TypeError, match=match):
144144
np.dtype("void0")
145+
# `a` alias was also removed (both with and without bytesize)
146+
with pytest.raises(TypeError, match=match):
147+
np.dtype("a")
148+
# warning is still issued from the C layer for bytsized variant
149+
with pytest.raises(TypeError):
150+
np.dtype("a8")
145151

146152
@pytest.mark.parametrize(
147153
'value',

0 commit comments

Comments
 (0)