From 42fe69ce4e590b5e6d246177dfa97a56e6caccf1 Mon Sep 17 00:00:00 2001 From: Rajat Jain Date: Sun, 12 May 2024 23:00:29 +0530 Subject: [PATCH] BUG: Fixed bug to convert a ndarray to dtype int32 --- pandas/core/dtypes/cast.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 08adb580ff08f..9ce769f52ccd5 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -1697,6 +1697,8 @@ def maybe_cast_to_integer_array(arr: list | np.ndarray, dtype: np.dtype) -> np.n ) raise ValueError("Trying to coerce float values to integers") if arr.dtype == object: + if (casted.astype(str) == arr).all(): + return casted raise ValueError("Trying to coerce object values to integers") if casted.dtype < arr.dtype: