MCPcopy
hub / github.com/pandas-dev/pandas / _str_replace

Method _str_replace

pandas/core/strings/object_array.py:172–196  ·  view source on GitHub ↗
(
        self,
        pat: str | re.Pattern,
        repl: str | Callable,
        n: int = -1,
        case: bool = True,
        flags: int = 0,
        regex: bool = True,
    )

Source from the content-addressed store, hash-verified

170 return self._str_map(f, na_value=na, dtype=np.dtype(bool))
171
172 def _str_replace(
173 self,
174 pat: str | re.Pattern,
175 repl: str | Callable,
176 n: int = -1,
177 case: bool = True,
178 flags: int = 0,
179 regex: bool = True,
180 ):
181 if case is False:
182 # add case flag, if provided
183 flags |= re.IGNORECASE
184
185 if regex or flags or callable(repl):
186 if not isinstance(pat, re.Pattern):
187 if regex is False:
188 pat = re.escape(pat)
189 pat = re.compile(pat, flags=flags)
190
191 n = n if n >= 0 else 0
192 f = lambda x: pat.sub(repl=repl, string=x, count=n)
193 else:
194 f = lambda x: x.replace(pat, repl, n)
195
196 return self._str_map(f, dtype=str)
197
198 def _str_repeat(self, repeats: int | Sequence[int]):
199 if lib.is_integer(repeats):

Callers 1

replaceMethod · 0.45

Calls 3

_str_mapMethod · 0.95
subMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected