Skip to content

Commit 3db333f

Browse files
committed
revert changes in block.putmask
1 parent f657ae3 commit 3db333f

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

pandas/core/internals/blocks.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -801,12 +801,14 @@ def replace(self, to_replace, value, inplace=False, filter=None,
801801
copy=not inplace) for b in blocks]
802802
return blocks
803803
except (TypeError, ValueError):
804-
805-
# try again with a compatible block
806-
block = self.astype(object)
807-
return block.replace(
808-
to_replace=original_to_replace, value=value, inplace=inplace,
809-
filter=filter, regex=regex, convert=convert)
804+
if self.dtype == 'object':
805+
raise
806+
else:
807+
# try again with a compatible block
808+
block = self.astype(object)
809+
return block.replace(
810+
to_replace=original_to_replace, value=value, inplace=inplace,
811+
filter=filter, regex=regex, convert=convert)
810812

811813
def _replace_single(self, *args, **kwargs):
812814
""" no-op on a non-ObjectBlock """
@@ -992,16 +994,15 @@ def putmask(self, mask, new, align=True, inplace=False, axis=0,
992994
#
993995
# TODO: this prob needs some better checking
994996
# for 2D cases
995-
if ((is_list_like(new) and np.any(mask[mask]) and
997+
if ((is_list_like(new) and
998+
np.any(mask[mask]) and
996999
getattr(new, 'ndim', 1) == 1)):
1000+
9971001
if not (mask.shape[-1] == len(new) or
9981002
mask[mask].shape[-1] == len(new) or
9991003
len(new) == 1):
1000-
# GH 19266 and GH 21977
1001-
# ValueError triggers try except block in Block.replace
1002-
# causing RecursionError
1003-
raise Exception("cannot assign mismatch length "
1004-
"to masked array")
1004+
raise ValueError("cannot assign mismatch length "
1005+
"to masked array")
10051006

10061007
np.putmask(new_values, mask, new)
10071008

0 commit comments

Comments
 (0)