From b5bd33bebfbf7db205ae5d729e00ca499fddb438 Mon Sep 17 00:00:00 2001 From: Adity Date: Sat, 8 Nov 2025 14:37:11 +0530 Subject: [PATCH 1/2] ENH: Add solution guidance to IntCastingNaNError message (#62838) --- pandas/core/dtypes/astype.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/dtypes/astype.py b/pandas/core/dtypes/astype.py index 75464cbb2b5f9..1e9a92a19ed56 100644 --- a/pandas/core/dtypes/astype.py +++ b/pandas/core/dtypes/astype.py @@ -144,7 +144,9 @@ def _astype_float_to_int_nansafe( """ if not np.isfinite(values).all(): raise IntCastingNaNError( - "Cannot convert non-finite values (NA or inf) to integer" + """Cannot convert non-finite values (NA or inf) to integer. + Replace or remove non-finite values or cast to an integer type + that supports these values (e.g. 'Int64')""" ) if dtype.kind == "u": # GH#45151 From d7a6d4e870c7d1dca26ffc37820f7c5c62df2c33 Mon Sep 17 00:00:00 2001 From: Adity Date: Sat, 8 Nov 2025 15:28:15 +0530 Subject: [PATCH 2/2] ENH: Improve IntCastingNaNError message with solutions --- pandas/core/dtypes/astype.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/dtypes/astype.py b/pandas/core/dtypes/astype.py index 1e9a92a19ed56..94b92ead92374 100644 --- a/pandas/core/dtypes/astype.py +++ b/pandas/core/dtypes/astype.py @@ -144,9 +144,9 @@ def _astype_float_to_int_nansafe( """ if not np.isfinite(values).all(): raise IntCastingNaNError( - """Cannot convert non-finite values (NA or inf) to integer. - Replace or remove non-finite values or cast to an integer type - that supports these values (e.g. 'Int64')""" + "Cannot convert non-finite values (NA or inf) to integer." + "Replace or remove non-finite values or cast to an integer type" + "that supports these values (e.g. 'Int64')" ) if dtype.kind == "u": # GH#45151