NumPy 2.3.0 Release Notes#

Highlights#

We’ll choose highlights for this release near the end of the release cycle.

Highlights#

Interactive examples in the NumPy documentation#

The NumPy documentation includes a number of examples that can now be run interactively in your browser using WebAssembly and Pyodide.

Please note that the examples are currently experimental in nature and may not work as expected for all methods in the public API.

(gh-26745)

New functions#

New function numpy.strings.slice#

The new function numpy.strings.slice was added, which implements fast native slicing of string arrays. It supports the full slicing API including negative slice offsets and steps.

(gh-27789)

Deprecations#

  • The numpy.typing.mypy_plugin has been deprecated in favor of platform-agnostic static type inference. Please remove numpy.typing.mypy_plugin from the plugins section of your mypy configuration. If this change results in new errors being reported, kindly open an issue.

    (gh-28129)

Expired deprecations#

  • Remove deprecated macros like NPY_OWNDATA from cython interfaces in favor of NPY_ARRAY_OWNDATA (deprecated since 1.7)

  • Remove numpy/npy_1_7_deprecated_api.h and C macros like NPY_OWNDATA in favor of NPY_ARRAY_OWNDATA (deprecated since 1.7)

  • Remove alias generate_divbyzero_error to npy_set_floatstatus_divbyzero and generate_overflow_error to npy_set_floatstatus_overflow (deprecated since 1.10)

  • Remove np.tostring (deprecated since 1.19)

  • Raise on np.conjugate of non-numeric types (deprecated since 1.13)

  • Raise when using np.bincount(...minlength=None), use 0 instead (deprecated since 1.14)

  • Passing shape=None to functions with a non-optional shape argument errors, use () instead (deprecated since 1.20)

  • Inexact matches for mode and searchside raise (deprecated since 1.20)

  • Setting __array_finalize__ = None errors (deprecated since 1.23)

  • np.fromfile and np.fromstring error on bad data, previously they would guess (deprecated since 1.18)

  • datetime64 and timedelta64 construction with a tuple no longer accepts an event value, either use a two-tuple of (unit, num) or a 4-tuple of (unit, num, den, 1) (deprecated since 1.14)

  • When constructing a dtype from a class with a dtype attribute, that attribute must be a dtype-instance rather than a thing that can be parsed as a dtype instance (deprecated in 1.19). At some point the whole construct of using a dtype attribute will be deprecated (see #25306)

  • Passing booleans as partition index errors (deprecated since 1.23)

  • Out-of-bounds indexes error even on empty arrays (deprecated since 1.20)

  • np.tostring has been removed, use tobytes instead (deprecated since 1.19)

  • Disallow make a non-writeable array writeable for arrays with a base that do not own their data (deprecated since 1.17)

  • concatenate() with axis=None uses same-kind casting by default, not unsafe (deprecated since 1.20)

  • Unpickling a scalar with object dtype errors (deprecated since 1.20)

  • The binary mode of fromstring now errors, use frombuffer instead (deprecated since 1.14)

  • Converting np.inexact or np.floating to a dtype errors (deprecated since 1.19)

  • Converting np.complex, np.integer, np.signedinteger, np.unsignedinteger, np.generic to a dtype errors (deprecated since 1.19)

  • The Python built-in round errors for complex scalars. Use np.round or scalar.round instead (deprecated since 1.19)

  • ‘np.bool’ scalars can no longer be interpreted as an index (deprecated since 1.19)

  • Parsing an integer via a float string is no longer supported. (deprecated since 1.23) To avoid this error you can * make sure the original data is stored as integers. * use the converters=float keyword argument. * Use np.loadtxt(...).astype(np.int64)

  • The use of a length 1 tuple for the ufunc signature errors. Use dtype or fill the tuple with None (deprecated since 1.19)

  • Special handling of matrix is in np.outer is removed. Convert to a ndarray via matrix.A (deprecated since 1.20)

    (gh-28254)

C API changes#

  • NpyIter_GetTransferFlags is now available to check if the iterator needs the Python API or if casts may cause floating point errors (FPE). FPEs can for example be set when casting float64(1e300) to float32 (overflow to infinity) or a NaN to an integer (invalid value).

    (gh-27883)

  • NpyIter now has no limit on the number of operands it supports.

    (gh-28080)

New NpyIter_GetTransferFlags and NpyIter_IterationNeedsAPI change#

NumPy now has the new NpyIter_GetTransferFlags function as a more precise way checking of iterator/buffering needs. I.e. whether the Python API/GIL is required or floating point errors may occur. This function is also faster if you already know your needs without buffering.

The NpyIter_IterationNeedsAPI function now performs all the checks that were previously performed at setup time. While it was never necessary to call it multiple times, doing so will now have a larger cost.

(gh-27998)

New Features#

  • The type parameter of np.dtype now defaults to typing.Any. This way, static type-checkers will infer dtype: np.dtype as dtype: np.dtype[Any], without reporting an error.

    (gh-28669)

NumPy now registers its pkg-config paths with the pkgconf PyPI package#

The pkgconf PyPI package provides an interface for projects like NumPy to register their own paths to be added to the pkg-config search path. This means that when using pkgconf from PyPI, NumPy will be discoverable without needing for any custom environment configuration.

Attention

Attention

This only applies when using the pkgconf package from PyPI, or put another way, this only applies when installing pkgconf via a Python package manager.

If you are using pkg-config or pkgconf provided by your system, or any other source that does not use the pkgconf-pypi project, the NumPy pkg-config directory will not be automatically added to the search path. In these situations, you might want to use numpy-config.

(gh-28214)

Allow out=... in ufuncs to ensure array result#

NumPy has the sometimes difficult behavior that it currently usually returns scalars rather than 0-D arrays (even if the inputs were 0-D arrays). This is especially problematic for non-numerical dtypes (e.g. object).

For ufuncs (i.e. most simple math functions) it is now possible to use out=... (literally , e.g. out=Ellipsis) which is identical in behavior to out not being passed, but will ensure a non-scalar return. This spelling is borrowed from arr1d[0, ...] where the ... also ensures a non-scalar return.

Other functions with an out= kwarg should gain support eventually. Downstream libraries that interoperate via __array_ufunc__ or __array_function__ may need to adapt to support this.

(gh-28576)

Improvements#

  • Scalar comparisons between non-comparable dtypes such as np.array(1) == np.array(‘s’) now return a NumPy bool instead of a Python bool.

    (gh-27288)

  • np.nditer now has no limit on the number of supported operands (C-integer).

    (gh-28080)

  • The __repr__ for user-defined dtypes now prefers the __name__ of the custom dtype over a more generic name constructed from its kind and itemsize.

    (gh-28250)

  • np.dot now reports floating point exceptions.

    (gh-28442)

Performance improvements and changes#

Performance improvements to np.unique#

np.unique now tries to use a hash table to find unique values instead of sorting values before finding unique values. This is limited to certain dtypes for now, and the function is now faster for those dtypes. The function now also exposes a sorted parameter to allow returning unique values as they were found, instead of sorting them afterwards.

(gh-26018)

Changes#

  • The vector norm ord=inf and the matrix norms ord={1, 2, inf, 'nuc'} now always returns zero for empty arrays. Empty arrays have at least one axis of size zero. This affects np.linalg.norm, np.linalg.vector_norm, and np.linalg.matrix_norm. Previously, NumPy would raises errors or return zero depending on the shape of the array.

    (gh-28343)

  • A spelling error in the error message returned when converting a string to a float with the method np.format_float_positional has been fixed.

    (gh-28569)

unique_values may return unsorted data#

The relatively new function (added in NumPy 2.0) unique_values may now return unsorted results. Just as unique_counts and unique_all these never guaranteed a sorted result, however, the result was sorted until now. In cases where these do return a sorted result, this may change in future releases to improve performance.

(gh-26018)

Changes to the main iterator and potential numerical changes#

The main iterator, used in math functions and via np.nditer from Python and NpyIter in C, now behaves differently for some buffered iterations. This means that:

  • The buffer size used will often be smaller than the maximum buffer sized allowed by the buffersize parameter.

  • The “growinner” flag is now honored with buffered reductions when no operand requires buffering.

For np.sum() such changes in buffersize may slightly change numerical results of floating point operations. Users who use “growinner” for custom reductions could notice changes in precision (for example, in NumPy we removed it from einsum to avoid most precision changes and improve precision for some 64bit floating point inputs).

(gh-27883)

The minimum supported GCC version is now 9.3.0#

The minimum supported version was updated from 8.4.0 to 9.3.0, primarily in order to reduce the chance of platform-specific bugs in old GCC versions from causing issues.

(gh-28102)

Changes to automatic bin selection in numpy.histogram#

The automatic bin selection algorithm in numpy.histogram has been modified to avoid out-of-memory errors for samples with low variation. For full control over the selected bins the user can use set the bin or range parameters of numpy.histogram.

(gh-28426)

Build manylinux_2_28 wheels#

Wheels for linux systems will use the manylinux_2_28 tag (instead of the manylinux2014 tag), which means dropping support for redhat7/centos7, amazonlinux2, debian9, ubuntu18.04, and other pre-glibc2.28 operating system versions, as per the PEP 600 support table.

(gh-28436)