diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index ff137601e3aa6..6532e17695c86 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -110,11 +110,7 @@ def trans(x): # noqa np.prod(result.shape)): return result - # don't convert bool to float GH16875 - if (issubclass(dtype.type, np.floating) and - not is_bool_dtype(result.dtype)): - return result.astype(dtype) - elif is_bool_dtype(dtype) or is_integer_dtype(dtype): + if is_bool_dtype(dtype) or is_integer_dtype(dtype): # if we don't have any elements, just astype it if not np.prod(result.shape): @@ -146,6 +142,9 @@ def trans(x): # noqa # hit here if (new_result == result).all(): return new_result + elif (issubclass(dtype.type, np.floating) and + not is_bool_dtype(result.dtype)): + return result.astype(dtype) # a datetimelike # GH12821, iNaT is casted to float