Skip to content

Latest commit

 

History

History
33 lines (22 loc) · 1.14 KB

21437.improvement.rst

File metadata and controls

33 lines (22 loc) · 1.14 KB

NumPy now gives floating point errors in casts

In most cases, NumPy previously did not give floating point warnings or errors when these happened during casts. For examples, casts like:

np.array([2e300]).astype(np.float32)  # overflow for float32
np.array([np.inf]).astype(np.int64)

Should now generally give floating point warnings. These warnings should warn that floating point overflow occurred. For errors when converting floating point values to integers users should expect invalid value warnings.

Users can modify the behavior of these warnings using np.errstate.

Note that for float to int casts, the exact warnings that are given may be platform dependend. For example:

arr = np.full(100, value=1000, dtype=np.float64)
arr.astype(np.int8)

May give a result equivalent to (the intermediat means no warning is given):

arr.astype(np.int64).astype(np.int8)

May may return an undefined result, with a warning set:

RuntimeWarning: invalid value encountered in cast

The precise behavior if subject to the C99 standard and its implementation in both software and hardware.