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

Function should_use_regex

pandas/core/array_algos/replace.py:32–43  ·  view source on GitHub ↗

Decide whether to treat `to_replace` as a regular expression.

(regex: bool, to_replace: Any)

Source from the content-addressed store, hash-verified

30
31
32def should_use_regex(regex: bool, to_replace: Any) -> bool:
33 """
34 Decide whether to treat `to_replace` as a regular expression.
35 """
36 if is_re(to_replace):
37 regex = True
38
39 regex = regex and is_re_compilable(to_replace)
40
41 # Don't use regex if the pattern is empty.
42 regex = regex and re.compile(to_replace).pattern != ""
43 return regex
44
45
46def compare_or_regex_search(

Callers 3

replaceMethod · 0.90
_replace_coerceMethod · 0.90
compare_or_regex_searchFunction · 0.85

Calls 2

is_reFunction · 0.85
is_re_compilableFunction · 0.85

Tested by

no test coverage detected