avoid problems for their users.**
The Python versions supported by this release are 3.9-3.12.
NumPy 2.0 Python API removals
- `np.geterrobj`, `np.seterrobj` and the related ufunc keyword
argument `extobj=` have been removed. The preferred replacement for
all of these is using the context manager `with np.errstate():`.
([gh-23922](https://github.com/numpy/numpy/pull/23922))
- `np.cast` has been removed. The literal replacement for
`np.cast[dtype](arg)` is `np.asarray(arg, dtype=dtype)`.
- `np.source` has been removed. The preferred replacement is
`inspect.getsource`.
- `np.lookfor` has been removed.
([gh-24144](https://github.com/numpy/numpy/pull/24144))
- `numpy.who` has been removed. As an alternative for the removed
functionality, one can use a variable explorer that is available in
IDEs such as Spyder or Jupyter Notebook.
([gh-24321](https://github.com/numpy/numpy/pull/24321))
- Multiple niche enums, expired members and functions have been
removed from the main namespace, such as: `ERR_*`, `SHIFT_*`,
`np.fastCopyAndTranspose`, `np.kernel_version`, `np.numarray`,
`np.oldnumeric` and `np.set_numeric_ops`.
([gh-24316](https://github.com/numpy/numpy/pull/24316))
- Replaced `from ... import *` in the `numpy/__init__.py` with
explicit imports. As a result, these main namespace members got
removed: `np.FLOATING_POINT_SUPPORT`, `np.FPE_*`, `np.NINF`,
`np.PINF`, `np.NZERO`, `np.PZERO`, `np.CLIP`, `np.WRAP`, `np.WRAP`,
`np.RAISE`, `np.BUFSIZE`, `np.UFUNC_BUFSIZE_DEFAULT`,
`np.UFUNC_PYVALS_NAME`, `np.ALLOW_THREADS`, `np.MAXDIMS`,
`np.MAY_SHARE_EXACT`, `np.MAY_SHARE_BOUNDS`, `add_newdoc`,
`np.add_docstring` and `np.add_newdoc_ufunc`.
([gh-24357](https://github.com/numpy/numpy/pull/24357))
- Alias `np.float_` has been removed. Use `np.float64` instead.
- Alias `np.complex_` has been removed. Use `np.complex128` instead.
- Alias `np.longfloat` has been removed. Use `np.longdouble` instead.
- Alias `np.singlecomplex` has been removed. Use `np.complex64`
instead.
- Alias `np.cfloat` has been removed. Use `np.complex128` instead.
- Alias `np.longcomplex` has been removed. Use `np.clongdouble`
instead.
- Alias `np.clongfloat` has been removed. Use `np.clongdouble`
instead.
- Alias `np.string_` has been removed. Use `np.bytes_` instead.
- Alias `np.unicode_` has been removed. Use `np.str_` instead.
- Alias `np.Inf` has been removed. Use `np.inf` instead.
- Alias `np.Infinity` has been removed. Use `np.inf` instead.
- Alias `np.NaN` has been removed. Use `np.nan` instead.
- Alias `np.infty` has been removed. Use `np.inf` instead.
- Alias `np.mat` has been removed. Use `np.asmatrix` instead.
- `np.issubclass_` has been removed. Use the `issubclass` builtin
instead.
- `np.asfarray` has been removed. Use `np.asarray` with a proper dtype
instead.
- `np.set_string_function` has been removed. Use `np.set_printoptions`
instead with a formatter for custom printing of NumPy objects.
- `np.tracemalloc_domain` is now only available from `np.lib`.
- `np.recfromcsv` and `recfromtxt` are now only available from
`np.lib.npyio`.
- `np.issctype`, `np.maximum_sctype`, `np.obj2sctype`,
`np.sctype2char`, `np.sctypes`, `np.issubsctype` were all removed
from the main namespace without replacement, as they where niche
members.
- Deprecated `np.deprecate` and `np.deprecate_with_doc` has been
removed from the main namespace. Use `DeprecationWarning` instead.
- Deprecated `np.safe_eval` has been removed from the main namespace.
Use `ast.literal_eval` instead.
([gh-24376](https://github.com/numpy/numpy/pull/24376))
- `np.find_common_type` has been removed. Use `numpy.promote_types` or
`numpy.result_type` instead. To achieve semantics for the
`scalar_types` argument, use `numpy.result_type` and pass `0`,
`0.0`, or `0j` as a Python scalar instead.
- `np.round_` has been removed. Use `np.round` instead.
- `np.nbytes` has been removed. Use `np.dtype(<dtype>).itemsize`
instead.
([gh-24477](https://github.com/numpy/numpy/pull/24477))
- `np.compare_chararrays` has been removed from the main namespace.
Use `np.char.compare_chararrays` instead.
- The `charrarray` in the main namespace has been deprecated. It can
be imported without a deprecation warning from `np.char.chararray`
for now, but we are planning to fully deprecate and remove
`chararray` in the future.
- `np.format_parser` has been removed from the main namespace. Use
`np.rec.format_parser` instead.
([gh-24587](https://github.com/numpy/numpy/pull/24587))
- Support for seven data type string aliases has been removed from
`np.dtype`: `int0`, `uint0`, `void0`, `object0`, `str0`, `bytes0`
and `bool8`.
([gh-24807](https://github.com/numpy/numpy/pull/24807))
- The experimental `numpy.array_api` submodule has been removed. Use
the main `numpy` namespace for regular usage instead, or the
separate `array-api-strict` package for the compliance testing use
case for which `numpy.array_api` was mostly used.
([gh-25911](https://github.com/numpy/numpy/pull/25911))
`__array_prepare__` is removed
UFuncs called `__array_prepare__` before running computations for normal
ufunc calls (not generalized ufuncs, reductions, etc.). The function was
also called instead of `__array_wrap__` on the results of some linear
algebra functions.
It is now removed. If you use it, migrate to `__array_ufunc__` or rely
on `__array_wrap__` which is called with a context in all cases,
although only after the result array is filled. In those code paths,
`__array_wrap__` will now be passed a base class, rather than a subclass
array.
([gh-25105](https://github.com/numpy/numpy/pull/25105))
Deprecations
- `np.compat` has been deprecated, as Python 2 is no longer supported.
- `np.safe_eval` has been deprecated. `ast.literal_eval` should be
used instead.
([gh-23830](https://github.com/numpy/numpy/pull/23830))
- `np.recfromcsv`, `np.recfromtxt`, `np.disp`, `np.get_array_wrap`,
`np.maximum_sctype`, `np.deprecate` and `np.deprecate_with_doc` have
been deprecated.
([gh-24154](https://github.com/numpy/numpy/pull/24154))
- `np.trapz` has been deprecated. Use `np.trapezoid` or a
`scipy.integrate` function instead.
- `np.in1d` has been deprecated. Use `np.isin` instead.
- Alias `np.row_stack` has been deprecated. Use `np.vstack` directly.
([gh-24445](https://github.com/numpy/numpy/pull/24445))
- `__array_wrap__` is now passed `arr, context, return_scalar` and
support for implementations not accepting all three are deprecated.
Its signature should be
`__array_wrap__(self, arr, context=None, return_scalar=False)`
([gh-25408](https://github.com/numpy/numpy/pull/25408))
- Arrays of 2-dimensional vectors for `np.cross` have been deprecated.
Use arrays of 3-dimensional vectors instead.
([gh-24818](https://github.com/numpy/numpy/pull/24818))
- `np.dtype("a")` alias for `np.dtype(np.bytes_)` was deprecated. Use
`np.dtype("S")` alias instead.
([gh-24854](https://github.com/numpy/numpy/pull/24854))
- Use of keyword arguments `x` and `y` with functions
`assert_array_equal` and `assert_array_almost_equal` has been
deprecated. Pass the first two arguments as positional arguments
instead.
([gh-24978](https://github.com/numpy/numpy/pull/24978))
`numpy.fft` deprecations for n-D transforms with None values in arguments
Using `fftn`, `ifftn`, `rfftn`, `irfftn`, `fft2`, `ifft2`, `rfft2` or
`irfft2` with the `s` parameter set to a value that is not `None` and
the `axes` parameter set to `None` has been deprecated, in line with the
array API standard. To retain current behaviour, pass a sequence \[0,
\..., k-1\] to `axes` for an array of dimension k.
Furthermore, passing an array to `s` which contains `None` values is
deprecated as the parameter is documented to accept a sequence of
integers in both the NumPy docs and the array API specification. To use
the default behaviour of the corresponding 1-D transform, pass the value
matching the default for its `n` parameter. To use the default behaviour
for every axis, the `s` argument can be omitted.
([gh-25495](https://github.com/numpy/numpy/pull/25495))
`np.linalg.lstsq` now defaults to a new `rcond` value
`numpy.linalg.lstsq` now uses the new rcond value of the
machine precision times `max(M, N)`. Previously, the machine precision
was used but a FutureWarning was given to notify that this change will
happen eventually. That old behavior can still be achieved by passing
`rcond=-1`.
([gh-25721](https://github.com/numpy/numpy/pull/25721))
Expired deprecations
- The `np.core.umath_tests` submodule has been removed from the public
API. (Deprecated in NumPy 1.15)
([gh-23809](https://github.com/numpy/numpy/pull/23809))
- The `PyDataMem_SetEventHook` deprecation has expired and it is
removed. Use `tracemalloc` and the `np.lib.tracemalloc_domain`
domain. (Deprecated in NumPy 1.23)
([gh-23921](https://github.com/numpy/numpy/pull/23921))
- The deprecation of `set_numeric_ops` and the C functions
`PyArray_SetNumericOps` and `PyArray_GetNumericOps` has been expired
and the functions removed. (Deprecated in NumPy 1.16)
([gh-23998](https://github.com/numpy/numpy/pull/23998))
- The `fasttake`, `fastclip`, and `fastputmask` `ArrFuncs` deprecation
is now finalized.
- The deprecated function `fastCopyAndTranspose` and its C counterpart
are now removed.
- The deprecation of `PyArray_ScalarFromObject` is now finalized.
([gh-24312](https://github.com/numpy/numpy/pull/24312))
- `np.msort` has been removed. For a replacement, `np.sort(a, axis=0)`
should be used instead.
([gh-24494](https://github.com/numpy/numpy/pull/24494))
- `np.dtype(("f8", 1)` will now return a shape 1 subarray dtype rather
than a non-subarray one.
([gh-25761](https://github.com/numpy/numpy/pull/25761))
- Assigning to the `.data` attribute of an ndarray is disallowed and
will raise.
- `np.binary_repr(a, width)` will raise if width is too small.
- Using `NPY_CHAR` in `PyArray_DescrFromType()` will raise, use
`NPY_STRING` `NPY_UNICODE`, or `NPY_VSTRING` instead.
([gh-25794](https://github.com/numpy/numpy/pull/25794))
Compatibility notes
`loadtxt` and `genfromtxt` default encoding changed
`loadtxt` and `genfromtxt` now both default to `encoding=None` which may
mainly modify how `converters` work. These will now be passed `str`
rather than `bytes`. Pass the encoding explicitly to always get the new
or old behavior. For `genfromtxt` the change also means that returned
values will now be unicode strings rather than bytes.
([gh-25158](https://github.com/numpy/numpy/pull/25158))
`f2py` compatibility notes
- `f2py` will no longer accept ambiguous `-m` and `.pyf` CLI
combinations. When more than one `.pyf` file is passed, an error is
raised. When both `-m` and a `.pyf` is passed, a warning is emitted
and the `-m` provided name is ignored.
([gh-25181](https://github.com/numpy/numpy/pull/25181))
- The `f2py.compile()` helper has been removed because it leaked
memory, has been marked as experimental for several years now, and
was implemented as a thin `subprocess.run` wrapper. It was also one
of the test bottlenecks. See
[gh-25122](https://github.com/numpy/numpy/issues/25122) for the full
rationale. It also used several `np.distutils` features which are
too fragile to be ported to work with `meson`.
- Users are urged to replace calls to `f2py.compile` with calls to
`subprocess.run("python", "-m", "numpy.f2py",...` instead, and to
use environment variables to interact with `meson`. [Native
files](https://mesonbuild.com/Machine-files.html) are also an
option.
([gh-25193](https://github.com/numpy/numpy/pull/25193))
Minor changes in behavior of sorting functions
Due to algorithmic changes and use of SIMD code, sorting functions with
methods that aren\'t stable may return slightly different results in