StringDType instances with equivalent floating-point NaN sentinels now
have equal hashes. Previously, distinct NaN objects could produce equal
dtype instances with different hashes, causing dictionary lookups and set
deduplication to fail.
MaskedArray resets a fill_value that cannot be represented in a new dtype
A fill_value copied from a source array is now reset to the default fill_value
for the new dtype when it cannot be represented in that dtype. Previously the
copied value could be stale: ufuncs that change dtype left the result holding a
fill_value typed for the old dtype, which raised a TypeError only when
something later validated it (such as .view()), and a floating point
fill_value that overflows an integer dtype was kept as an out-of-range value
together with a RuntimeWarning. Both now fall back to the default,
including when a masked array is passed to MaskedArray with a different dtype. A fill_value given explicitly by the user is still validated and
raises as before. This can now raise a ComplexWarning if the fill_value is
complex and the new dtype is real.
The NumPy 2.5.3 is a patch release that fixes bugs discovered after the 2.5.2
release. Apart from the usual bug and maintenance work, there are a number of
StringDType related fixes for problems discovered during the ongoing string
work in the main branch.
This release supports Python versions 3.12-3.15
Changes
Casting a fixed-width byte string array (np.bytes_) to StringDType
now raises TypeError when the bytes are not valid UTF-8. Previously the
invalid bytes were stored as-is and later caused undefined behavior in
string operations.
MaskedArray._fill_value would become stale when ufuncs that change dtype
left the result holding a fill_value typed for the old dtype. The mismatch
was silent until something later called _check_fill_value, such as .view(), and then a TypeError would be raised. Now, when the copied
fill_value is no longer valid for the new dtype, fall back to the
default fill_value for that dtype instead of propagating the stale value.
This may raise a ComplexWarning if the fill_value is complex and the
new dtype is real.
The NumPy 2.5.2 is a patch release that fixes bugs discovered after the 2.5.1
release. The big news is that it includes wheels for the newly released
Python 3.15.0rc1.
This release supports Python versions 3.12-3.15
C API changes
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).
The NumPy 2.5.1 is a patch release that fixes bugs discovered after the 2.5.0
release. The most noticeable is the fix is to the numpy datetime cython API
which should allow downstream to support NumPy versions older than 2.5.
Preparation for Python 3.15 continues along with typing improvements.
This release supports Python versions 3.12-3.14
Changes
The minimum supported GCC version has been updated from 9.3.0 to 10.3.0
Numpy 2.5.0 is a transitional release. It drops support for Python 3.11,
marking the end of distutils, and expires a large number of deprecations made
in the 2.0.x release. It also improves free threading and brings sorting into
compliance with the array-api standard with the addition of descending sorts.
There is also a fair amount of preparation for Python 3.15, which will be
supported starting with the first rc.
This release supports Python versions 3.12-3.14.
Highlights
Distutils has been removed,
Many expired deprecations, see below,
Many new deprecations, see below,
Many static typing improvements.
Improved support for free threading,
Support for descending sorts,
See New Features below for other additions.
Deprecations
numpy.char.chararray is deprecated. Use an ndarray with a string or bytes dtype instead.
numpy.take now correctly checks if the result can be cast to the provided out=out under the same-kind rule. A DeprecationWarning is given now
when this check fails. Previously, take incorrectly checked if out
could be cast to the result (the wrong direction). This deprecation also
affects compress and possibly other functions. (Future versions of NumPy
may tighten the casting check further.)
Setting the dtype attribute is deprecated because mutating an array is unsafe
if an array is shared, especially by multiple threads. As an alternative,
you can create a view with a new dtype via array.view(dtype=new_dtype).
Setting the shape attribute is deprecated because mutating an array is
unsafe if an array is shared, especially by multiple threads. As an
alternative, you can create a new view via np.reshape or np.ndarray.reshape. For example: x = np.arange(15); x = np.reshape(x, (3, 5)).
To ensure no copy is made from the data, one can use np.reshape(..., copy=False).
While setting the shape on an array is discouraged, for cases where it is
difficult to work around, e.g., in __array_finalize__, it is possible
with the private method np.ndarray._set_shape.
Using the generic unit in numpy.timedelta64 is deprecated since this
can lead to unexpected behavior such as non-transitive comparison, see gh-28287 for details. As
an alternative, specify an explicit unit such as 's' (seconds) or 'D'
(days) when constructing numpy.timedelta64. Due to this change, operations
that implicitly rely on the generic unit are also deprecated. For
example:
Resizing a Numpy array in place is deprecated since mutating an array is
unsafe if an array is shared, especially by multiple threads. As an
alternative, you can create a resized array via np.resize.
numpy.fix is deprecated, use numpy.trunc instead. It is faster and
follows the Array API standard. Both functions provide identical
functionality: rounding array elements towards zero.
Inputs other than integers are deprecated for numpy.triu_indices and numpy.tril_indices. Non-integer values for the M, k and N
parameters of numpy.tri are deprecated. Non-integer values for the k
parameter of both numpy.tril_indices_from and numpy.triu_indices_from
are deprecated.
Deprecations in custom dtype property and __array_finalize__.
Previously arr.view(dtype=new_dtype) called arr.dtype = new_dtype
also for subclasses, i.e., the attribute setting. That path is now
deprecated and refined, meaning that even subclasses that do not see this DeprecationWarning may wish to update their code.
A subclass that does any dtype specific logic (i.e. verifying the dtype
in __array_finalize__ or has a dtype property) should now:
Set _set_dtype = None in which case arr.view(dtype=new_dtype)
will call __array_finalize__ with the new dtype, ensuring that
any validation __array_finalize__ will run is done.
Or, for a quick fix, define _set_dtype as a function (calling ndarray._set_dtype() to avoid DeprecationWarnings.
(Future versions might migrate towards the _set_dtype = None path.)
Ideally, follow NumPy's deprecation to prevent dtype mutation by users.
The use of ndarray._set_dtype() may be necessary for some subclass
finalization patterns, but should otherwise be avoided.
linalg.eig and linalg.eigvals now always return complex arrays
Previously, the return values depended on whether the eigenvalues happen to lie
on the real line (which, for a general, non-symmetric matrix, is not
guaranteed).
This change makes consistent what was a value-dependent result. To retain the
previous behavior, do:
w = eigvals(a)
if np.any(w.imag == 0): # this is what NumPy used to do
w = w.real
If your matrix is symmetrix/hermitian, use eigh and eigvalsh instead of eig and eigvals. These are guaranteed to return real values. A common
case is covariance matrices, which are symmetric and positive definite by
construction.
NumPy's Cython headers (accessed via cimport numpy) now require Cython 3.0
or newer to build. If you try to compile a project that depends on NumPy's
Cython headers using Cython 0.29 or older, you will see a message like this:
#
DEF err = int('Build aborted: the NumPy Cython headers require Cython 3.0.0 or newer.')
------------------------------------------------------------
/path/to/site-packages/numpy/__init__.pxd:11:13: Error in compile-time expression:
ValueError: invalid literal for int() with base 10:
'Build aborted: the NumPy Cython headers require Cython 3.0.0 or newer.'
Note that the invalid integer is not a bug in NumPy - we are intentionally
generating this error to avoid triggering a more obscure error later in the
build when an older Cython version tries to use a Cython feature that was not
available in the old Cython version.
Previously, if the x or y argument of numpy.where was a Python
integer that was out of range of the output type, it would be silently
truncated. Now, an OverflowError will be raised instead.
This change also applies to the underlying C API function PyArray_Where.
from_dlpack raises BufferError instead of RuntimeError
np.from_dlpack now raises BufferError instead of RuntimeError when
the incoming DLPack tensor has an unsupported device, dtype, or exceeds the
maximum number of dimensions. This aligns with the DLPack and Array API
specifications, which recommend BufferError for data that cannot be
imported.
Two independent errors in the Stirling series of the acceptance/rejection step
of the BTPE algorithm used by numpy.random.Generator.binomial have been
corrected:
The third and fourth error terms were added rather than subtracted. This sign
error was inherited from section 5.3 of the original 1988 paper by
Kachitvichyanukul & Schmeiser, which incorrectly adds all four terms.
The leading coefficient had a digit-swap typo (13680 instead of 13860) that was introduced in the initial implementation.
As a result, Generator.binomial and Generator.multinomial, which uses
binomial internally, may now return different samples for the same seed.
The legacy numpy.random.RandomState.binomial and numpy.random.RandomState.multinomial are not affected: they preserve the
original (incorrect) behavior, so existing streams remain reproducible.
datetime64/timedelta64 arithmetic raises on overflow
Addition, subtraction, and integer multiplication of datetime64 and timedelta64 values now raise OverflowError when the result would
overflow int64 or land on the NaT sentinel value. Previously these
operations silently wrapped, often producing a value that was indistinguishable
from NaT. This matches the overflow checking already performed by
unit-conversion casts.
It is now possible to register "real" and "imag" ArrayMethods via PyUFunc_AddLoopsFromSpecs. These will be used for imag and real
and should normally set *view_offset in their resolve_descriptors
function to allow the array attributes to return views.
New PyDataType_TYPE, PyDataType_KIND, PyDataType_BYTEORDER and PyDataType_TYPEOBJ accessor macros to the C API. Together with the other
accessor macros added for the NumPy 2.0 transition, these allow accessing the
fields of PyArray_Descr structs without any direct field accesses.
PyArray_DescrFromScalar now returns the full dtype descriptor for scalars
of user-defined parametric data types, including any dtype parameters.
Parameters were previously silently discarded, which could cause incorrect
results in operations like astype on scalar objects. Internally, the
function now delegates to discover_descr_from_pyobject, which handles
parametric dtypes correctly.
It is now possible to register user-dtypes for dlpack export and import
via numpy.dtypes.register_dlpack_dtype. This functionality is meant to
be used with care by user-dtype authors.
Pixi package definitions have been added for different kinds
of from-source builds of NumPy. These can be used in
downstream Pixi workspaces via the pixi-build feature.
Definitions for both default and AddressSanitizer-instrumented
(asan) builds are available in the source code under the pixi-packages/ directory.
numpy.ndarray now supports structural pattern matching
numpy.ndarray and its subclasses now have the Py_TPFLAGS_SEQUENCE flag
set, enabling structural pattern matching (PEP 634) with match/case
statements. This also enables Cython to optimize integer indexing operations.
See `arrays.ndarray.pattern-matching{.interpreted-text role="ref"}` for details.
Added N-D evaluation functions to the polynomial package
New functions polyvalnd, chebvalnd, legvalnd, hermvalnd, hermevalnd, and lagvalnd have been added to evaluate polynomials
in arbitrary dimensions, analogous to the existing 2D and 3D evaluators.
New "descending" keyword argument for numpy.sort and numpy.argsort
Users can now pass the descending=True keyword argument to numpy.sort
and numpy.argsort to sort and argsort arrays in descending order. NaN
values, if present, are sorted to the end of the array in both ascending and
descending sorts. This feature is available for all built-in dtypes except void, object, and generic. Note that SIMD optimizations for sorting
are currently not available for descending sorts, so performance may be slower.
For f2py, the behaviour of intent(inplace) has improved. Previously,
if an input array did not have the right dtype or order, the input array was
modified in-place, changing its dtype and replacing its data by a corrected
copy. Now, instead, the corrected copy is kept a separate array, which, after
being passed and presumably modified by the fortran routine, is copied back to
the input routine. The above means one no longer has the risk that
pre-existing views or slices of the input array start pointing to unallocated
memory (at the price of increased overhead for the write-back copy at the end
of the call).
A potential problem would be that one might get very different results if one,
e.g., previously passed in an integer array where a double array was expected:
the writeback to integer would likely give wrong results. To avoid such
situations, intent(inplace) will now only allow arrays that have equivalent
type to that used in the fortran routine, i.e., dtype.kind is the same. For
instance, a routine expecting double would be able to receive float, but would
raise on integer input.
The C++ binary search implementation used by numpy.searchsorted now has a
much better performance when searching for multiple keys. The new
implementation batches binary search steps across all keys to leverage cache
locality and out-of-order execution. Benchmarks show the new implementation can
be up to 20 times faster for hundreds of thousands keys while single-key
performance remains comparable to previous versions.
NumPy's ufuncs now scale significantly better on free-threading builds
of CPython due to the following optimizations:
Lock-free dispatch table: The ufuncs dispatch table is now implemented as
a lock-free concurrent hash map, allowing multiple threads to call ufuncs
without contention.
Immortal shared objects: Certain shared objects, such as global memory
handlers, have been made immortal. This effectively reduces reference
counting contention across threads.
Optimized memory allocation: NumPy now utilizes PyMem_RawMalloc and PyMem_RawFree for memory allocation. On Python 3.15 and newer, this
leverages mimalloc and significantly reduces memory allocation overhead
in multi-threaded workloads.
Faster reductions on small/medium contiguous arrays
numpy.sum, numpy.prod, numpy.any, numpy.all, and other
reductions with an identity value now use a fast path when the input is a
contiguous, aligned, non-object array and the reduction covers all axes
(axis=None) with no special arguments. Typical speedup is ~1.3x on small
arrays; numpy.any / numpy.all on contiguous boolean arrays can see
speedup up to 1.9x.
numpy.linalg typing improvements and preliminary shape-typing support
Input and output dtypes for numpy.linalg functions are now more precise.
Several of these functions also gain preliminary shape-typing support while
remaining backward compatible. For example, the return type of numpy.linalg.matmul now depends on the shape-type of its inputs, or fall
back to the backward-compatible return type if the shape-types are unknown at
type-checking time. Because of limitations in Python's type system and current
type-checkers, shape-typing cannot cover every situation and is often only
implemented for the most common lower-rank cases.
The numpy.ma module is now fully covered by typing annotations. This
includes annotations for masked arrays, masks, and various functions and
methods. With this, NumPy has achieved 100% typing coverage across all its
submodules.
Shape-typing support for many functions and methods
Many functions and methods now have shape-aware return type annotations.
Type-checkers can now infer the number of dimensions of the returned array
through common operations. For example, np.linspace(0, 1) is now typed as a
1-d float64 array, and np.sum(x, keepdims=True) has the same number of
dimensions as x.
This covers numpy.linalg functions, array creation functions (like asarray, from{buffer,string,file,iter,regex}), range functions
(linspace, logspace, geomspace), aggregation functions and methods
(sum, mean, std, var, min, max, all, any,
etc.), sorting (sort, argsort, argpartition), cumulative operations
(cumsum, cumprod, etc.), set operations (unique_values, intersect1d, union1d, etc.), and various other functions including nonzero, transpose, diagonal, atleast_{1,2,3}d, clip, round, inner, bincount, and fft.fftfreq. Several of these also
gained more precise return dtype annotations as part of this work.
Shape-typing is still a work-in-progress, so coverage is not yet complete.
Because of limitations in Python's type system and current type-checkers,
shape-typing is often only implemented for the most common lower-rank cases.
numpy.fft typing improvements and preliminary shape-typing support
The numpy.fft functions now support non-float64/complex128 dtypes
and gain preliminary shape-typing support. For example, the return type of numpy.fft.fft now depends on the shape-type of its inputs, falling back to
the backward-compatible return type when the shape-types are unknown at
type-checking time.
Structured array copies now use memcpy for contiguous dtypes
Copying structured arrays with identical dtypes now uses memcpy instead of
field-by-field transfer when the dtype has a contiguous layout (no gaps between
fields). A new NPY_NOT_TRIVIALLY_COPYABLE dtype flag is set on structured
dtypes that have gaps in their memory layout, such as those created with
explicit offsets or via multi-field indexing. Only these dtypes continue to
use the slower field-by-field copy.
This means that padding bytes in contiguous structured dtypes (e.g. those
created without explicit offsets) may now be copied as part of the memcpy, whereas previously they were left untouched. Code that relies on
padding bytes being preserved during structured array copies may be affected.
numpy.ctypeslib.as_ctypes now does not support scalar types
The function numpy.ctypeslib.as_ctypes has been updated to only accept numpy.ndarray. Passing a scalar type (e.g., numpy.int32(5)) will now
raise a TypeError. This change was made to avoid the issue gh-30354 and to enforce the
readonly nature of scalar types in NumPy. The previous behavior relied on
undocumented implicit temporary arrays and was not well-defined. Users who
need to convert scalar types to ctypes should first convert them to an array
(e.g., numpy.asarray) before passing them to numpy.ctypeslib.as_ctypes.
Scalars now export the __array_interface__ directly rather than including
an array copy as a __ref entry. This means that scalars are now exported as
read-only while they previously exported as writeable. The path via __ref
was undocumented and not consistently used even within NumPy itself.
object dtype in .real and .imag and related functions
The array attributes .real and .imag now behave differently for object
arrays and return getattr(element, "real", element) or getattr(element, "imag", 0)
elementwise. Additionally, the return for both is now read-only to avoid possible
in-place changes having no effect.
This change also affects np.isreal() which uses arr.imag.
Previously, .imag always returned 0 while .real returned the
original array unmodified. The new behavior now returnes the correct values
for complex Python objects but may also lead to surprises for example if element.real() is a method and not a property.
This PR contains the following updates:
| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [numpy](https://github.com/numpy/numpy) ([changelog](https://numpy.org/doc/stable/release)) | `==2.4.6` → `==2.5.4` |  |  |
---
### Release Notes
<details>
<summary>numpy/numpy (numpy)</summary>
### [`v2.5.4`](https://github.com/numpy/numpy/releases/tag/v2.5.4): (Oct 10, 2026)
[Compare Source](https://github.com/numpy/numpy/compare/v2.5.3...v2.5.4)
### NumPy 2.5.4 Release Notes
*Released on 2026-10-10.*
NumPy 2.5.4 is a patch release that fixes bugs discovered after the 2.5.3
release. Highlights are:
- Many typing fixes and improvements,
- A workaround for the MSVC 19.51 bug, see below.
This release supports Python versions 3.12-3.15.
#### Improvements
- `numpy.linalg.svd` and `numpy.linalg.lstsq` now raise for inputs containing
infinities instead of returning garbage results.
- Fixed hangs in `numpy.linalg.svd` and `numpy.linalg.lstsq` for certain inputs
containing infinities for recent versions of some LAPACK implementations.
- `numpy.linalg.cond` now handles non-finite inputs more consistently.
([gh-32593](https://github.com/numpy/numpy/pull/32593))
##### StringDType hashing with NaN sentinels
`StringDType` instances with equivalent floating-point NaN sentinels now
have equal hashes. Previously, distinct NaN objects could produce equal
dtype instances with different hashes, causing dictionary lookups and set
deduplication to fail.
([gh-32563](https://github.com/numpy/numpy/pull/32563))
#### Changes
##### `MaskedArray` resets a fill_value that cannot be represented in a new dtype
A fill_value copied from a source array is now reset to the default fill_value
for the new dtype when it cannot be represented in that dtype. Previously the
copied value could be stale: ufuncs that change dtype left the result holding a
fill_value typed for the old dtype, which raised a `TypeError` only when
something later validated it (such as `.view()`), and a floating point
fill_value that overflows an integer dtype was kept as an out-of-range value
together with a `RuntimeWarning`. Both now fall back to the default,
including when a masked array is passed to `MaskedArray` with a different
`dtype`. A fill_value given explicitly by the user is still validated and
raises as before. This can now raise a `ComplexWarning` if the fill_value is
complex and the new dtype is real.
([gh-32508](https://github.com/numpy/numpy/pull/32508))
([gh-32562](https://github.com/numpy/numpy/pull/32562))
#### Contributors
A total of 9 people contributed to this release. People with a "+" by their
names contributed a patch for the first time.
- Aniket Singh Yadav
- Bhuvansh Kataria +
- Charles Harris
- Iason Krommydas
- Joren Hammudoglu
- Lazizbek Ergashev +
- Nathan Goldbaum
- Sebastian Berg
- Yeonho Kim
#### Pull requests merged
A total of 17 pull requests were merged for this release.
- [#​32520](https://github.com/numpy/numpy/pull/32520): MAINT: Prepare 2.5.x for further development
- [#​32557](https://github.com/numpy/numpy/pull/32557): BUG: Reset an unrepresentable fill_value on a dtype change ([#​32508](https://github.com/numpy/numpy/issues/32508))
- [#​32565](https://github.com/numpy/numpy/pull/32565): BLD: work around MSVC 19.51 bug ([#​32561](https://github.com/numpy/numpy/issues/32561))
- [#​32600](https://github.com/numpy/numpy/pull/32600): BUG: fix np.strings.replace truncating old/new to a's
- [#​32707](https://github.com/numpy/numpy/pull/32707): BUG: fix \[ureduce]{#ureduce} reshape when a kept axis has size 0 ([#​32536](https://github.com/numpy/numpy/issues/32536))
- [#​32709](https://github.com/numpy/numpy/pull/32709): BUG: fix two possible crashes in the ufunc.accumulate implementation...
- [#​32710](https://github.com/numpy/numpy/pull/32710): BUG: Reset an inherited fill_value in MaskedArray.\_\_new\_\_ as...
- [#​32711](https://github.com/numpy/numpy/pull/32711): ENH: Improvements and fixes for stringdtype hashing ([#​32563](https://github.com/numpy/numpy/issues/32563))
- [#​32713](https://github.com/numpy/numpy/pull/32713): CI: increase ppc64le timeout to match other timeouts ([#​32583](https://github.com/numpy/numpy/issues/32583))
- [#​32718](https://github.com/numpy/numpy/pull/32718): BUG: fix memory leak in legacy ArrayMethod wrapper code
- [#​32719](https://github.com/numpy/numpy/pull/32719): BUG: check for non-finite input before calling gesdd/gelsd and...
- [#​32738](https://github.com/numpy/numpy/pull/32738): BUG: fix segfault in as_arrays() on self-referencing pyscalars
- [#​32741](https://github.com/numpy/numpy/pull/32741): TYP: Various typing improvements.
- [#​32791](https://github.com/numpy/numpy/pull/32791): BUG: Fix canonicalization/promotion of nested subarray types...
- [#​32888](https://github.com/numpy/numpy/pull/32888): MAINT: Update vendored-meson to match main.
- [#​32904](https://github.com/numpy/numpy/pull/32904): TYP: Backport a number of typing updates.
- [#​32956](https://github.com/numpy/numpy/pull/32956): TYP: Various typing fixes and improvements.
### [`v2.5.3`](https://github.com/numpy/numpy/releases/tag/v2.5.3): (Sep 6, 2026)
[Compare Source](https://github.com/numpy/numpy/compare/v2.5.2...v2.5.3)
### NumPy 2.5.3 Release Notes
The NumPy 2.5.3 is a patch release that fixes bugs discovered after the 2.5.2
release. Apart from the usual bug and maintenance work, there are a number of
StringDType related fixes for problems discovered during the ongoing string
work in the main branch.
This release supports Python versions 3.12-3.15
#### Changes
- Casting a fixed-width byte string array (`np.bytes_`) to `StringDType`
now raises `TypeError` when the bytes are not valid UTF-8. Previously the
invalid bytes were stored as-is and later caused undefined behavior in
string operations.
([gh-32296](https://github.com/numpy/numpy/pull/32296))
- `MaskedArray._fill_value` would become stale when ufuncs that change dtype
left the result holding a fill_value typed for the old dtype. The mismatch
was silent until something later called `_check_fill_value`, such as
`.view()`, and then a `TypeError` would be raised. Now, when the copied
fill_value is no longer valid for the new dtype, fall back to the
default fill_value for that dtype instead of propagating the stale value.
This may raise a `ComplexWarning` if the fill_value is complex and the
new dtype is real.
([gh-32423](https://github.com/numpy/numpy/pull/32423))
#### Contributors
A total of 9 people contributed to this release. People with a "+" by their
names contributed a patch for the first time.
- Charles Harris
- Iason Krommydas
- James Davies +
- Joren Hammudoglu
- Maanas Arora
- Matti Picus
- Nathan Goldbaum
- Shikhar Goel +
- Yeonho Kim +
#### Pull requests merged
A total of 27 pull requests were merged for this release.
- [#​32235](https://github.com/numpy/numpy/pull/32235): MAINT: Prepare 2.5.x for further development
- [#​32289](https://github.com/numpy/numpy/pull/32289): BUG: raise ValueError when reading into record array with references...
- [#​32290](https://github.com/numpy/numpy/pull/32290): BUG: avoid uninitialized memory access / NULL-pointer deref in...
- [#​32291](https://github.com/numpy/numpy/pull/32291): TYP: fix `np.random.{get,set}_bit_generator` implicit re-exports...
- [#​32292](https://github.com/numpy/numpy/pull/32292): BUG: don't assume strides are a multiple of itemsize in stringdtype...
- [#​32293](https://github.com/numpy/numpy/pull/32293): CI: fix ccache CC override, add CXX in mac Conda CI ([#​32285](https://github.com/numpy/numpy/issues/32285))
- [#​32303](https://github.com/numpy/numpy/pull/32303): BUG: Fix ref leak in \[convert_from_type]{#convert_from_type} for custom scalar types...
- [#​32304](https://github.com/numpy/numpy/pull/32304): BUG: fix a number of issues around iterators and StringDType...
- [#​32326](https://github.com/numpy/numpy/pull/32326): TST: avoid allocating huge tuple of arrays in concatenate test...
- [#​32338](https://github.com/numpy/numpy/pull/32338): BUG: avoid possible UB in 'safe' multiplication helpers ([#​32294](https://github.com/numpy/numpy/issues/32294))
- [#​32339](https://github.com/numpy/numpy/pull/32339): MAINT: use `PyObject_` functions instead of raw `PyArray_ ones` ([#​32331](https://github.com/numpy/numpy/issues/32331))
- [#​32378](https://github.com/numpy/numpy/pull/32378): BUG: validate UTF-8 and harden StringDType bounds handling ([#​32296](https://github.com/numpy/numpy/issues/32296))
- [#​32380](https://github.com/numpy/numpy/pull/32380): BUG: fix two error handling mistakes in stringdtype replace loop...
- [#​32381](https://github.com/numpy/numpy/pull/32381): BUG: fix visibility annotations for functions in StringDType...
- [#​32384](https://github.com/numpy/numpy/pull/32384): MAINT: Update ml_dtypes pin to 8/21/2026.
- [#​32385](https://github.com/numpy/numpy/pull/32385): MAINT: Update numpy/\_core/src/umath/svml
- [#​32410](https://github.com/numpy/numpy/pull/32410): MAINT: skip failing cython limited API tests on Cython 3.3.0...
- [#​32427](https://github.com/numpy/numpy/pull/32427): BUG: close duplicated file descriptor if fdopen fails ([#​32386](https://github.com/numpy/numpy/issues/32386))
- [#​32428](https://github.com/numpy/numpy/pull/32428): MAINT: add missing space in warning and error messages ([#​32405](https://github.com/numpy/numpy/issues/32405))
- [#​32430](https://github.com/numpy/numpy/pull/32430): BUG: fix error handling in StringDType to fixed-width bytes case...
- [#​32441](https://github.com/numpy/numpy/pull/32441): MAINT: Only run nightly BLAS tests on main.
- [#​32471](https://github.com/numpy/numpy/pull/32471): BUG: fix memory leak in StringDType creation error path ([#​32470](https://github.com/numpy/numpy/issues/32470))
- [#​32477](https://github.com/numpy/numpy/pull/32477): BUG: fix stale fill_value after ufuncs change MaskedArray dtype...
- [#​32478](https://github.com/numpy/numpy/pull/32478): MAINT: exit deadlock tests quickly on slow hardware ([#​32466](https://github.com/numpy/numpy/issues/32466))
- [#​32481](https://github.com/numpy/numpy/pull/32481): BUG: Backport StringDType byteorder fixes
- [#​32506](https://github.com/numpy/numpy/pull/32506): DOC: use static scipy doc site for intershpinx ([#​32503](https://github.com/numpy/numpy/issues/32503))
- [#​32509](https://github.com/numpy/numpy/pull/32509): BUG: fix crash in ufunc.resolve_dtypes with a Python scalar type...
### [`v2.5.2`](https://github.com/numpy/numpy/releases/tag/v2.5.2): (Aug 9, 2026)
[Compare Source](https://github.com/numpy/numpy/compare/v2.5.1...v2.5.2)
### NumPy 2.5.2 Release Notes
The NumPy 2.5.2 is a patch release that fixes bugs discovered after the 2.5.1
release. The big news is that it includes wheels for the newly released
Python 3.15.0rc1.
This release supports Python versions 3.12-3.15
#### C API changes
##### `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](https://github.com/numpy/numpy/pull/31771))
#### Contributors
A total of 16 people contributed to this release. People with a "+" by their
names contributed a patch for the first time.
- Abhijeetsingh Meena +
- Charalampos Stratakis
- Charles Harris
- Chris Ninham +
- David Woods
- Geonho +
- Gopu Yeshwanth Reddy +
- Iason Krommydas
- Ijtihed Kilani
- Jelle Zijlstra +
- Joren Hammudoglu
- Kumar Aditya
- Mike Boyle
- Nathan Goldbaum
- Raghuveer Devulapalli
- Sebastian Berg
#### Pull requests merged
A total of 28 pull requests were merged for this release.
- [#​31864](https://github.com/numpy/numpy/pull/31864): MAINT: Prepare 2.5.x for further development
- [#​31889](https://github.com/numpy/numpy/pull/31889): TYP: Backport multiple static typing fixes 1.
- [#​31900](https://github.com/numpy/numpy/pull/31900): TST: add tests for stable ABI numpy extensions ([#​31822](https://github.com/numpy/numpy/issues/31822))
- [#​31901](https://github.com/numpy/numpy/pull/31901): BUG: fix `StringDType` coerce flag in binary ufunc promotion...
- [#​31902](https://github.com/numpy/numpy/pull/31902): BLD: fix meson deprecation warnings ([#​31892](https://github.com/numpy/numpy/issues/31892))
- [#​31921](https://github.com/numpy/numpy/pull/31921): TYP: Backport multiple typing fixes 2.
- [#​31947](https://github.com/numpy/numpy/pull/31947): MAINT: Update x86-simd-sort subproject ([`5adb334`](https://github.com/numpy/numpy/commit/5adb334) → [`fa944ef`](https://github.com/numpy/numpy/commit/fa944ef)) ([#​31908](https://github.com/numpy/numpy/issues/31908))
- [#​31949](https://github.com/numpy/numpy/pull/31949): BUG: fix crash on 32 bit systems using abi3t ([#​31771](https://github.com/numpy/numpy/issues/31771))
- [#​31950](https://github.com/numpy/numpy/pull/31950): MNT: remove some obsolete string to bool workarounds ([#​31859](https://github.com/numpy/numpy/issues/31859))
- [#​31952](https://github.com/numpy/numpy/pull/31952): BUG: centralized helper for output coerce and na_object in stringdtype...
- [#​31953](https://github.com/numpy/numpy/pull/31953): BUG: fix CPU feature env diagnostic buffer overruns ([#​31905](https://github.com/numpy/numpy/issues/31905))
- [#​31954](https://github.com/numpy/numpy/pull/31954): BUG: restore ndarray.conjugate() for legacy user-defined dtypes...
- [#​31955](https://github.com/numpy/numpy/pull/31955): TYP: Avoid shadowed dtype annotations
- [#​32077](https://github.com/numpy/numpy/pull/32077): MAINT: Update verdored-meson/meson to match main.
- [#​32114](https://github.com/numpy/numpy/pull/32114): BUG: fix refcount leak on overlapping copyto with where=False
- [#​32115](https://github.com/numpy/numpy/pull/32115): BUG: fix swallowed cast error in fancy indexing assignment ([#​31975](https://github.com/numpy/numpy/issues/31975))
- [#​32116](https://github.com/numpy/numpy/pull/32116): BUG: Fix buffered iterator stride after removing multi-index
- [#​32117](https://github.com/numpy/numpy/pull/32117): BUG: fix `np.fromiter` corruption when reusing a `StringDType`...
- [#​32119](https://github.com/numpy/numpy/pull/32119): BUG: add a special case for StringDType in np.isdtype ([#​32030](https://github.com/numpy/numpy/issues/32030))
- [#​32121](https://github.com/numpy/numpy/pull/32121): BUG: reference leak in `simd_sequence_from_iterable` ([#​32038](https://github.com/numpy/numpy/issues/32038))
- [#​32122](https://github.com/numpy/numpy/pull/32122): BUG: ensure lock is held when accessing or writing to RNG state...
- [#​32123](https://github.com/numpy/numpy/pull/32123): BUG: fully reset cached RNG state for non-MT19937 RNGs ([#​32062](https://github.com/numpy/numpy/issues/32062))
- [#​32135](https://github.com/numpy/numpy/pull/32135): TYP: type capabilities max dimensions
- [#​32158](https://github.com/numpy/numpy/pull/32158): BUG: avoid possible stack overflow in arraydescr_dealloc ([#​32133](https://github.com/numpy/numpy/issues/32133))
- [#​32206](https://github.com/numpy/numpy/pull/32206): MAINT: Update cibuildwheel to v4.2.0
- [#​32214](https://github.com/numpy/numpy/pull/32214): MAINT: Skip limited_api tests on some platforms.
- [#​32220](https://github.com/numpy/numpy/pull/32220): TYP: `isclose` shape-typing fix for 2d array-likes ([#​32205](https://github.com/numpy/numpy/issues/32205))
- [#​32221](https://github.com/numpy/numpy/pull/32221): BUG: avoid segfaults when legacy copyswap slot is not defined...
### [`v2.5.1`](https://github.com/numpy/numpy/releases/tag/v2.5.1): (July 4, 2026)
[Compare Source](https://github.com/numpy/numpy/compare/v2.5.0...v2.5.1)
### NumPy 2.5.1 Release Notes
The NumPy 2.5.1 is a patch release that fixes bugs discovered after the 2.5.0
release. The most noticeable is the fix is to the numpy datetime cython API
which should allow downstream to support NumPy versions older than 2.5.
Preparation for Python 3.15 continues along with typing improvements.
This release supports Python versions 3.12-3.14
#### Changes
- The minimum supported GCC version has been updated from 9.3.0 to 10.3.0
([gh-31843](https://github.com/numpy/numpy/pull/31843))
#### Contributors
A total of 10 people contributed to this release. People with a "+" by their
names contributed a patch for the first time.
- Adhyan Gupta +
- Ankit Ahlawat
- Charles Harris
- Iason Krommydas
- Joren Hammudoglu
- Kumar Aditya
- Nathan Goldbaum
- Sebastian Berg
- Ties Jan Hefting +
- Vineet Kumar
#### Pull requests merged
A total of 20 pull requests were merged for this release.
- [#​31707](https://github.com/numpy/numpy/pull/31707): MAINT: Prepare 2.5.x for further development
- [#​31721](https://github.com/numpy/numpy/pull/31721): CI: fix new `cython-lint` errors ([#​31711](https://github.com/numpy/numpy/issues/31711))
- [#​31723](https://github.com/numpy/numpy/pull/31723): MAINT: Update meson to match main
- [#​31729](https://github.com/numpy/numpy/pull/31729): TST: use setup-sde instead of curl to get SDE binaries ([#​31727](https://github.com/numpy/numpy/issues/31727))
- [#​31829](https://github.com/numpy/numpy/pull/31829): BUG: Relax finfo to be easier accessible for all user dtypes...
- [#​31831](https://github.com/numpy/numpy/pull/31831): TYP: Fix `flatiter.__next__` return type for `object_` and...
- [#​31832](https://github.com/numpy/numpy/pull/31832): BUG: avoid deadlocks using NpyString API ([#​31682](https://github.com/numpy/numpy/issues/31682))
- [#​31833](https://github.com/numpy/numpy/pull/31833): BUG: fix out array leak in reduceat and accumulate when dtype...
- [#​31835](https://github.com/numpy/numpy/pull/31835): BUG: fix numpy datetime cython APIs to be compatible with older...
- [#​31836](https://github.com/numpy/numpy/pull/31836): TYP: Fix incorrect dtype inference of `asarray([])` ([#​31732](https://github.com/numpy/numpy/issues/31732))
- [#​31837](https://github.com/numpy/numpy/pull/31837): TYP: Fix `np.ma.masked_array` 2.5.0 regression
- [#​31838](https://github.com/numpy/numpy/pull/31838): FIX: Refactor error handling in array_setstate to prevent typecode...
- [#​31839](https://github.com/numpy/numpy/pull/31839): TST: xfail multithreaded BLAS test more generously
- [#​31840](https://github.com/numpy/numpy/pull/31840): MAINT: Rename subroutine for crackfortran tests
- [#​31842](https://github.com/numpy/numpy/pull/31842): BUG: fix leak in reductions when a ufunc override errors or is...
- [#​31849](https://github.com/numpy/numpy/pull/31849): BLD: set minimum required gcc version to 10.3 ([#​31843](https://github.com/numpy/numpy/issues/31843))
- [#​31855](https://github.com/numpy/numpy/pull/31855): CI: fix hangs on MacOS ASan CI ([#​31853](https://github.com/numpy/numpy/issues/31853))
- [#​31856](https://github.com/numpy/numpy/pull/31856): BUG: fix several bugs in StringDType operations ([#​31846](https://github.com/numpy/numpy/issues/31846))
- [#​31857](https://github.com/numpy/numpy/pull/31857): BUG: Fix segfault in MT19937 by preventing recursive seed lists...
- [#​31858](https://github.com/numpy/numpy/pull/31858): BUG: Fix signed integer overflow in datetime.c ([#​31688](https://github.com/numpy/numpy/issues/31688))
### [`v2.5.0`](https://github.com/numpy/numpy/releases/tag/v2.5.0): (June 21, 2026)
[Compare Source](https://github.com/numpy/numpy/compare/v2.4.6...v2.5.0)
### NumPy 2.5.0 Release Notes
Numpy 2.5.0 is a transitional release. It drops support for Python 3.11,
marking the end of distutils, and expires a large number of deprecations made
in the 2.0.x release. It also improves free threading and brings sorting into
compliance with the array-api standard with the addition of descending sorts.
There is also a fair amount of preparation for Python 3.15, which will be
supported starting with the first rc.
This release supports Python versions 3.12-3.14.
#### Highlights
- Distutils has been removed,
- Many expired deprecations, see below,
- Many new deprecations, see below,
- Many static typing improvements.
- Improved support for free threading,
- Support for descending sorts,
See New Features below for other additions.
#### Deprecations
- `numpy.char.chararray` is deprecated. Use an `ndarray` with a string or bytes dtype instead.
([gh-30605](https://github.com/numpy/numpy/pull/30605))
- `numpy.take` now correctly checks if the result can be cast to the provided
`out=out` under the same-kind rule. A `DeprecationWarning` is given now
when this check fails. Previously, `take` incorrectly checked if `out`
could be cast to the result (the wrong direction). This deprecation also
affects `compress` and possibly other functions. (Future versions of NumPy
may tighten the casting check further.)
([gh-30615](https://github.com/numpy/numpy/pull/30615))
- The `numpy.char.[as]array` functions are deprecated. Use an
`numpy.[as]array` with a string or bytes dtype instead.
([gh-30802](https://github.com/numpy/numpy/pull/30802))
- Setting the dtype attribute is deprecated because mutating an array is unsafe
if an array is shared, especially by multiple threads. As an alternative,
you can create a view with a new dtype via `array.view(dtype=new_dtype)`.
([gh-29244](https://github.com/numpy/numpy/pull/29244))
- Setting the `shape` attribute is deprecated because mutating an array is
unsafe if an array is shared, especially by multiple threads. As an
alternative, you can create a new view via `np.reshape` or
`np.ndarray.reshape`. For example: `x = np.arange(15); x = np.reshape(x, (3, 5))`.
To ensure no copy is made from the data, one can use `np.reshape(..., copy=False)`.
While setting the shape on an array is discouraged, for cases where it is
difficult to work around, e.g., in `__array_finalize__`, it is possible
with the private method `np.ndarray._set_shape`.
([gh-29536](https://github.com/numpy/numpy/pull/29536))
- Using the `generic` unit in `numpy.timedelta64` is deprecated since this
can lead to unexpected behavior such as non-transitive comparison, see
[gh-28287](https://github.com/numpy/numpy/issues/28287) for details. As
an alternative, specify an explicit unit such as `'s'` (seconds) or `'D'`
(days) when constructing `numpy.timedelta64`. Due to this change, operations
that implicitly rely on the `generic` unit are also deprecated. For
example:
```
arr = np.array([1, 2, 3], dtype="m8[s]")
```
### `1` is implicitly converted to generic timedelta64
```
arr + 1
```
([gh-29619](https://github.com/numpy/numpy/pull/29619))
- Resizing a Numpy array in place is deprecated since mutating an array is
unsafe if an array is shared, especially by multiple threads. As an
alternative, you can create a resized array via `np.resize`.
([gh-30181](https://github.com/numpy/numpy/pull/30181))
- `numpy.fix` is deprecated, use `numpy.trunc` instead. It is faster and
follows the Array API standard. Both functions provide identical
functionality: rounding array elements towards zero.
([gh-30644](https://github.com/numpy/numpy/pull/30644))
- `numpy.ma.round_` is deprecated. `numpy.ma.round` can be used as a
replacement.
([gh-30738](https://github.com/numpy/numpy/pull/30738))
- `numpy.typename` is deprecated because the names returned by it were
outdated and inconsistent. `numpy.dtype.name` can be used as a
replacement.
([gh-30774](https://github.com/numpy/numpy/pull/30774))
- Inputs other than integers are deprecated for `numpy.triu_indices` and
`numpy.tril_indices`. Non-integer values for the `M`, `k` and `N`
parameters of `numpy.tri` are deprecated. Non-integer values for the `k`
parameter of both `numpy.tril_indices_from` and `numpy.triu_indices_from`
are deprecated.
([gh-30869](https://github.com/numpy/numpy/pull/30869))
- Deprecations in custom `dtype` property and `__array_finalize__`.
Previously `arr.view(dtype=new_dtype)` called `arr.dtype = new_dtype`
also for subclasses, i.e., the attribute setting. That path is now
deprecated and refined, meaning that even subclasses that do not see this
`DeprecationWarning` may wish to update their code.
A subclass that does any `dtype` specific logic (i.e. verifying the dtype
in `__array_finalize__` or has a `dtype` property) should now:
- Set `_set_dtype = None` in which case `arr.view(dtype=new_dtype)`
will call `__array_finalize__` with the new dtype, ensuring that
any validation `__array_finalize__` will run is done.
- Or, for a quick fix, define `_set_dtype` as a function (calling
`ndarray._set_dtype()` to avoid `DeprecationWarnings`.
(Future versions might migrate towards the `_set_dtype = None` path.)
Ideally, follow NumPy's deprecation to prevent `dtype` mutation by users.
The use of `ndarray._set_dtype()` may be necessary for some subclass
finalization patterns, but should otherwise be avoided.
([gh-31293](https://github.com/numpy/numpy/pull/31293))
#### Expired deprecations
- `numpy.distutils` has been removed
([gh-30340](https://github.com/numpy/numpy/pull/30340))
- Passing `None` as dtype to `np.finfo` will now raise a `TypeError`
(deprecated since 1.25)
([gh-30460](https://github.com/numpy/numpy/pull/30460))
- `numpy.cross` no longer supports 2-dimensional vectors.
(Deprecated since 2.0)
([gh-30461](https://github.com/numpy/numpy/pull/30461))
- `numpy._core.numerictypes.maximum_sctype` has been removed.
(deprecated since 2.0)
([gh-30462](https://github.com/numpy/numpy/pull/30462))
- `numpy.row_stack` has been removed in favor of `numpy.vstack`.
(deprecated since 2.0)
([gh-30463](https://github.com/numpy/numpy/pull/30463))
- `get_array_wrap` has been removed.
(deprecated since 2.0)
([gh-30463](https://github.com/numpy/numpy/pull/30463))
- `recfromtxt` and `recfromcsv` have been removed from `numpy.lib._npyio`
in favor of `numpy.genfromtxt`.
(deprecated since 2.0)
([gh-30467](https://github.com/numpy/numpy/pull/30467))
- The `numpy.chararray` re-export of `numpy.char.chararray` has been removed.
(deprecated since 2.0)
([gh-30604](https://github.com/numpy/numpy/pull/30604))
- `bincount` now raises a `TypeError` for non-integer inputs.
(deprecated since 2.1)
([gh-30610](https://github.com/numpy/numpy/pull/30610))
- The `numpy.lib.math` alias for the standard library `math` module has
been removed.
(deprecated since 1.25)
([gh-30612](https://github.com/numpy/numpy/pull/30612))
- Data type alias `'a'` was removed in favor of `'S'`.
(deprecated since 2.0)
([gh-30613](https://github.com/numpy/numpy/pull/30613))
- `_add_newdoc_ufunc(ufunc, newdoc)` has been removed in favor of
`ufunc.__doc__ = newdoc`.
(deprecated since 2.2)
([gh-30614](https://github.com/numpy/numpy/pull/30614))
#### Compatibility notes
##### `linalg.eig` and `linalg.eigvals` now always return complex arrays
Previously, the return values depended on whether the eigenvalues happen to lie
on the real line (which, for a general, non-symmetric matrix, is not
guaranteed).
This change makes consistent what was a value-dependent result. To retain the
previous behavior, do:
```
w = eigvals(a)
if np.any(w.imag == 0): # this is what NumPy used to do
w = w.real
```
If your matrix is symmetrix/hermitian, use `eigh` and `eigvalsh` instead of
`eig` and `eigvals`. These are guaranteed to return real values. A common
case is covariance matrices, which are symmetric and positive definite by
construction.
([gh-30411](https://github.com/numpy/numpy/pull/30411))
##### MSVC support
NumPy now requires minimum MSVC 19.35 toolchain version on Windows platforms.
This corresponds to Visual Studio 2022 version 17.5 Preview 2 or newer.
([gh-30489](https://github.com/numpy/numpy/pull/30489))
##### Cython support
NumPy's Cython headers (accessed via `cimport numpy`) now require Cython 3.0
or newer to build. If you try to compile a project that depends on NumPy's
Cython headers using Cython 0.29 or older, you will see a message like this:
```
Error compiling Cython file:
------------------------------------------------------------
...
```
### versions.
```
#
```
### See **init**.cython-30.pxd for the real Cython header
```
#
DEF err = int('Build aborted: the NumPy Cython headers require Cython 3.0.0 or newer.')
------------------------------------------------------------
/path/to/site-packages/numpy/__init__.pxd:11:13: Error in compile-time expression:
ValueError: invalid literal for int() with base 10:
'Build aborted: the NumPy Cython headers require Cython 3.0.0 or newer.'
```
Note that the invalid integer is not a bug in NumPy - we are intentionally
generating this error to avoid triggering a more obscure error later in the
build when an older Cython version tries to use a Cython feature that was not
available in the old Cython version.
([gh-30770](https://github.com/numpy/numpy/pull/30770))
##### `numpy.where` no longer truncates Python integers
Previously, if the `x` or `y` argument of `numpy.where` was a Python
integer that was out of range of the output type, it would be silently
truncated. Now, an `OverflowError` will be raised instead.
This change also applies to the underlying C API function `PyArray_Where`.
([gh-30803](https://github.com/numpy/numpy/pull/30803))
##### Default memory allocator change
NumPy now uses `PyMem_RawMalloc` and `PyMem_RawFree` as the default memory
allocator, instead of system's `malloc` and `free` directly.
([gh-30846](https://github.com/numpy/numpy/pull/30846))
##### `from_dlpack` raises `BufferError` instead of `RuntimeError`
`np.from_dlpack` now raises `BufferError` instead of `RuntimeError` when
the incoming DLPack tensor has an unsupported device, dtype, or exceeds the
maximum number of dimensions. This aligns with the DLPack and Array API
specifications, which recommend `BufferError` for data that cannot be
imported.
([gh-30937](https://github.com/numpy/numpy/pull/30937))
##### Corrections to the BTPE binomial sampler
Two independent errors in the Stirling series of the acceptance/rejection step
of the BTPE algorithm used by `numpy.random.Generator.binomial` have been
corrected:
- The third and fourth error terms were added rather than subtracted. This sign
error was inherited from section 5.3 of the original 1988 paper by
Kachitvichyanukul & Schmeiser, which incorrectly adds all four terms.
- The leading coefficient had a digit-swap typo (`13680` instead of
`13860`) that was introduced in the initial implementation.
As a result, `Generator.binomial` and `Generator.multinomial`, which uses
binomial internally, may now return different samples for the same seed.
The legacy `numpy.random.RandomState.binomial` and
`numpy.random.RandomState.multinomial` are not affected: they preserve the
original (incorrect) behavior, so existing streams remain reproducible.
([gh-31238](https://github.com/numpy/numpy/pull/31238))
##### `datetime64`/`timedelta64` arithmetic raises on overflow
Addition, subtraction, and integer multiplication of `datetime64` and
`timedelta64` values now raise `OverflowError` when the result would
overflow `int64` or land on the `NaT` sentinel value. Previously these
operations silently wrapped, often producing a value that was indistinguishable
from `NaT`. This matches the overflow checking already performed by
unit-conversion casts.
([gh-31378](https://github.com/numpy/numpy/pull/31378))
#### C API changes
- It is now possible to register `"real"` and `"imag"` ArrayMethods via
`PyUFunc_AddLoopsFromSpecs`. These will be used for `imag` and `real`
and should normally set `*view_offset` in their `resolve_descriptors`
function to allow the array attributes to return views.
([gh-30984](https://github.com/numpy/numpy/pull/30984))
- New `PyDataType_TYPE`, `PyDataType_KIND`, `PyDataType_BYTEORDER` and
`PyDataType_TYPEOBJ` accessor macros to the C API. Together with the other
accessor macros added for the NumPy 2.0 transition, these allow accessing the
fields of `PyArray_Descr` structs without any direct field accesses.
([gh-30994](https://github.com/numpy/numpy/pull/30994))
- NumPy now supports the stable ABI for free-threaded Python as described in
`803`{.interpreted-text role="pep"}.
([gh-31091](https://github.com/numpy/numpy/pull/31091))
- `PyArray_DescrFromScalar` now returns the full dtype descriptor for scalars
of user-defined parametric data types, including any dtype parameters.
Parameters were previously silently discarded, which could cause incorrect
results in operations like `astype` on scalar objects. Internally, the
function now delegates to `discover_descr_from_pyobject`, which handles
parametric dtypes correctly.
([gh-31067](https://github.com/numpy/numpy/pull/31067))
#### New Features
- It is now possible to register user-dtypes for dlpack export and import
via `numpy.dtypes.register_dlpack_dtype`. This functionality is meant to
be used with care by user-dtype authors.
([gh-31256](https://github.com/numpy/numpy/pull/31256))
##### Pixi package definitions
Pixi package definitions have been added for different kinds
of from-source builds of NumPy. These can be used in
downstream Pixi workspaces via the `pixi-build` feature.
Definitions for both `default` and AddressSanitizer-instrumented
(`asan`) builds are available in the source code under the
`pixi-packages/` directory.
`linux-64` and `osx-arm64` platforms are supported.
([gh-30381](https://github.com/numpy/numpy/pull/30381))
##### `numpy.ndarray` now supports structural pattern matching
`numpy.ndarray` and its subclasses now have the `Py_TPFLAGS_SEQUENCE` flag
set, enabling structural pattern matching (PEP 634) with `match`/`case`
statements. This also enables Cython to optimize integer indexing operations.
See `` `arrays.ndarray.pattern-matching ``{.interpreted-text role="ref"}\` for details.
([gh-30653](https://github.com/numpy/numpy/pull/30653))
##### Added N-D evaluation functions to the polynomial package
New functions `polyvalnd`, `chebvalnd`, `legvalnd`, `hermvalnd`,
`hermevalnd`, and `lagvalnd` have been added to evaluate polynomials
in arbitrary dimensions, analogous to the existing 2D and 3D evaluators.
([gh-30857](https://github.com/numpy/numpy/pull/30857))
##### New "descending" keyword argument for `numpy.sort` and `numpy.argsort`
Users can now pass the `descending=True` keyword argument to `numpy.sort`
and `numpy.argsort` to sort and argsort arrays in descending order. NaN
values, if present, are sorted to the end of the array in both ascending and
descending sorts. This feature is available for all built-in dtypes except
`void`, `object`, and `generic`. Note that SIMD optimizations for sorting
are currently not available for descending sorts, so performance may be slower.
([gh-31345](https://github.com/numpy/numpy/pull/31345))
#### Improvements
For `f2py`, the behaviour of `intent(inplace)` has improved. Previously,
if an input array did not have the right dtype or order, the input array was
modified in-place, changing its dtype and replacing its data by a corrected
copy. Now, instead, the corrected copy is kept a separate array, which, after
being passed and presumably modified by the fortran routine, is copied back to
the input routine. The above means one no longer has the risk that
pre-existing views or slices of the input array start pointing to unallocated
memory (at the price of increased overhead for the write-back copy at the end
of the call).
A potential problem would be that one might get very different results if one,
e.g., previously passed in an integer array where a double array was expected:
the writeback to integer would likely give wrong results. To avoid such
situations, `intent(inplace)` will now only allow arrays that have equivalent
type to that used in the fortran routine, i.e., `dtype.kind` is the same. For
instance, a routine expecting double would be able to receive float, but would
raise on integer input.
([gh-29929](https://github.com/numpy/numpy/pull/29929))
##### `f2py` modules now show allocatable arrays in `dir()`
Allocatable module variables wrapped by `f2py` now appear in `dir()`
output, matching their accessibility by name.
([gh-30965](https://github.com/numpy/numpy/pull/30965))
##### `StringDType` comparisons now correctly handle embedded NULL bytes.
([gh-31662](https://github.com/numpy/numpy/pull/31662))
#### Performance improvements and changes
##### Improved performance of `numpy.searchsorted`
The C++ binary search implementation used by `numpy.searchsorted` now has a
much better performance when searching for multiple keys. The new
implementation batches binary search steps across all keys to leverage cache
locality and out-of-order execution. Benchmarks show the new implementation can
be up to 20 times faster for hundreds of thousands keys while single-key
performance remains comparable to previous versions.
([gh-30517](https://github.com/numpy/numpy/pull/30517))
##### Improved scaling of ufuncs on free-threading
NumPy's ufuncs now scale significantly better on free-threading builds
of CPython due to the following optimizations:
- **Lock-free dispatch table:** The ufuncs dispatch table is now implemented as
a lock-free concurrent hash map, allowing multiple threads to call ufuncs
without contention.
- **Immortal shared objects:** Certain shared objects, such as global memory
handlers, have been made immortal. This effectively reduces reference
counting contention across threads.
- **Optimized memory allocation:** NumPy now utilizes `PyMem_RawMalloc` and
`PyMem_RawFree` for memory allocation. On Python 3.15 and newer, this
leverages `mimalloc` and significantly reduces memory allocation overhead
in multi-threaded workloads.
([gh-30846](https://github.com/numpy/numpy/pull/30846))
##### Faster reductions on small/medium contiguous arrays
`numpy.sum`, `numpy.prod`, `numpy.any`, `numpy.all`, and other
reductions with an identity value now use a fast path when the input is a
contiguous, aligned, non-object array and the reduction covers all axes
(`axis=None`) with no special arguments. Typical speedup is \~1.3x on small
arrays; `numpy.any` / `numpy.all` on contiguous boolean arrays can see
speedup up to 1.9x.
([gh-31274](https://github.com/numpy/numpy/pull/31274))
#### Typing improvements and changes
##### `numpy.linalg` typing improvements and preliminary shape-typing support
Input and output dtypes for `numpy.linalg` functions are now more precise.
Several of these functions also gain preliminary shape-typing support while
remaining backward compatible. For example, the return type of
`numpy.linalg.matmul` now depends on the shape-type of its inputs, or fall
back to the backward-compatible return type if the shape-types are unknown at
type-checking time. Because of limitations in Python's type system and current
type-checkers, shape-typing cannot cover every situation and is often only
implemented for the most common lower-rank cases.
([gh-30480](https://github.com/numpy/numpy/pull/30480))
##### `numpy.ma` typing annotations
The `numpy.ma` module is now fully covered by typing annotations. This
includes annotations for masked arrays, masks, and various functions and
methods. With this, NumPy has achieved 100% typing coverage across all its
submodules.
([gh-30566](https://github.com/numpy/numpy/pull/30566))
##### Shape-typing support for many functions and methods
Many functions and methods now have shape-aware return type annotations.
Type-checkers can now infer the number of dimensions of the returned array
through common operations. For example, `np.linspace(0, 1)` is now typed as a
1-d `float64` array, and `np.sum(x, keepdims=True)` has the same number of
dimensions as `x`.
This covers `numpy.linalg` functions, array creation functions (like
`asarray`, `from{buffer,string,file,iter,regex}`), range functions
(`linspace`, `logspace`, `geomspace`), aggregation functions and methods
(`sum`, `mean`, `std`, `var`, `min`, `max`, `all`, `any`,
etc.), sorting (`sort`, `argsort`, `argpartition`), cumulative operations
(`cumsum`, `cumprod`, etc.), set operations (`unique_values`,
`intersect1d`, `union1d`, etc.), and various other functions including
`nonzero`, `transpose`, `diagonal`, `atleast_{1,2,3}d`, `clip`,
`round`, `inner`, `bincount`, and `fft.fftfreq`. Several of these also
gained more precise return dtype annotations as part of this work.
Shape-typing is still a work-in-progress, so coverage is not yet complete.
Because of limitations in Python's type system and current type-checkers,
shape-typing is often only implemented for the most common lower-rank cases.
([gh-31172](https://github.com/numpy/numpy/pull/31172))
##### `numpy.fft` typing improvements and preliminary shape-typing support
The `numpy.fft` functions now support non-`float64`/`complex128` dtypes
and gain preliminary shape-typing support. For example, the return type of
`numpy.fft.fft` now depends on the shape-type of its inputs, falling back to
the backward-compatible return type when the shape-types are unknown at
type-checking time.
([gh-31226](https://github.com/numpy/numpy/pull/31226))
#### Changes
##### Structured array copies now use `memcpy` for contiguous dtypes
Copying structured arrays with identical dtypes now uses `memcpy` instead of
field-by-field transfer when the dtype has a contiguous layout (no gaps between
fields). A new `NPY_NOT_TRIVIALLY_COPYABLE` dtype flag is set on structured
dtypes that have gaps in their memory layout, such as those created with
explicit `offsets` or via multi-field indexing. Only these dtypes continue to
use the slower field-by-field copy.
This means that padding bytes in contiguous structured dtypes (e.g. those
created without explicit `offsets`) may now be copied as part of the
`memcpy`, whereas previously they were left untouched. Code that relies on
padding bytes being preserved during structured array copies may be affected.
([gh-29270](https://github.com/numpy/numpy/pull/29270))
##### `numpy.ctypeslib.as_ctypes` now does not support scalar types
The function `numpy.ctypeslib.as_ctypes` has been updated to only accept
`numpy.ndarray`. Passing a scalar type (e.g., `numpy.int32(5)`) will now
raise a `TypeError`. This change was made to avoid the issue
[gh-30354](https://github.com/numpy/numpy/issues/30354) and to enforce the
readonly nature of scalar types in NumPy. The previous behavior relied on
undocumented implicit temporary arrays and was not well-defined. Users who
need to convert scalar types to ctypes should first convert them to an array
(e.g., `numpy.asarray`) before passing them to `numpy.ctypeslib.as_ctypes`.
([gh-30538](https://github.com/numpy/numpy/pull/30538))
##### `__array_interface__` changes on scalars
Scalars now export the `__array_interface__` directly rather than including
an array copy as a `__ref` entry. This means that scalars are now exported as
read-only while they previously exported as writeable. The path via `__ref`
was undocumented and not consistently used even within NumPy itself.
([gh-30538](https://github.com/numpy/numpy/pull/30538))
##### `meshgrid` now always returns a tuple
`np.meshgrid` previously used to return a list when `sparse` was true and
`copy` was false. Now, it always returns a tuple regardless of the
arguments.
([gh-30707](https://github.com/numpy/numpy/pull/30707))
##### `numpy.triu_indices` now accepts `unsigned integers`
`numpy.triu_indices` previously used to error in some cases when `unsigned integers`
were given as arguments. Now, it accepts them in all cases.
([gh-30869](https://github.com/numpy/numpy/pull/30869))
##### `object` dtype in `.real` and `.imag` and related functions
The array attributes `.real` and `.imag` now behave differently for object
arrays and return `getattr(element, "real", element)` or `getattr(element, "imag", 0)`
elementwise. Additionally, the return for both is now read-only to avoid possible
in-place changes having no effect.
This change also affects `np.isreal()` which uses `arr.imag`.
Previously, `.imag` always returned `0` while `.real` returned the
original array unmodified. The new behavior now returnes the correct values
for complex Python objects but may also lead to surprises for example if
`element.real()` is a method and not a property.
([gh-30984](https://github.com/numpy/numpy/pull/30984))
##### 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](https://github.com/numpy/numpy/pull/31503))
</details>
---
### Configuration
📅 **Schedule**: (in timezone Europe/Paris)
- Branch creation
- At any time (no schedule defined)
- Automerge
- At any time (no schedule defined)
🚦 **Automerge**: Enabled.
♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.
🔕 **Ignore**: Close this PR and you won't be reminded about this update again.
---
- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box
---
This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4yNTcuOSIsInVwZGF0ZWRJblZlciI6IjQ0LjI1Ny45IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJib3QiLCJtaW5vciJdfQ==-->
Djeex
added the minor label 2026-11-21 19:18:39 +01:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
This PR contains the following updates:
==2.4.6→==2.5.4Release Notes
numpy/numpy (numpy)
v2.5.4: (Oct 10, 2026)Compare Source
NumPy 2.5.4 Release Notes
Released on 2026-10-10.
NumPy 2.5.4 is a patch release that fixes bugs discovered after the 2.5.3
release. Highlights are:
This release supports Python versions 3.12-3.15.
Improvements
numpy.linalg.svdandnumpy.linalg.lstsqnow raise for inputs containinginfinities instead of returning garbage results.
Fixed hangs in
numpy.linalg.svdandnumpy.linalg.lstsqfor certain inputscontaining infinities for recent versions of some LAPACK implementations.
numpy.linalg.condnow handles non-finite inputs more consistently.(gh-32593)
StringDType hashing with NaN sentinels
StringDTypeinstances with equivalent floating-point NaN sentinels nowhave equal hashes. Previously, distinct NaN objects could produce equal
dtype instances with different hashes, causing dictionary lookups and set
deduplication to fail.
(gh-32563)
Changes
MaskedArrayresets a fill_value that cannot be represented in a new dtypeA fill_value copied from a source array is now reset to the default fill_value
for the new dtype when it cannot be represented in that dtype. Previously the
copied value could be stale: ufuncs that change dtype left the result holding a
fill_value typed for the old dtype, which raised a
TypeErroronly whensomething later validated it (such as
.view()), and a floating pointfill_value that overflows an integer dtype was kept as an out-of-range value
together with a
RuntimeWarning. Both now fall back to the default,including when a masked array is passed to
MaskedArraywith a differentdtype. A fill_value given explicitly by the user is still validated andraises as before. This can now raise a
ComplexWarningif the fill_value iscomplex and the new dtype is real.
(gh-32508)
(gh-32562)
Contributors
A total of 9 people contributed to this release. People with a "+" by their
names contributed a patch for the first time.
Pull requests merged
A total of 17 pull requests were merged for this release.
v2.5.3: (Sep 6, 2026)Compare Source
NumPy 2.5.3 Release Notes
The NumPy 2.5.3 is a patch release that fixes bugs discovered after the 2.5.2
release. Apart from the usual bug and maintenance work, there are a number of
StringDType related fixes for problems discovered during the ongoing string
work in the main branch.
This release supports Python versions 3.12-3.15
Changes
Casting a fixed-width byte string array (
np.bytes_) toStringDTypenow raises
TypeErrorwhen the bytes are not valid UTF-8. Previously theinvalid bytes were stored as-is and later caused undefined behavior in
string operations.
(gh-32296)
MaskedArray._fill_valuewould become stale when ufuncs that change dtypeleft the result holding a fill_value typed for the old dtype. The mismatch
was silent until something later called
_check_fill_value, such as.view(), and then aTypeErrorwould be raised. Now, when the copiedfill_value is no longer valid for the new dtype, fall back to the
default fill_value for that dtype instead of propagating the stale value.
This may raise a
ComplexWarningif the fill_value is complex and thenew dtype is real.
(gh-32423)
Contributors
A total of 9 people contributed to this release. People with a "+" by their
names contributed a patch for the first time.
Pull requests merged
A total of 27 pull requests were merged for this release.
np.random.{get,set}_bit_generatorimplicit re-exports...PyObject_functions instead of rawPyArray_ ones(#32331)v2.5.2: (Aug 9, 2026)Compare Source
NumPy 2.5.2 Release Notes
The NumPy 2.5.2 is a patch release that fixes bugs discovered after the 2.5.1
release. The big news is that it includes wheels for the newly released
Python 3.15.0rc1.
This release supports Python versions 3.12-3.15
C API changes
PyArray_StringDTypeObjectis opaque under the abi3t stable ABIThe
PyArray_StringDTypeObjectwas accidentally exposed in NumPy2.5 when targeting the free-threading-compatible stable ABI
(
Py_TARGET_ABI3T).PyArray_StringDTypeObjectis now an opaquestruct: 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_StringDTypeObjectfields in an abi3t buildwould have crashed, so we are making this API change in a bugfix
release.
The
NpyStringallocator API remains usable by passing thedescriptor object pointer, e.g.
NpyString_acquire_allocator((PyArray_StringDTypeObject *)descr).(gh-31771)
Contributors
A total of 16 people contributed to this release. People with a "+" by their
names contributed a patch for the first time.
Pull requests merged
A total of 28 pull requests were merged for this release.
StringDTypecoerce flag in binary ufunc promotion...5adb334→fa944ef) (#31908)np.fromitercorruption when reusing aStringDType...simd_sequence_from_iterable(#32038)iscloseshape-typing fix for 2d array-likes (#32205)v2.5.1: (July 4, 2026)Compare Source
NumPy 2.5.1 Release Notes
The NumPy 2.5.1 is a patch release that fixes bugs discovered after the 2.5.0
release. The most noticeable is the fix is to the numpy datetime cython API
which should allow downstream to support NumPy versions older than 2.5.
Preparation for Python 3.15 continues along with typing improvements.
This release supports Python versions 3.12-3.14
Changes
The minimum supported GCC version has been updated from 9.3.0 to 10.3.0
(gh-31843)
Contributors
A total of 10 people contributed to this release. People with a "+" by their
names contributed a patch for the first time.
Pull requests merged
A total of 20 pull requests were merged for this release.
cython-linterrors (#31711)flatiter.__next__return type forobject_and...asarray([])(#31732)np.ma.masked_array2.5.0 regressionv2.5.0: (June 21, 2026)Compare Source
NumPy 2.5.0 Release Notes
Numpy 2.5.0 is a transitional release. It drops support for Python 3.11,
marking the end of distutils, and expires a large number of deprecations made
in the 2.0.x release. It also improves free threading and brings sorting into
compliance with the array-api standard with the addition of descending sorts.
There is also a fair amount of preparation for Python 3.15, which will be
supported starting with the first rc.
This release supports Python versions 3.12-3.14.
Highlights
See New Features below for other additions.
Deprecations
numpy.char.chararrayis deprecated. Use anndarraywith a string or bytes dtype instead.(gh-30605)
numpy.takenow correctly checks if the result can be cast to the providedout=outunder the same-kind rule. ADeprecationWarningis given nowwhen this check fails. Previously,
takeincorrectly checked ifoutcould be cast to the result (the wrong direction). This deprecation also
affects
compressand possibly other functions. (Future versions of NumPymay tighten the casting check further.)
(gh-30615)
The
numpy.char.[as]arrayfunctions are deprecated. Use annumpy.[as]arraywith a string or bytes dtype instead.(gh-30802)
Setting the dtype attribute is deprecated because mutating an array is unsafe
if an array is shared, especially by multiple threads. As an alternative,
you can create a view with a new dtype via
array.view(dtype=new_dtype).(gh-29244)
Setting the
shapeattribute is deprecated because mutating an array isunsafe if an array is shared, especially by multiple threads. As an
alternative, you can create a new view via
np.reshapeornp.ndarray.reshape. For example:x = np.arange(15); x = np.reshape(x, (3, 5)).To ensure no copy is made from the data, one can use
np.reshape(..., copy=False).While setting the shape on an array is discouraged, for cases where it is
difficult to work around, e.g., in
__array_finalize__, it is possiblewith the private method
np.ndarray._set_shape.(gh-29536)
Using the
genericunit innumpy.timedelta64is deprecated since thiscan lead to unexpected behavior such as non-transitive comparison, see
gh-28287 for details. As
an alternative, specify an explicit unit such as
's'(seconds) or'D'(days) when constructing
numpy.timedelta64. Due to this change, operationsthat implicitly rely on the
genericunit are also deprecated. Forexample:
1is implicitly converted to generic timedelta64(gh-29619)
Resizing a Numpy array in place is deprecated since mutating an array is
unsafe if an array is shared, especially by multiple threads. As an
alternative, you can create a resized array via
np.resize.(gh-30181)
numpy.fixis deprecated, usenumpy.truncinstead. It is faster andfollows the Array API standard. Both functions provide identical
functionality: rounding array elements towards zero.
(gh-30644)
numpy.ma.round_is deprecated.numpy.ma.roundcan be used as areplacement.
(gh-30738)
numpy.typenameis deprecated because the names returned by it wereoutdated and inconsistent.
numpy.dtype.namecan be used as areplacement.
(gh-30774)
Inputs other than integers are deprecated for
numpy.triu_indicesandnumpy.tril_indices. Non-integer values for theM,kandNparameters of
numpy.triare deprecated. Non-integer values for thekparameter of both
numpy.tril_indices_fromandnumpy.triu_indices_fromare deprecated.
(gh-30869)
Deprecations in custom
dtypeproperty and__array_finalize__.Previously
arr.view(dtype=new_dtype)calledarr.dtype = new_dtypealso for subclasses, i.e., the attribute setting. That path is now
deprecated and refined, meaning that even subclasses that do not see this
DeprecationWarningmay wish to update their code.A subclass that does any
dtypespecific logic (i.e. verifying the dtypein
__array_finalize__or has adtypeproperty) should now:_set_dtype = Nonein which casearr.view(dtype=new_dtype)will call
__array_finalize__with the new dtype, ensuring thatany validation
__array_finalize__will run is done._set_dtypeas a function (callingndarray._set_dtype()to avoidDeprecationWarnings.(Future versions might migrate towards the
_set_dtype = Nonepath.)Ideally, follow NumPy's deprecation to prevent
dtypemutation by users.The use of
ndarray._set_dtype()may be necessary for some subclassfinalization patterns, but should otherwise be avoided.
(gh-31293)
Expired deprecations
numpy.distutilshas been removed(gh-30340)
Passing
Noneas dtype tonp.finfowill now raise aTypeError(deprecated since 1.25)
(gh-30460)
numpy.crossno longer supports 2-dimensional vectors.(Deprecated since 2.0)
(gh-30461)
numpy._core.numerictypes.maximum_sctypehas been removed.(deprecated since 2.0)
(gh-30462)
numpy.row_stackhas been removed in favor ofnumpy.vstack.(deprecated since 2.0)
(gh-30463)
get_array_wraphas been removed.(deprecated since 2.0)
(gh-30463)
recfromtxtandrecfromcsvhave been removed fromnumpy.lib._npyioin favor of
numpy.genfromtxt.(deprecated since 2.0)
(gh-30467)
The
numpy.chararrayre-export ofnumpy.char.chararrayhas been removed.(deprecated since 2.0)
(gh-30604)
bincountnow raises aTypeErrorfor non-integer inputs.(deprecated since 2.1)
(gh-30610)
The
numpy.lib.mathalias for the standard librarymathmodule hasbeen removed.
(deprecated since 1.25)
(gh-30612)
Data type alias
'a'was removed in favor of'S'.(deprecated since 2.0)
(gh-30613)
_add_newdoc_ufunc(ufunc, newdoc)has been removed in favor ofufunc.__doc__ = newdoc.(deprecated since 2.2)
(gh-30614)
Compatibility notes
linalg.eigandlinalg.eigvalsnow always return complex arraysPreviously, the return values depended on whether the eigenvalues happen to lie
on the real line (which, for a general, non-symmetric matrix, is not
guaranteed).
This change makes consistent what was a value-dependent result. To retain the
previous behavior, do:
If your matrix is symmetrix/hermitian, use
eighandeigvalshinstead ofeigandeigvals. These are guaranteed to return real values. A commoncase is covariance matrices, which are symmetric and positive definite by
construction.
(gh-30411)
MSVC support
NumPy now requires minimum MSVC 19.35 toolchain version on Windows platforms.
This corresponds to Visual Studio 2022 version 17.5 Preview 2 or newer.
(gh-30489)
Cython support
NumPy's Cython headers (accessed via
cimport numpy) now require Cython 3.0or newer to build. If you try to compile a project that depends on NumPy's
Cython headers using Cython 0.29 or older, you will see a message like this:
versions.
See init.cython-30.pxd for the real Cython header
Note that the invalid integer is not a bug in NumPy - we are intentionally
generating this error to avoid triggering a more obscure error later in the
build when an older Cython version tries to use a Cython feature that was not
available in the old Cython version.
(gh-30770)
numpy.whereno longer truncates Python integersPreviously, if the
xoryargument ofnumpy.wherewas a Pythoninteger that was out of range of the output type, it would be silently
truncated. Now, an
OverflowErrorwill be raised instead.This change also applies to the underlying C API function
PyArray_Where.(gh-30803)
Default memory allocator change
NumPy now uses
PyMem_RawMallocandPyMem_RawFreeas the default memoryallocator, instead of system's
mallocandfreedirectly.(gh-30846)
from_dlpackraisesBufferErrorinstead ofRuntimeErrornp.from_dlpacknow raisesBufferErrorinstead ofRuntimeErrorwhenthe incoming DLPack tensor has an unsupported device, dtype, or exceeds the
maximum number of dimensions. This aligns with the DLPack and Array API
specifications, which recommend
BufferErrorfor data that cannot beimported.
(gh-30937)
Corrections to the BTPE binomial sampler
Two independent errors in the Stirling series of the acceptance/rejection step
of the BTPE algorithm used by
numpy.random.Generator.binomialhave beencorrected:
error was inherited from section 5.3 of the original 1988 paper by
Kachitvichyanukul & Schmeiser, which incorrectly adds all four terms.
13680instead of13860) that was introduced in the initial implementation.As a result,
Generator.binomialandGenerator.multinomial, which usesbinomial internally, may now return different samples for the same seed.
The legacy
numpy.random.RandomState.binomialandnumpy.random.RandomState.multinomialare not affected: they preserve theoriginal (incorrect) behavior, so existing streams remain reproducible.
(gh-31238)
datetime64/timedelta64arithmetic raises on overflowAddition, subtraction, and integer multiplication of
datetime64andtimedelta64values now raiseOverflowErrorwhen the result wouldoverflow
int64or land on theNaTsentinel value. Previously theseoperations silently wrapped, often producing a value that was indistinguishable
from
NaT. This matches the overflow checking already performed byunit-conversion casts.
(gh-31378)
C API changes
It is now possible to register
"real"and"imag"ArrayMethods viaPyUFunc_AddLoopsFromSpecs. These will be used forimagandrealand should normally set
*view_offsetin theirresolve_descriptorsfunction to allow the array attributes to return views.
(gh-30984)
New
PyDataType_TYPE,PyDataType_KIND,PyDataType_BYTEORDERandPyDataType_TYPEOBJaccessor macros to the C API. Together with the otheraccessor macros added for the NumPy 2.0 transition, these allow accessing the
fields of
PyArray_Descrstructs without any direct field accesses.(gh-30994)
NumPy now supports the stable ABI for free-threaded Python as described in
803{.interpreted-text role="pep"}.(gh-31091)
PyArray_DescrFromScalarnow returns the full dtype descriptor for scalarsof user-defined parametric data types, including any dtype parameters.
Parameters were previously silently discarded, which could cause incorrect
results in operations like
astypeon scalar objects. Internally, thefunction now delegates to
discover_descr_from_pyobject, which handlesparametric dtypes correctly.
(gh-31067)
New Features
It is now possible to register user-dtypes for dlpack export and import
via
numpy.dtypes.register_dlpack_dtype. This functionality is meant tobe used with care by user-dtype authors.
(gh-31256)
Pixi package definitions
Pixi package definitions have been added for different kinds
of from-source builds of NumPy. These can be used in
downstream Pixi workspaces via the
pixi-buildfeature.Definitions for both
defaultand AddressSanitizer-instrumented(
asan) builds are available in the source code under thepixi-packages/directory.linux-64andosx-arm64platforms are supported.(gh-30381)
numpy.ndarraynow supports structural pattern matchingnumpy.ndarrayand its subclasses now have thePy_TPFLAGS_SEQUENCEflagset, enabling structural pattern matching (PEP 634) with
match/casestatements. This also enables Cython to optimize integer indexing operations.
See
`arrays.ndarray.pattern-matching{.interpreted-text role="ref"}` for details.(gh-30653)
Added N-D evaluation functions to the polynomial package
New functions
polyvalnd,chebvalnd,legvalnd,hermvalnd,hermevalnd, andlagvalndhave been added to evaluate polynomialsin arbitrary dimensions, analogous to the existing 2D and 3D evaluators.
(gh-30857)
New "descending" keyword argument for
numpy.sortandnumpy.argsortUsers can now pass the
descending=Truekeyword argument tonumpy.sortand
numpy.argsortto sort and argsort arrays in descending order. NaNvalues, if present, are sorted to the end of the array in both ascending and
descending sorts. This feature is available for all built-in dtypes except
void,object, andgeneric. Note that SIMD optimizations for sortingare currently not available for descending sorts, so performance may be slower.
(gh-31345)
Improvements
For
f2py, the behaviour ofintent(inplace)has improved. Previously,if an input array did not have the right dtype or order, the input array was
modified in-place, changing its dtype and replacing its data by a corrected
copy. Now, instead, the corrected copy is kept a separate array, which, after
being passed and presumably modified by the fortran routine, is copied back to
the input routine. The above means one no longer has the risk that
pre-existing views or slices of the input array start pointing to unallocated
memory (at the price of increased overhead for the write-back copy at the end
of the call).
A potential problem would be that one might get very different results if one,
e.g., previously passed in an integer array where a double array was expected:
the writeback to integer would likely give wrong results. To avoid such
situations,
intent(inplace)will now only allow arrays that have equivalenttype to that used in the fortran routine, i.e.,
dtype.kindis the same. Forinstance, a routine expecting double would be able to receive float, but would
raise on integer input.
(gh-29929)
f2pymodules now show allocatable arrays indir()Allocatable module variables wrapped by
f2pynow appear indir()output, matching their accessibility by name.
(gh-30965)
StringDTypecomparisons now correctly handle embedded NULL bytes.(gh-31662)
Performance improvements and changes
Improved performance of
numpy.searchsortedThe C++ binary search implementation used by
numpy.searchsortednow has amuch better performance when searching for multiple keys. The new
implementation batches binary search steps across all keys to leverage cache
locality and out-of-order execution. Benchmarks show the new implementation can
be up to 20 times faster for hundreds of thousands keys while single-key
performance remains comparable to previous versions.
(gh-30517)
Improved scaling of ufuncs on free-threading
NumPy's ufuncs now scale significantly better on free-threading builds
of CPython due to the following optimizations:
a lock-free concurrent hash map, allowing multiple threads to call ufuncs
without contention.
handlers, have been made immortal. This effectively reduces reference
counting contention across threads.
PyMem_RawMallocandPyMem_RawFreefor memory allocation. On Python 3.15 and newer, thisleverages
mimallocand significantly reduces memory allocation overheadin multi-threaded workloads.
(gh-30846)
Faster reductions on small/medium contiguous arrays
numpy.sum,numpy.prod,numpy.any,numpy.all, and otherreductions with an identity value now use a fast path when the input is a
contiguous, aligned, non-object array and the reduction covers all axes
(
axis=None) with no special arguments. Typical speedup is ~1.3x on smallarrays;
numpy.any/numpy.allon contiguous boolean arrays can seespeedup up to 1.9x.
(gh-31274)
Typing improvements and changes
numpy.linalgtyping improvements and preliminary shape-typing supportInput and output dtypes for
numpy.linalgfunctions are now more precise.Several of these functions also gain preliminary shape-typing support while
remaining backward compatible. For example, the return type of
numpy.linalg.matmulnow depends on the shape-type of its inputs, or fallback to the backward-compatible return type if the shape-types are unknown at
type-checking time. Because of limitations in Python's type system and current
type-checkers, shape-typing cannot cover every situation and is often only
implemented for the most common lower-rank cases.
(gh-30480)
numpy.matyping annotationsThe
numpy.mamodule is now fully covered by typing annotations. Thisincludes annotations for masked arrays, masks, and various functions and
methods. With this, NumPy has achieved 100% typing coverage across all its
submodules.
(gh-30566)
Shape-typing support for many functions and methods
Many functions and methods now have shape-aware return type annotations.
Type-checkers can now infer the number of dimensions of the returned array
through common operations. For example,
np.linspace(0, 1)is now typed as a1-d
float64array, andnp.sum(x, keepdims=True)has the same number ofdimensions as
x.This covers
numpy.linalgfunctions, array creation functions (likeasarray,from{buffer,string,file,iter,regex}), range functions(
linspace,logspace,geomspace), aggregation functions and methods(
sum,mean,std,var,min,max,all,any,etc.), sorting (
sort,argsort,argpartition), cumulative operations(
cumsum,cumprod, etc.), set operations (unique_values,intersect1d,union1d, etc.), and various other functions includingnonzero,transpose,diagonal,atleast_{1,2,3}d,clip,round,inner,bincount, andfft.fftfreq. Several of these alsogained more precise return dtype annotations as part of this work.
Shape-typing is still a work-in-progress, so coverage is not yet complete.
Because of limitations in Python's type system and current type-checkers,
shape-typing is often only implemented for the most common lower-rank cases.
(gh-31172)
numpy.ffttyping improvements and preliminary shape-typing supportThe
numpy.fftfunctions now support non-float64/complex128dtypesand gain preliminary shape-typing support. For example, the return type of
numpy.fft.fftnow depends on the shape-type of its inputs, falling back tothe backward-compatible return type when the shape-types are unknown at
type-checking time.
(gh-31226)
Changes
Structured array copies now use
memcpyfor contiguous dtypesCopying structured arrays with identical dtypes now uses
memcpyinstead offield-by-field transfer when the dtype has a contiguous layout (no gaps between
fields). A new
NPY_NOT_TRIVIALLY_COPYABLEdtype flag is set on structureddtypes that have gaps in their memory layout, such as those created with
explicit
offsetsor via multi-field indexing. Only these dtypes continue touse the slower field-by-field copy.
This means that padding bytes in contiguous structured dtypes (e.g. those
created without explicit
offsets) may now be copied as part of thememcpy, whereas previously they were left untouched. Code that relies onpadding bytes being preserved during structured array copies may be affected.
(gh-29270)
numpy.ctypeslib.as_ctypesnow does not support scalar typesThe function
numpy.ctypeslib.as_ctypeshas been updated to only acceptnumpy.ndarray. Passing a scalar type (e.g.,numpy.int32(5)) will nowraise a
TypeError. This change was made to avoid the issuegh-30354 and to enforce the
readonly nature of scalar types in NumPy. The previous behavior relied on
undocumented implicit temporary arrays and was not well-defined. Users who
need to convert scalar types to ctypes should first convert them to an array
(e.g.,
numpy.asarray) before passing them tonumpy.ctypeslib.as_ctypes.(gh-30538)
__array_interface__changes on scalarsScalars now export the
__array_interface__directly rather than includingan array copy as a
__refentry. This means that scalars are now exported asread-only while they previously exported as writeable. The path via
__refwas undocumented and not consistently used even within NumPy itself.
(gh-30538)
meshgridnow always returns a tuplenp.meshgridpreviously used to return a list whensparsewas true andcopywas false. Now, it always returns a tuple regardless of thearguments.
(gh-30707)
numpy.triu_indicesnow acceptsunsigned integersnumpy.triu_indicespreviously used to error in some cases whenunsigned integerswere given as arguments. Now, it accepts them in all cases.
(gh-30869)
objectdtype in.realand.imagand related functionsThe array attributes
.realand.imagnow behave differently for objectarrays and return
getattr(element, "real", element)orgetattr(element, "imag", 0)elementwise. Additionally, the return for both is now read-only to avoid possible
in-place changes having no effect.
This change also affects
np.isreal()which usesarr.imag.Previously,
.imagalways returned0while.realreturned theoriginal array unmodified. The new behavior now returnes the correct values
for complex Python objects but may also lead to surprises for example if
element.real()is a method and not a property.(gh-30984)
NumPy's internal memory allocations now use
PyMem_RawMallocNumPy's internal memory allocations now use
PyMem_RawMallocinstead ofmallocand can be tracked bytracemalloc.(gh-31503)
Configuration
📅 Schedule: (in timezone Europe/Paris)
🚦 Automerge: Enabled.
♻ Rebasing: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR has been generated by Mend Renovate CLI.