Skip to content

Commit 818adb0

Browse files
committed
CLN: replace in bool block rather than special-casing in common
1 parent 84376e9 commit 818adb0

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

pandas/core/common.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,7 @@ def mask_missing(arr, values_to_mask):
347347
values_to_mask = [values_to_mask]
348348

349349
try:
350-
values = np.array(values_to_mask)
351-
cant_cast = not np.can_cast(values.dtype, arr.dtype, casting='safe')
352-
353-
if cant_cast and arr.dtype == np.bool_:
354-
values_to_mask = values
355-
else:
356-
values_to_mask = np.array(values_to_mask, dtype=arr.dtype)
350+
values_to_mask = np.array(values_to_mask, dtype=arr.dtype)
357351
except Exception:
358352
values_to_mask = np.array(values_to_mask, dtype=object)
359353

pandas/core/internals.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,7 @@ def should_store(self, value):
12161216
return (issubclass(value.dtype.type, np.floating) and
12171217
value.dtype == self.dtype)
12181218

1219+
12191220
class ComplexBlock(FloatOrComplexBlock):
12201221
is_complex = True
12211222

@@ -1355,6 +1356,14 @@ def _try_cast(self, element):
13551356
def should_store(self, value):
13561357
return issubclass(value.dtype.type, np.bool_)
13571358

1359+
def replace(self, to_replace, value, inplace=False, filter=None,
1360+
regex=False):
1361+
to_replace_values = np.atleast_1d(to_replace)
1362+
if not np.can_cast(to_replace_values, bool):
1363+
to_replace = to_replace_values
1364+
return super(BoolBlock, self).replace(to_replace, value,
1365+
inplace=inplace, filter=filter,
1366+
regex=regex)
13581367

13591368
class ObjectBlock(Block):
13601369
is_object = True

0 commit comments

Comments
 (0)