NumPy

NumPy 1.19.0 Release Notes

Highlights

  • Code compatibility with Python versions < 3.5 (including Python 2) was dropped from both the python and C code. The shims in numpy.compat will remain to support third-party packages, but they may be deprecated in a future release.

    (gh-15233)

Deprecations

Deprecate automatic dtype=object for ragged input

Calling np.array([[1, [1, 2, 3]]) will issue a DeprecationWarning as per NEP 34. Users should explicitly use dtype=object to avoid the warning.

(gh-15119)

Passing shape=0 to factory functions in numpy.rec is deprecated

0 is treated as a special case and is aliased to None in the functions:

In future, 0 will not be special cased, and will be treated as an array length like any other integer.

(gh-15217)

Compatibility notes

Scalar promotion in PyArray_ConvertToCommonType

The promotion of mixed scalars and arrays in PyArray_ConvertToCommonType has been changed to adhere to those used by np.result_type. This means that input such as (1000, np.array([1], dtype=np.uint8))) will now return uint16 dtypes. In most cases the behaviour is unchanged. Note that the use of this C-API function is generally discouraged. This also fixes np.choose to behave the same way as the rest of NumPy in this respect.

(gh-14933)

Fasttake and fastputmask slots are deprecated and NULL’ed

The fasttake and fastputmask slots are now never used and must always be set to NULL. This will result in no change in behaviour. However, if a user dtype should set one of these a DeprecationWarning will be given.

(gh-14942)

np.ediff1d casting behaviour with to_end and to_begin

np.ediff1d now uses the "same_kind" casting rule for its additional to_end and to_begin arguments. This ensures type safety except when the input array has a smaller integer type than to_begin or to_end. In rare cases, the behaviour will be more strict than it was previously in 1.16 and 1.17. This is necessary to solve issues with floating point NaN.

(gh-14981)

Removed multiarray.int_asbuffer

As part of the continued removal of Python 2 compatibility, multiarray.int_asbuffer was removed. On Python 3, it threw a NotImplementedError and was unused internally. It is expected that there are no downstream use cases for this method with Python 3.

(gh-15229)

numpy.distutils.compat has been removed

This module contained only the function get_exception(), which was used as:

try:
    ...
except Exception:
    e = get_exception()

Its purpose was to handle the change in syntax introduced in Python 2.6, from except Exception, e: to except Exception as e:, meaning it was only necessary for codebases supporting Python 2.5 and older.

(gh-15255)

C API changes

Better support for const dimensions in API functions

The following functions now accept a constant array of npy_intp:

  • PyArray_BroadcastToShape

  • PyArray_IntTupleFromIntp

  • PyArray_OverflowMultiplyList

Previously the caller would have to cast away the const-ness to call these functions.

(gh-15251)

Const qualify UFunc inner loops

UFuncGenericFunction now expects pointers to const dimension and strides as arguments. This means inner loops may no longer modify either dimension or strides. This change leads to an incompatible-pointer-types warning forcing users to either ignore the compiler warnings or to const qualify their own loop signatures.

(gh-15355)

New Features

numpy.frompyfunc now accepts an identity argument

This allows the numpy.ufunc.identity attribute to be set on the resulting ufunc, meaning it can be used for empty and multi-dimensional calls to numpy.ufunc.reduce.

(gh-8255)

Improvements

Use 64-bit integer size on 64-bit platforms in fallback lapack_lite

Use 64-bit integer size on 64-bit platforms in the fallback LAPACK library, which is used when the system has no LAPACK installed, allowing it to deal with linear algebra for large arrays.

(gh-15218)

Changes

Remove handling of extra argument to __array__

A code path and test have been in the code since NumPy 0.4 for a two-argument variant of __array__(dtype=None, context=None). It was activated when calling ufunc(op) or ufunc.reduce(op) if op.__array__ existed. However that variant is not documented, and it is not clear what the intention was for its use. It has been removed.

(gh-15118)

NumPy 1.19.0 Release Notes