Skip to content

Fix bool float no coercion #18607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ def f(m, v, i):

return [self.make_block(new_values)]

def coerce_to_target_dtype(self, other):
def coerce_to_target_dtype(self, other, force_coericion=False):
"""
coerce the current block to a dtype compat for other
we will return a block, possibly object, and not raise
Expand All @@ -1067,8 +1067,10 @@ def coerce_to_target_dtype(self, other):
return self

if self.is_bool or is_object_dtype(dtype) or is_bool_dtype(dtype):
# we don't upcast to bool
return self.astype(object)
if force_coericion and is_float_dtype(dtype) or is_integer_dtype(dtype):
return self.astype(dtype)
else:
return self.astype(object)

elif ((self.is_float or self.is_complex) and
(is_integer_dtype(dtype) or is_float_dtype(dtype))):
Expand Down Expand Up @@ -1349,7 +1351,7 @@ def eval(self, func, other, errors='raise', try_cast=False, mgr=None):
values, values_mask, other, other_mask = self._try_coerce_args(
transf(values), other)
except TypeError:
block = self.coerce_to_target_dtype(orig_other)
block = self.coerce_to_target_dtype(orig_other, True)
return block.eval(func, orig_other,
errors=errors,
try_cast=try_cast, mgr=mgr)
Expand Down