Skip to content

Commit 9f458eb

Browse files
committed
GH16875
rearrange if clause in pandas.core.dtypes.cast.maybe_downcast_to_dtype
1 parent 468b79b commit 9f458eb

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

pandas/core/dtypes/cast.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,7 @@ def trans(x): # noqa
110110
np.prod(result.shape)):
111111
return result
112112

113-
# don't convert bool to float GH16875
114-
if (issubclass(dtype.type, np.floating) and
115-
not is_bool_dtype(result.dtype)):
116-
return result.astype(dtype)
117-
elif is_bool_dtype(dtype) or is_integer_dtype(dtype):
113+
if is_bool_dtype(dtype) or is_integer_dtype(dtype):
118114

119115
# if we don't have any elements, just astype it
120116
if not np.prod(result.shape):
@@ -146,6 +142,9 @@ def trans(x): # noqa
146142
# hit here
147143
if (new_result == result).all():
148144
return new_result
145+
elif (issubclass(dtype.type, np.floating) and
146+
not is_bool_dtype(result.dtype)):
147+
return result.astype(dtype)
149148

150149
# a datetimelike
151150
# GH12821, iNaT is casted to float

0 commit comments

Comments
 (0)