NumPy 2.6.0 Release Notes#

Highlights#

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

Expired deprecations#

  • The deprecated 'full', 'f', 'economic', and 'e' modes of numpy.linalg.qr have been removed. These were deprecated in NumPy 1.8. Use 'reduced' instead of 'full'/'f', and 'raw' instead of 'economic'/'e'.

    (gh-31387)

Compatibility notes#

numpy.insert out-of-bounds index detection#

numpy.insert now consistently raises IndexError for any out-of-bounds index, including when out-of-bounds and in-bounds indices are mixed in the same call. Previously such cases could silently succeed or produce incorrect results.

(gh-31782)

C API changes#

NumPy DTypes are heap-allocated and can use PyType_FromMetaType#

Most of NumPy DType classes, except np.dtype itself, are now heap-allocated types and downstream DTypes can now create their own DType classes using PyType_FromMetaType.

DType authors using PyArrayInitDTypeMeta_FromSpec may notice this if the DType has incorrect reference counting, since DTypes are no longer immortal. In theory this also means that you cannot subclass abstract DTypes anymore unless converting your DType to a heap-allocated type itself.

(gh-31364)

PyArray_StringDTypeObject is opaque under the abi3t stable ABI#

The PyArray_StringDTypeObject was accidentally exposed in NumPy 2.5 when targeting the free-threading-compatible stable ABI (Py_TARGET_ABI3T). PyArray_StringDTypeObject is now an opaque struct: extensions compiled that way cannot access its fields, since the struct layout depends on the size of the object header. Any code that accessed PyArray_StringDTypeObject fields in an abi3t build would have crashed, so we are making this API change in a bugfix release.

The NpyString allocator API remains usable by passing the descriptor object pointer, e.g. NpyString_acquire_allocator((PyArray_StringDTypeObject *)descr).

(gh-31771)

New Features#

New descending keyword argument for numpy.partition and numpy.argpartition#

Users can now pass the descending=True keyword argument to numpy.partition and numpy.argpartition to partition and argpartition arrays in descending order. NaN values, if present, are partitioned to the end of the array in both ascending and descending sorts. This feature is available for all built-in dtypes except string, unicode, void, object, and generic. Note that SIMD optimizations for partitioning are currently not available for descending order, so performance may be slower.

(gh-31511)

Improvements#

  • StringDType comparisons now correctly handle embedded NULL bytes.

    (gh-31662)

numpy.common_type now raises a clear error for non-array input#

Passing a dtype or scalar type to numpy.common_type, such as np.common_type(np.dtype("f4")), used to raise a confusing AttributeError. It now raises a TypeError that points to numpy.result_type and numpy.promote_types, which are the tools meant for combining dtypes and scalar types.

(gh-30890)

Object array sorting supports descending=True and consistently sorts NaN-like objects#

np.sort and np.argsort with arrays of dtype object now support passing descending=True to sort in descending order. Objects that compare as not equal to themselves (obj != obj), such as NaN-like objects, are considered unordered and are sorted to the end of the array, regardless of the value of descending.

(gh-31431)

np.linspace no longer returns NaN for equal infinite endpoints#

np.linspace(np.inf, np.inf, N) (and -np.inf) now correctly returns an array filled with inf instead of nan.

(gh-31620)

Performance improvements and changes#

Faster reductions on small arrays#

numpy.sum, numpy.prod, numpy.min, numpy.max, numpy.any, and numpy.all are now faster for small arrays. This reduces the Python-level overhead of calling these reductions, which is most noticeable when the reduction itself is cheap.

(gh-31845)

Changes#

  • The minimum supported GCC version has been updated from 9.3.0 to 10.3.0

    (gh-31843)

NumPy’s internal memory allocations now use PyMem_RawMalloc#

NumPy’s internal memory allocations now use PyMem_RawMalloc instead of malloc and can be tracked by tracemalloc.

(gh-31503)