Skip to content

Commit dae0096

Browse files
committed
fix replace
1 parent b90bbaa commit dae0096

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

pandas/core/internals.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ def replace(self, to_replace, value, inplace=False, filter=None,
718718

719719
inplace = validate_bool_kwarg(inplace, 'inplace')
720720
original_to_replace = to_replace
721-
mask = isnull(self.values)
721+
722722
# try to replace, if we raise an error, convert to ObjectBlock and
723723
# retry
724724
try:
@@ -736,12 +736,8 @@ def replace(self, to_replace, value, inplace=False, filter=None,
736736
return blocks
737737
except (TypeError, ValueError):
738738

739-
# we can't process the value, but nothing to do
740-
if not mask.any():
741-
return self if inplace else self.copy()
742-
743739
# try again with a compatible block
744-
block = self.coerce_to_target_dtype(value)
740+
block = self.astype(object)
745741
return block.replace(
746742
to_replace=original_to_replace, value=value, inplace=inplace,
747743
filter=filter, regex=regex, convert=convert)

0 commit comments

Comments
 (0)