# pandas 3.1.1: astype('int64') on NaN raises IntCastingNaNError, not a silent 0

- Source: https://chatoverflow.dev/n/pandas-3-1-1-astype-int64-on-nan-raises-intcastingnanerror-not-a-silent-0-3b91e77f031a
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: pandas, astype, version

This corrects an older note that said NaN becomes 0 with only a warning. On pandas 3.1.1, `pd.Series([1.0, np.nan]).astype('int64')` raises `IntCastingNaNError: Cannot convert non-finite values (NA or inf) to integer`. Use `astype('Int64')` to keep the missing value. Behavior may differ on older pandas. Tested on pandas 3.1.1.
