NumPy 1.25.0 Release Notes#
Deprecations#
np.core.MachAr
is deprecated. It is private API. In names defined innp.core
should generally be considered private.(gh-22638)
np.finfo(None)
is deprecated.(gh-23011)
np.round_
is deprecated. Use np.round instead.(gh-23302)
np.product
is deprecated. Use np.prod instead.np.cumproduct
is deprecated. Use np.cumprod instead.np.sometrue
is deprecated. Use np.any instead.np.alltrue
is deprecated. Use np.all instead.(gh-23314)
Expired deprecations#
np.core.machar
andnp.finfo.machar
have been removed.(gh-22638)
+arr
will now raise an error when the dtype is not numeric (and positive is undefined).(gh-22998)
A sequence must now be passed into the stacking family of functions (
stack
,vstack
,hstack
,dstack
andcolumn_stack
).(gh-23019)
np.clip
now defaults to same-kind casting. Falling back to unsafe casting was deprecated in NumPy 1.17.np.clip
will now propagatenp.nan
values passed asmin
ormax
. Previously, a scalar NaN was usually ignored. This was deprecated in NumPy 1.17.(gh-23403)
==
and !=
warnings finalized#
The ==
and !=
operators on arrays now always:
raise errors that occur during comparisons such as when the arrays have incompatible shapes (
np.array([1, 2]) == np.array([1, 2, 3])
).return an array of all
True
or allFalse
when values are fundamentally not comparable (e.g. have different dtypes). An example isnp.array(["a"]) == np.array([1])
.
This mimics the Python behavior of returning False
and True
when comparing incompatible types like "a" == 1
and "a" != 1
.
For a long time these gave DeprecationWarning
or FutureWarning
.
(gh-22707)
Nose support has been removed#
NumPy switched to using pytest in 2018 and nose has been unmaintained for many years. We have kept NumPy’s nose support to avoid breaking downstream projects who might have been using it and not yet switched to pytest or some other testing framework. With the arrival of Python 3.12, unpatched nose will raise an error. It is time to move on.
Decorators removed#
raises
slow
setastest
skipif
knownfailif
deprecated
parametrize
_needs_refcount
These are not to be confused with pytest versions with similar names, e.g., pytest.mark.slow, pytest.mark.skipif, pytest.mark.parametrize.
Functions removed#
Tester
import_nose
run_module_suite
(gh-23041)
The numpy.testing.utils
shim has been removed.#
Importing from the numpy.testing.utils
shim has been deprecated since 2019,
the shim has now been removed. All imports should be made directly from
numpy.testing
.
(gh-23060)
Environment variable to disable dispatching removed#
Support for the NUMPY_EXPERIMENTAL_ARRAY_FUNCTION
environment variable has
been removed. This variable disabled dispatching with __array_function__
.
Support for y=
as an alias of out=
removed#
The fix
, isposinf
and isneginf
functions allowed using y=
as a
(deprecated) alias for out=
. This is no longer supported.
(gh-23376)
Compatibility notes#
The
busday_count
method now correctly handles cases where thebegindates
is later in time than theenddates
. Previously, theenddates
was included, even though the documentation states it is always excluded.(gh-23229)
When comparing datetimes and timedelta using
np.equal
ornp.not_equal
numpy previously allowed the comparison withcasting="unsafe"
. This operation now fails. Forcing the output dtype using thedtype
kwarg can make the operation succeed, but we do not recommend it.(gh-22707)
When loading data from a file handle using
np.load
, if the handle is at the end of file, as can happen when reading multiple arrays by callingnp.load
repeatedly, numpy previously raisedValueError
ifallow_pickle=False
, andOSError
ifallow_pickle=True
. Now it raisesEOFError
instead, in both cases.(gh-23105)
np.pad
with mode=wrap
pads with strict multiples of original data#
Code based on earlier version of pad
that uses mode="wrap"
will return
different results when the padding size is larger than initial array.
np.pad
with mode=wrap
now always fills the space with
strict multiples of original data even if the padding size is larger than the
initial array.
(gh-22575)
Cython long_t
and ulong_t
removed#
long_t
and ulong_t
were aliases for longlong_t
and ulonglong_t
and confusing (a remainder from of Python 2). This change may lead to the errors:
'long_t' is not a type identifier
'ulong_t' is not a type identifier
We recommend use of bit-sized types such as cnp.int64_t
or the use of
cnp.intp_t
which is 32 bits on 32 bit systems and 64 bits on 64 bit
systems (this is most compatible with indexing).
If C long
is desired, use plain long
or npy_long
.
cnp.int_t
is also long
(NumPy’s default integer). However, long
is 32 bit on 64 bit windows and we may wish to adjust this even in NumPy.
(Please do not hesitate to contact NumPy developers if you are curious about this.)
(gh-22637)
Changed error message and type for bad axes
argument to ufunc
#
The error message and type when a wrong axes
value is passed to
ufunc(..., axes=[...])`
has changed. The message is now more indicative of
the problem, and if the value is mismatched an AxisError
will be raised.
A TypeError
will still be raised for invalid input types.
(gh-22675)
Array-likes that define __array_ufunc__
can now override ufuncs if used as where
#
If the where
keyword argument of a numpy.ufunc
is a subclass of
numpy.ndarray
or is a duck type that defines
numpy.class.__array_ufunc__
it can override the behavior of the ufunc
using the same mechanism as the input and output arguments.
Note that for this to work properly, the where.__array_ufunc__
implementation will have to unwrap the where
argument to pass it into the
default implementation of the ufunc
or, for numpy.ndarray
subclasses before using super().__array_ufunc__
.
(gh-23240)
New Features#
NumPy now has an np.exceptions
namespace#
NumPy now has a dedicated namespace making most exceptions and warnings available. All of these remain available in the main namespace, although some may be moved slowly in the future. The main reason for this is to increase discoverably and add future exceptions.
(gh-22644)
String functions in np.char are compatible with NEP 42 custom dtypes#
Custom dtypes that represent unicode strings or byte strings can now be passed to the string functions in np.char.
(gh-22863)
String dtype instances can be created from the string abstract dtype classes#
It is now possible to create a string dtype instance with a size without
using the string name of the dtype. For example, type(np.dtype('U'))(8)
will create a dtype that is equivalent to np.dtype('U8')
. This feature
is most useful when writing generic code dealing with string dtype
classes.
(gh-22963)
Fujitsu C/C++ compiler is now supported#
Support for Fujitsu compiler has been added. To build with Fujitsu compiler, run:
python setup.py build -c fujitsu
SSL2 is now supported#
Support for SSL2 has been added. SSL2 is a library that provides OpenBLAS compatible GEMM functions. To enable SSL2, it need to edit site.cfg and build with Fujitsu compiler. See site.cfg.example.
(gh-22982)
Improvements#
The
NDArrayOperatorsMixin
class now specifies that it contains no__slots__
ensureing that subclasses can now make use of this feature in Python.(gh-23113)
Fix power of complex zero#
np.power
now returns a different result for 0^{non-zero}
for complex numbers. Note that the value is only defined when
the real part of the exponent is larger than zero.
Previously, NaN was returned unless the imaginary part was strictly
zero. The return value is either 0+0j
or 0-0j
.
(gh-18535)
New DTypePromotionError
#
NumPy now has a new DTypePromotionError
which is used when two
dtypes cannot be promoted to a common one, for example:
np.result_type("M8[s]", np.complex128)
raises this new exception.
(gh-22707)
np.show_config uses information from Meson#
Build and system information now contains information from Meson.
np.show_config now has a new optional parameter mode
to help
customize the output.
(gh-22769)
Fix np.ma.diff
not preserving the mask when called with arguments prepend/append.#
Calling np.ma.diff
with arguments prepend and/or append now returns a
MaskedArray
with the input mask preserved.
Previously, a MaskedArray
without the mask was returned.
(gh-22776)
Corrected error handling for NumPy C-API in Cython#
Many NumPy C functions defined for use in Cython were lacking the
correct error indicator like except -1
or except *
.
These have now been added.
(gh-22997)
Ability to directly spawn random number generators#
numpy.random.Generator.spawn
now allows to directly spawn new
independent child generators via the numpy.random.SeedSequence.spawn
mechanism.
numpy.random.BitGenerator.spawn
does the same for the underlying
bit generator.
Additionally, numpy.random.BitGenerator.seed_seq
now gives direct
access to the seed sequence used for initializing the bit generator.
This allows for example:
seed = 0x2e09b90939db40c400f8f22dae617151
rng = np.random.default_rng(seed)
child_rng1, child_rng2 = rng.spawn(2)
# safely use rng, child_rng1, and child_rng2
Previously, this was hard to do without passing the SeedSequence
explicitly. Please see numpy.random.SeedSequence
for more information.
(gh-23195)
Performance improvements and changes#
Faster np.sort
on AVX-512 enabled processors#
Quicksort for 16-bit and 64-bit dtypes gain up to 15x and 9x speed up on processors that support AVX-512 instruction set.
Thanks to Intel corporation for sponsoring this work.
(gh-22315)
__array_function__
machinery is now much faster#
The overhead of the majority of functions in NumPy is now smaller especially when keyword arguments are used. This change significantly speeds up many simple function calls.
(gh-23020)
ufunc.at
can be much faster#
Generic ufunc.at
can be up to 9x faster. The conditions for this speedup:
operands are aligned
no casting
If ufuncs with appropriate indexed loops on 1d arguments with the above
conditions, ufunc.at
can be up to 60x faster (an additional 7x speedup).
Appropriate indexed loops have been added to add
, subtract
,
multiply
, floor_divide
, maximum
, minimum
, fmax
, and
fmin
.
The internal logic is similar to the logic used for regular ufuncs, which also have fast paths.
Thanks to the D. E. Shaw group for sponsoring this work.
(gh-23136)
Changes#
Most NumPy functions are wrapped into a C-callable#
To speed up the __array_function__
dispatching, most NumPy functions
are now wrapped into C-callables and are not proper Python functions or
C methods.
They still look and feel the same as before (like a Python function), and this
should only improve performance and user experience (cleaner tracebacks).
However, please inform the NumPy developers if this change confuses your
program for some reason.
(gh-23020)