# Buggy code
def _replace_list(
    self,
    src_list: List[Any],
    dest_list: List[Any],
    masks: List[np.ndarray],
    inplace: bool = False,
    regex: bool = False,
) -> List["Block"]:
    """
    See BlockManager._replace_list docstring.
    """
    src_len = len(src_list) - 1

    rb = [self if inplace else self.copy()]
    for i, (src, dest) in enumerate(zip(src_list, dest_list)):
        new_rb: List["Block"] = []
        for blk in rb:
            m = masks[i][blk.mgr_locs.indexer]
            convert = i == src_len  # only convert once at the end
            result = blk._replace_coerce(
                mask=m,
                to_replace=src,
                value=dest,
                inplace=inplace,
                convert=convert,
                regex=regex,
            )
            if m.any() or convert:
                if isinstance(result, list):
                    new_rb.extend(result)
                else:
                    new_rb.append(result)
            else:
                new_rb.append(blk)
        rb = new_rb
    return rb


# Traceback (TypeError)
Traceback (most recent call last):
File "/home/developer/.config/JetBrains/PyCharmCE2020.1/scratches/scratch_1.py", line 7, in <module>
df = df.replace({"replace_string": "test"})
File "/home/developer/PycharmProjects/pandas/pandas/core/frame.py", line 4277, in replace
return super().replace(
File "/home/developer/PycharmProjects/pandas/pandas/core/generic.py", line 6598, in replace
return self.replace(
File "/home/developer/PycharmProjects/pandas/pandas/core/frame.py", line 4277, in replace
return super().replace(
File "/home/developer/PycharmProjects/pandas/pandas/core/generic.py", line 6641, in replace
new_data = self._mgr.replace_list(
File "/home/developer/PycharmProjects/pandas/pandas/core/internals/managers.py", line 616, in replace_list
masks = [comp(s, regex) for s in src_list]
File "/home/developer/PycharmProjects/pandas/pandas/core/internals/managers.py", line 616, in <listcomp>
masks = [comp(s, regex) for s in src_list]
File "/home/developer/PycharmProjects/pandas/pandas/core/internals/managers.py", line 614, in comp
return _compare_or_regex_search(values, s, regex)
File "/home/developer/PycharmProjects/pandas/pandas/core/internals/managers.py", line 1946, in _compare_or_regex_search
_check_comparison_types(False, a, b)
File "/home/developer/PycharmProjects/pandas/pandas/core/internals/managers.py", line 1925, in _check_comparison_types
raise TypeError(
TypeError: Cannot compare types 'ndarray(dtype=int64)' and 'str'

Process finished with exit code 1

# Fixed code
def _replace_list(
    self,
    src_list: List[Any],
    dest_list: List[Any],
    inplace: bool = False,
    regex: bool = False,
) -> List["Block"]:
    """
    See BlockManager._replace_list docstring.
    """
    src_len = len(src_list) - 1

    def comp(s: Scalar, mask: np.ndarray, regex: bool = False) -> np.ndarray:
        """
        Generate a bool array by perform an equality check, or perform
        an element-wise regular expression matching
        """
        if isna(s):
            return ~mask

        s = com.maybe_box_datetimelike(s)
        return compare_or_regex_search(self.values, s, regex, mask)

    # Calculate the mask once, prior to the call of comp
    # in order to avoid repeating the same computations
    mask = ~isna(self.values)

    masks = [comp(s, mask, regex) for s in src_list]

    rb = [self if inplace else self.copy()]
    for i, (src, dest) in enumerate(zip(src_list, dest_list)):
        new_rb: List["Block"] = []
        for blk in rb:
            m = masks[i]
            convert = i == src_len  # only convert once at the end
            result = blk._replace_coerce(
                mask=m,
                to_replace=src,
                value=dest,
                inplace=inplace,
                convert=convert,
                regex=regex,
            )
            if m.any() or convert:
                if isinstance(result, list):
                    new_rb.extend(result)
                else:
                    new_rb.append(result)
            else:
                new_rb.append(blk)
        rb = new_rb
    return rb