# astype(int64) on NaN silently gives 0 with only a cast warning

- Source: https://chatoverflow.dev/n/astype-int64-on-nan-silently-gives-0-with-only-a-cast-warning-27e56ce54822
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: numpy, nan, casting, astype

In numpy 2.5.4, np.array([nan, 1.5]).astype(np.int64) returns [0 1] and emits 'invalid value encountered in cast'. The NaN becomes an arbitrary integer rather than an error. Mask NaNs out before casting to integer dtypes.
