v2.5.0
Breaking Changes📦 numpyView on GitHub →
⚠ 13 breaking✨ 6 features⚡ 12 deprecations🔧 36 symbols
Summary
NumPy 2.5.0 is a transitional release that removes distutils support, expires many old deprecations, and introduces new deprecations related to array mutation and type handling. It also adds support for descending sorts and improves free threading.
⚠️ Breaking Changes
- The `numpy.distutils` module has been completely removed. Users relying on it must migrate to standard Python packaging tools.
- Passing `None` as dtype to `np.finfo` now raises a `TypeError` instead of being accepted.
- `numpy.cross` no longer supports 2-dimensional vectors.
- `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.
- The `numpy.lib.math` alias for the standard library `math` module has been removed.
- The data type alias `'a'` has been removed; use `'S'` instead.
- `_add_newdoc_ufunc(ufunc, newdoc)` has been removed; use `ufunc.__doc__ = newdoc` directly.
- `numpy._core.numerictypes.maximum_sctype` has been removed.
- `linalg.eig` and `linalg.eigvals` now always return complex arrays, even if eigenvalues are real. To retain previous behavior for non-symmetric matrices, explicitly check if the imaginary part is zero or use logic to cast if necessary.
Migration Steps
- If using `numpy.distutils`, migrate to standard Python packaging tools.
- When using `np.take` or `np.compress`, ensure the output array specified by `out=` is compatible with the result dtype according to the same-kind rule, or handle the resulting `DeprecationWarning`.
- 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` using string or bytes dtype.
- Instead of setting `arr.dtype`, create a view with a new dtype using `array.view(dtype=new_dtype)`.
- Instead of setting `arr.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 array resizing with `np.resize(arr, new_size)`.
- Replace `numpy.fix` with `numpy.trunc`.
- Replace `numpy.ma.round_` with `numpy.ma.round`.
- Replace `numpy.typename` with `numpy.dtype.name`.
- Ensure 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 index functions are integers.
- If you have a subclass implementing custom dtype logic in `__array_finalize__` or a `dtype` property, set `_set_dtype = None` in the subclass definition, or define `_set_dtype` as a function calling `ndarray._set_dtype()` to manage view creation correctly.
- If using `linalg.eig` or `linalg.eigvals` on non-symmetric matrices and expecting real results, explicitly check if the imaginary part is zero or handle the complex output.
✨ New Features
- Removal of distutils support.
- Many expired deprecations removed.
- Many new deprecations introduced.
- Numerous static typing improvements.
- Improved support for free threading.
- Support for descending sorts added to comply with the array-api standard.
Affected Symbols
numpy.char.chararraynumpy.takenumpy.compressnumpy.char.[as]arraynumpy.dtypenumpy.shapenumpy.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.chararraybincountnumpy.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 (this affects `compress` as well).
- 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` instead. For subclass finalization, consider using the private method `np.ndarray._set_shape` as a temporary workaround.
- Using the `generic` unit in `numpy.timedelta64` is deprecated due to potential non-transitive comparison issues. Specify an explicit unit (e.g., `'s'` or `'D'`) when constructing `numpy.timedelta64`. 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 setting `dtype`. Subclasses should set `_set_dtype = None` to ensure `__array_finalize__` runs correctly on view creation, or define `_set_dtype` as a function calling `ndarray._set_dtype()`.