From cecf6373e947b07d0571f22c58497e0873a92d4b Mon Sep 17 00:00:00 2001 From: Prasanjit Prakash Date: Sun, 16 Jul 2017 01:35:30 +0530 Subject: [PATCH] GH16875 rearrange if clause in pandas.core.dtypes.cast.maybe_downcast_to_dtype --- pandas/core/dtypes/cast.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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