def _replace_single(self, to_replace, value, inplace=False, filter=None,<EOL>regex=False, convert=True, mask=None):
inplace = validate_bool_kwarg(inplace, '<STR_LIT>')<EOL>to_rep_re = regex and is_re_compilable(to_replace)<EOL>regex_re = is_re_compilable(regex)<EOL>if to_rep_re and regex_re:<EOL><INDENT>raise AssertionError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if regex_re:<EOL><INDENT>to_replace = regex<EOL><DEDENT>regex = regex_re or to_rep_re<EOL>try:<EOL><INDENT>pattern = to_replace.pattern<EOL><DEDENT>except AttributeError:<EOL><INDENT>pattern = to_replace<EOL><DEDENT>if regex and pattern:<EOL><INDENT>rx = re.compile(to_replace)<EOL><DEDENT>else:<EOL><INDENT>return super().replace(to_replace, value, inplace=inplace,<EOL>filter=filter, regex=regex)<EOL><DEDENT>new_values = self.values if inplace else self.values.copy()<EOL>if isna(value) or not isinstance(value, str):<EOL><INDENT>def re_replacer(s):<EOL><INDENT>try:<EOL><INDENT>return value if rx.search(s) is not None else s<EOL><DEDENT>except TypeError:<EOL><INDENT>return s<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>def re_replacer(s):<EOL><INDENT>try:<EOL><INDENT>return rx.sub(value, s)<EOL><DEDENT>except TypeError:<EOL><INDENT>return s<EOL><DEDENT><DEDENT><DEDENT>f = np.vectorize(re_replacer, otypes=[self.dtype])<EOL>if filter is None:<EOL><INDENT>filt = slice(None)<EOL><DEDENT>else:<EOL><INDENT>filt = self.mgr_locs.isin(filter).nonzero()[<NUM_LIT:0>]<EOL><DEDENT>if mask is None:<EOL><INDENT>new_values[filt] = f(new_values[filt])<EOL><DEDENT>else:<EOL><INDENT>new_values[filt][mask] = f(new_values[filt][mask])<EOL><DEDENT>block = self.make_block(new_values)<EOL>if convert:<EOL><INDENT>block = block.convert(by_item=True, numeric=False)<EOL><DEDENT>return block<EOL>
Replace elements by the given value.

Parameters
----------
to_replace : object or pattern
    Scalar to replace or regular expression to match.
value : object
    Replacement object.
inplace : bool, default False
    Perform inplace modification.
filter : list, optional
regex : bool, default False
    If true, perform regular expression substitution.
convert : bool, default True
    If true, try to coerce any object types to better types.
mask : array-like of bool, optional
    True indicate corresponding element is ignored.

Returns
-------
a new block, the result after replacing