v2.5.0rc1
Breaking Changes📦 numpyView on GitHub →
⚠ 14 breaking✨ 4 features⚡ 12 deprecations🔧 36 symbols
Summary
NumPy 2.5.0 is a transitional release that removes distutils support, expires many older deprecations, and introduces new deprecations for unsafe array mutation methods. It also adds support for descending sorts and improves free threading.
⚠️ Breaking Changes
- Support for Python 3.11 has been dropped. Users must upgrade to Python 3.12 or newer.
- The entire `numpy.distutils` module has been removed. Users should migrate build systems away from distutils.
- Passing `None` as dtype to `np.finfo` now raises a `TypeError` (previously deprecated since 1.25).
- `numpy.cross` no longer supports 2-dimensional vectors. Ensure inputs are 1D or 3D vectors.
- `numpy._core.numerictypes.maximum_sctype` has been removed.
- `numpy.row_stack` has been removed; use `numpy.vstack` instead.
- `get_array_wrap` has been removed.
- `recfromtxt` and `recfromcsv` have been removed from `numpy.lib._npyio`; use `numpy.genfromtxt` instead.
- The re-export of `numpy.char.chararray` from `numpy.chararray` has been removed.
- `bincount` now raises a `TypeError` for non-integer inputs (previously deprecated since 2.1).
- The alias `numpy.lib.math` for the standard library `math` module has been removed.
- Data type alias `'a'` has been removed; use `'S'` instead.
- `_add_newdoc_ufunc(ufunc, newdoc)` has been removed; use `ufunc.__doc__ = newdoc` directly.
- `linalg.eig` and `linalg.eigvals` now always return complex arrays, even if eigenvalues are real. To retain previous behavior when eigenvalues are real, check `np.any(w.imag == 0)` and handle accordingly.
Migration Steps
- If you were using `numpy.distutils`, migrate your build system away from it.
- Replace usage of `numpy.char.chararray` with an `ndarray` having a string or bytes dtype.
- Replace usage of `numpy.char.[as]array` functions with `numpy.[as]array` specifying a string or bytes dtype.
- Instead of setting `arr.dtype = new_dtype`, use `arr.view(dtype=new_dtype)` to create a view with a new dtype.
- Instead of setting `arr.shape = new_shape`, use `np.reshape(arr, new_shape)` or `arr.reshape(new_shape)`.
- When constructing `numpy.timedelta64`, specify an explicit unit like `'s'` or `'D'` instead of using the generic unit.
- Replace in-place resizing of arrays with `np.resize(arr, new_shape)`.
- Replace calls to `numpy.fix` with `numpy.trunc`.
- Replace calls to `numpy.ma.round_` with `numpy.ma.round`.
- Replace calls to `numpy.typename` with `numpy.dtype.name`.
- Ensure that inputs to `numpy.triu_indices` and `numpy.tril_indices` are integers. Ensure `M`, `k`, and `N` parameters for `numpy.tri` are integers, and `k` for `numpy.tril_indices_from` and `numpy.triu_indices_from` are integers.
- If you have custom dtypes or logic in `__array_finalize__` affected by dtype setting changes, review the deprecation note regarding setting `_set_dtype = None` or defining `_set_dtype`.
- If you relied on `linalg.eig` or `linalg.eigvals` returning real arrays when eigenvalues were real, you must now explicitly check if the imaginary part is zero and handle the result accordingly.
✨ New Features
- Improved support for free threading.
- Support for descending sorts has been added, bringing sorting into compliance with the array-api standard.
- Many static typing improvements.
- Python 3.15 will be supported when released.
Affected Symbols
numpy.char.chararraynumpy.takenumpy.compressnumpy.char.[as]arraynumpy.dtype.__set__numpy.ndarray.shape.__set__numpy.timedelta64numpy.resizenumpy.fixnumpy.truncnumpy.ma.round_numpy.ma.roundnumpy.typenamenumpy.dtype.namenumpy.triu_indicesnumpy.tril_indicesnumpy.trinumpy.tril_indices_fromnumpy.triu_indices_fromnumpy.ndarray.__array_finalize__numpy.ndarray._set_dtypenumpy.distutilsnumpy.finfonumpy.crossnumpy._core.numerictypes.maximum_sctypenumpy.row_stacknumpy.vstackget_array_wrapnumpy.lib._npyio.recfromtxtnumpy.lib._npyio.recfromcsvnumpy.genfromtxtnumpy.chararraynumpy.bincountnumpy.lib.mathnumpy.linalg.eignumpy.linalg.eigvals
⚡ Deprecations
- `numpy.char.chararray` is deprecated. Use an `ndarray` with a string or bytes dtype instead.
- `numpy.take` now issues a `DeprecationWarning` when the result cannot be cast to the provided `out=` array under the same-kind rule (affects `compress` and possibly others).
- The `numpy.char.[as]array` functions are deprecated. Use an `numpy.[as]array` with a string or bytes dtype instead.
- Setting the `dtype` attribute on an array is deprecated. Use `array.view(dtype=new_dtype)` to create a view with a new dtype.
- Setting the `shape` attribute on an array is deprecated. Use `np.reshape` or `np.ndarray.reshape` to create a new view.
- Using the `generic` unit in `numpy.timedelta64` is deprecated due to potential non-transitive comparison. Specify an explicit unit (e.g., `'s'` or `'D'`). Operations implicitly relying on the generic unit are also deprecated.
- Resizing a Numpy array in place is deprecated. Use `np.resize` to create a resized array.
- `numpy.fix` is deprecated; use `numpy.trunc` instead.
- `numpy.ma.round_` is deprecated; use `numpy.ma.round` as a replacement.
- `numpy.typename` is deprecated; use `numpy.dtype.name` as a replacement.
- Inputs other than integers are deprecated for `numpy.triu_indices` and `numpy.tril_indices`. Non-integer values for `M`, `k`, and `N` parameters of `numpy.tri` are deprecated. Non-integer values for the `k` parameter of `numpy.tril_indices_from` and `numpy.triu_indices_from` are deprecated.
- Deprecations in custom `dtype` property and `__array_finalize__` related to how `arr.view(dtype=new_dtype)` interacts with subclasses. Subclasses should set `_set_dtype = None` or define `_set_dtype` as a function calling `ndarray._set_dtype()`.