In addition to the usual bug fixes, this NumPy release cleans up and documents the new random C-API, expires a large number of old deprecations, and improves the appearance of the documentation. The Python versions supported are 3.5-3.8. This is the last NumPy release series that will support Python 3.5.
Downstream developers should use Cython >= 0.29.14 for Python 3.8 support and OpenBLAS >= 3.7 to avoid problems on the Skylake architecture.
The C-API for numpy.random has been defined and documented.
numpy.random
Basic infrastructure for linking with 64 bit BLAS and LAPACK libraries.
Many documentation improvements.
The method multivariate_hypergeometric has been added to the class numpy.random.Generator. This method generates random variates from the multivariate hypergeometric probability distribution. (gh-13794)
multivariate_hypergeometric
numpy.random.Generator
np.fromfile
np.fromstring
In future numpy releases, the functions np.fromfile and np.fromstring will throw an error when parsing bad data. This will now give a DeprecationWarning where previously partial or even invalid data was silently returned. This deprecation also affects the C defined functions PyArray_FromString and PyArray_FromFile (gh-13605)
DeprecationWarning
PyArray_FromString
PyArray_FromFile
ma.fill_value
Setting a MaskedArray.fill_value to a non-scalar array is deprecated since the logic to broadcast the fill value to the array is fragile, especially when slicing. (gh-13698)
MaskedArray.fill_value
PyArray_As1D
PyArray_As2D
PyArray_As1D, PyArray_As2D are deprecated, use PyArray_AsCArray instead (gh-14036)
PyArray_AsCArray
np.alen
np.alen was deprecated. Use len instead. (gh-14181)
len
In accordance with NEP-32, the financial functions fv ipmt, irr, mirr, nper, npv, pmt, ppmt, pv and rate are deprecated, and will be removed from NumPy 1.20.The replacement for these functions is the Python package numpy-financial. (gh-14720)
fv
ipmt
irr
mirr
nper
npv
pmt
ppmt
pv
rate
axis
numpy.ma.mask_cols
numpy.ma.mask_row
This argument was always ignored. (gh-14996)
PyArray_As1D and PyArray_As2D have been removed in favor of PyArray_AsCArray (gh-14036)
np.rank has been removed. This was deprecated in NumPy 1.10 and has been replaced by np.ndim. (gh-14039)
np.rank
np.ndim
The deprecation of expand_dims out-of-range axes in 1.13.0 has expired. (gh-14051)
expand_dims
PyArray_FromDimsAndDataAndDescr and PyArray_FromDims have been removed (they will always raise an error). Use PyArray_NewFromDescr and PyArray_SimpleNew instead. (gh-14100)
PyArray_FromDimsAndDataAndDescr
PyArray_FromDims
PyArray_NewFromDescr
PyArray_SimpleNew
numeric.loads, numeric.load, np.ma.dump, np.ma.dumps, np.ma.load, np.ma.loads are removed, use pickle methods instead (gh-14256)
numeric.loads
numeric.load
np.ma.dump
np.ma.dumps
np.ma.load
np.ma.loads
pickle
arrayprint.FloatFormat, arrayprint.LongFloatFormat has been removed, use FloatingFormat instead
arrayprint.FloatFormat
arrayprint.LongFloatFormat
FloatingFormat
arrayprint.ComplexFormat, arrayprint.LongComplexFormat has been removed, use ComplexFloatingFormat instead
arrayprint.ComplexFormat
arrayprint.LongComplexFormat
ComplexFloatingFormat
arrayprint.StructureFormat has been removed, use StructureVoidFormat instead (gh-14259)
arrayprint.StructureFormat
StructureVoidFormat
np.testing.rand has been removed. This was deprecated in NumPy 1.11 and has been replaced by np.random.rand. (gh-14325)
np.testing.rand
np.random.rand
Class SafeEval in numpy/lib/utils.py has been removed. This was deprecated in NumPy 1.10. Use np.safe_eval instead. (gh-14335)
SafeEval
numpy/lib/utils.py
np.safe_eval
Remove deprecated support for boolean and empty condition lists in np.select (gh-14583)
np.select
Array order only accepts ‘C’, ‘F’, ‘A’, and ‘K’. More permissive options were deprecated in NumPy 1.11. (gh-14596)
np.linspace parameter num must be an integer. Deprecated in NumPy 1.12. (gh-14620)
num
UFuncs with multiple outputs must use a tuple for the out kwarg. This finishes a deprecation started in NumPy 1.10. (gh-14682)
out
The files numpy/testing/decorators.py, numpy/testing/noseclasses.py and numpy/testing/nosetester.py have been removed. They were never meant to be public (all relevant objects are present in the numpy.testing namespace), and importing them has given a deprecation warning since NumPy 1.15.0 (gh-14567)
numpy/testing/decorators.py
numpy/testing/noseclasses.py
numpy/testing/nosetester.py
numpy.testing
numpy.lib.recfunctions.drop_fields
If drop_fields is used to drop all fields, previously the array would be completely discarded and None returned. Now it returns an array of the same shape as the input, but with no fields. The old behavior can be retained with:
drop_fields
dropped_arr = drop_fields(arr, ['a', 'b']) if dropped_arr.dtype.names == (): dropped_arr = None
converting the empty recarray to None (gh-14510)
numpy.argmin/argmax/min/max
NaT
numpy.argmin, numpy.argmax, numpy.min, and numpy.max will return NaT if it exists in the array. (gh-14717)
numpy.argmin
numpy.argmax
numpy.min
numpy.max
np.can_cast(np.uint64, np.timedelta64, casting='safe')
False
Previously this was True - however, this was inconsistent with uint64 not being safely castable to int64, and resulting in strange type resolution.
True
uint64
int64
If this impacts your code, cast uint64 to int64 first. (gh-14718)
numpy.random.Generator.integers
There was a bug in numpy.random.Generator.integers that caused biased sampling of 8 and 16 bit integer types. Fixing that bug has changed the output stream from what it was in previous releases. (gh-14777)
datetime64
timedelta64
np.datetime('NaT') should behave more like float('Nan'). Add needed infrastructure so np.isinf(a) and np.isnan(a) will run on datetime64 and timedelta64 dtypes. Also added specific loops for numpy.fmin and numpy.fmax that mask NaT. This may require adjustment to user- facing code. Specifically, code that either disallowed the calls to numpy.isinf or numpy.isnan or checked that they raised an exception will require adaptation, and code that mistakenly called numpy.fmax and numpy.fmin instead of numpy.maximum or numpy.minimum respectively will require adjustment. This also affects numpy.nanmax and numpy.nanmin. (gh-14841)
np.datetime('NaT')
float('Nan')
np.isinf(a)
np.isnan(a)
numpy.fmin
numpy.fmax
numpy.isinf
numpy.isnan
numpy.maximum
numpy.minimum
numpy.nanmax
numpy.nanmin
As part of the API cleanup, the submodules in numpy.random bit_generator, philox, pcg64, sfc64, ``common, generator, and bounded_integers were moved to _bit_generator, _philox, _pcg64, _sfc64, ``_common, _generator, and _bounded_integers respectively to indicate that they are not part of the public interface. (gh-14608)
bit_generator
philox
pcg64
sfc64, ``common
generator
bounded_integers
_bit_generator
_philox
_pcg64
_sfc64, ``_common
_generator
_bounded_integers
PyDataType_ISUNSIZED(descr)
Previously this returned True for any datatype of itemsize 0, but now this returns false for the non-flexible datatype with itemsize 0, np.dtype([]). (gh-14393)
np.dtype([])
*.pxd
Added a numpy/__init__.pxd file. It will be used for cimport numpy (gh-12284)
numpy/__init__.pxd
cimport numpy
The numpy.expand_dims axis keyword can now accept a tuple of axes. Previously, axis was required to be an integer. (gh-14051)
numpy.expand_dims
Added support for 64-bit (ILP64) OpenBLAS. See site.cfg.example for details. (gh-15012)
site.cfg.example
--f2cmap
Allow specifying a file to load Fortran-to-C type map customizations from. (gh-15113)
On any given platform, two of np.intc, np.int_, and np.longlong would previously appear indistinguishable through their repr, despite their corresponding dtype having different properties. A similar problem existed for the unsigned counterparts to these types, and on some platforms for np.double and np.longdouble
np.intc
np.int_
np.longlong
repr
dtype
np.double
np.longdouble
These types now always print with a unique __name__. (gh-10151)
__name__
argwhere
On N-d arrays, numpy.argwhere now always produces an array of shape (n_non_zero, arr.ndim), even when arr.ndim == 0. Previously, the last axis would have a dimension of 1 in this case. (gh-13610)
numpy.argwhere
(n_non_zero, arr.ndim)
arr.ndim == 0
random.permutation
random.shuffle
Previously the random.permutation and random.shuffle functions can only shuffle an array along the first axis; they now have a new argument axis which allows shuffle along a specified axis. (gh-13829)
method
np.random.multivariate_normal
A method keyword argument is now available for np.random.multivariate_normal with possible values {'svd', 'eigh', 'cholesky'}. To use it, write np.random.multivariate_normal(..., method=<method>). (gh-14197)
{'svd', 'eigh', 'cholesky'}
np.random.multivariate_normal(..., method=<method>)
numpy.fromstring
Now numpy.fromstring can read complex numbers. (gh-14227)
numpy.unique
Using moveaxis instead of swapaxes in numpy.unique, so that the ordering of axes except the axis in arguments will not be broken. (gh-14255)
moveaxis
swapaxes
numpy.matmul
Calling numpy.matmul where the output is a boolean array would fill the array with uint8 equivalents of the result, rather than 0/1. Now it forces the output to 0 or 1 (NPY_TRUE or NPY_FALSE). (gh-14464)
NPY_TRUE
NPY_FALSE
numpy.random.randint
2**32
The implementation introduced in 1.17.0 had an incorrect check when determining whether to use the 32-bit path or the full 64-bit path that incorrectly redirected random integer generation with a high - low range of 2**32 to the 64-bit generator. (gh-14501)
numpy.fromfile
Now numpy.fromfile can read complex numbers. (gh-14730)
std=c99
gcc
GCC before version 5 requires the -std=c99 command line argument. Newer compilers automatically turn on C99 mode. The compiler setup code will automatically add the code if the compiler name has gcc in it. (gh-14771)
-std=c99
NaT is now effectively treated as the largest integer for sorting purposes, so that it sorts to the end of arrays. This change is for consistency with NaN sorting behavior. (gh-12658) (gh-15068)
NaN
threshold
np.set_printoptions
TypeError
ValueError
Previously an incorrect threshold raised ValueError; it now raises TypeError for non-numeric types and ValueError for nan values. (gh-13899)
nan
A UserWarning will be emitted when saving an array via numpy.save with metadata. Saving such an array may not preserve metadata, and if metadata is preserved, loading it will cause a ValueError. This shortcoming in save and load will be addressed in a future release. (gh-14142)
UserWarning
numpy.save
metadata
numpy.distutils
numpy.distutils has always overridden rather than appended to LDFLAGS and other similar such environment variables for compiling Fortran extensions. Now the default behavior has changed to appending - which is the expected behavior in most situations. To preserve the old (overwriting) behavior, set the NPY_DISTUTILS_APPEND_FLAGS environment variable to 0. This applies to: LDFLAGS, F77FLAGS, F90FLAGS, FREEFLAGS, FOPT, FDEBUG, and FFLAGS. NumPy 1.16 and 1.17 gave build warnings in situations where this change in behavior would have affected the compile flags used. (gh-14248)
LDFLAGS
NPY_DISTUTILS_APPEND_FLAGS
F77FLAGS
F90FLAGS
FREEFLAGS
FOPT
FDEBUG
FFLAGS
numpy.random.entropy
numpy.random.entropy was added to the numpy.random namespace in 1.17.0. It was meant to be a private c-extension module, but was exposed as public. It has been replaced by numpy.random.SeedSequence so the module was completely removed. (gh-14498)
numpy.random.SeedSequence
-Werror
Added two new configuration options. During the build_src subcommand, as part of configuring NumPy, the files _numpyconfig.h and config.h are created by probing support for various runtime functions and routines. Previously, the very verbose compiler output during this stage clouded more important information. By default the output is silenced. Running runtests.py --debug-info will add --verbose-cfg to the build_src subcommand,which will restore the previous behaviour.
build_src
_numpyconfig.h
config.h
runtests.py --debug-info
--verbose-cfg
Adding CFLAGS=-Werror to turn warnings into errors would trigger errors during the configuration. Now runtests.py --warn-error will add --warn-error to the build subcommand, which will percolate to the build_ext and build_lib subcommands. This will add the compiler flag to those stages and turn compiler warnings into errors while actually building NumPy itself, avoiding the build_src subcommand compiler calls.
CFLAGS=-Werror
runtests.py --warn-error
--warn-error
build
build_ext
build_lib
(gh-14527) (gh-14518)