From 27673ffd6c6ebff779d494342272eb2dd58a7e66 Mon Sep 17 00:00:00 2001 From: aschade Date: Sat, 2 Dec 2017 19:46:11 -0500 Subject: [PATCH 1/2] BUG: Returning other dtype when first is bool and other is int or float --- pandas/core/internals.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/core/internals.py b/pandas/core/internals.py index f553e1a02c9d6..9189b0eff0412 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -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 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))): From 0f72afd9ec46354d5086edc4f02164ebdd0ca8db Mon Sep 17 00:00:00 2001 From: aschade Date: Sun, 3 Dec 2017 00:24:21 -0500 Subject: [PATCH 2/2] TST: Fixed test failure --- pandas/core/internals.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/internals.py b/pandas/core/internals.py index 9189b0eff0412..957b293ac3156 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -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 @@ -1067,7 +1067,7 @@ def coerce_to_target_dtype(self, other): return self if self.is_bool or is_object_dtype(dtype) or is_bool_dtype(dtype): - if is_float_dtype(dtype) or is_integer_dtype(dtype): + if force_coericion and is_float_dtype(dtype) or is_integer_dtype(dtype): return self.astype(dtype) else: return self.astype(object) @@ -1351,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)