NumPy 1.24.0, released on December 18, 2022, turns use of old type aliases such as np.float and np.int into errors. For developers maintaining numerical applications, Python’s built-in float and int are the direct replacements for those two aliases. Choosing a NumPy scalar type instead can change behavior: a bulk replacement with np.float64 is not simply a spelling repair. [S1][S2][D1]
The 1.24 release notes identify six expired aliases: np.object, np.bool, np.float, np.complex, np.str and np.int. Their deprecation began in NumPy 1.20. That earlier release’s migration table maps them to the Python built-ins object, bool, float, complex, str and int, respectively. These are the direct replacements for the old aliases. Some expired names now produce a FutureWarning as well as an error; seeing the warning does not mean the old use remains supported. [S1][S2]
For floating-point code, distinguish an array’s dtype—its element data type—from a call that creates a single value. NumPy’s 1.20 guide permits the corresponding NumPy type in place of np.float in np.dtype(...) or dtype=... without changing the output. Scalar construction needs more care. The old np.float(123) uses Python’s float constructor, so float(123) preserves that choice. Replacing it with np.float64(123) chooses a NumPy scalar instead. The guide warns that scalar behavior can differ, including for division by zero. [S2]
Integer width is a separate decision. When int or np.int_ specifies a NumPy integer dtype, the precision still depends on the computer and operating system. Removing np.int therefore does not, by itself, give an array a fixed-width integer type. The guide points to np.int32 or np.int64 when an explicit width is wanted, and to np.intp as a possible choice for indexing. If a data interface requires a particular width, treat that requirement as a type decision rather than an incidental rename. [S2]
Some similar-looking names still have time left. NumPy 1.24 newly deprecates np.int0, np.uint0 and np.bool8, among others, and says they will eventually be removed. Those names are not in the same position as np.int and the other expired built-in aliases, whose deprecation now results in errors. [S1]
For arrays whose data type must stay unchanged, test it alongside the values. NumPy 1.24 adds strict=True to testing.assert_array_equal: the option requires matching data types and disables scalar broadcasting in the comparison. [S1][S2]
Source documents
- NumPy 1.24.0 release notes (release-tag source)https://raw.githubusercontent.com/numpy/numpy/v1.24.0/doc/source/release/1.24.0-notes.rst
- NumPy 1.20.0 release notes (release-tag source)https://raw.githubusercontent.com/numpy/numpy/v1.20.0/doc/source/release/1.20.0-notes.rst
- NumPy v1.24.0 official release recordhttps://api.github.com/repos/numpy/numpy/releases/tags/v1.24.0
