@@ -801,12 +801,14 @@ def replace(self, to_replace, value, inplace=False, filter=None,
801
801
copy = not inplace ) for b in blocks ]
802
802
return blocks
803
803
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 )
810
812
811
813
def _replace_single (self , * args , ** kwargs ):
812
814
""" no-op on a non-ObjectBlock """
@@ -992,16 +994,15 @@ def putmask(self, mask, new, align=True, inplace=False, axis=0,
992
994
#
993
995
# TODO: this prob needs some better checking
994
996
# 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
996
999
getattr (new , 'ndim' , 1 ) == 1 )):
1000
+
997
1001
if not (mask .shape [- 1 ] == len (new ) or
998
1002
mask [mask ].shape [- 1 ] == len (new ) or
999
1003
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" )
1005
1006
1006
1007
np .putmask (new_values , mask , new )
1007
1008
0 commit comments