Test if pattern or regex is contained within each string of the array. Return boolean array based on whether a given pattern or regex is contained within a string of the array. The pattern `pat` can either be a single ``str`` or `re.Pattern` or array-like o
(
self,
pat: str | bytes | Pattern | Any,
case: bool | None = None,
flags: int = 0,
regex: bool = True,
)
| 1448 | return self.rjust(width, fillchar="0") |
| 1449 | |
| 1450 | def contains( |
| 1451 | self, |
| 1452 | pat: str | bytes | Pattern | Any, |
| 1453 | case: bool | None = None, |
| 1454 | flags: int = 0, |
| 1455 | regex: bool = True, |
| 1456 | ) -> T_DataArray: |
| 1457 | """ |
| 1458 | Test if pattern or regex is contained within each string of the array. |
| 1459 | |
| 1460 | Return boolean array based on whether a given pattern or regex is |
| 1461 | contained within a string of the array. |
| 1462 | |
| 1463 | The pattern `pat` can either be a single ``str`` or `re.Pattern` or |
| 1464 | array-like of ``str`` or `re.Pattern`. If array-like, it is broadcast |
| 1465 | against the array and applied elementwise. |
| 1466 | |
| 1467 | Parameters |
| 1468 | ---------- |
| 1469 | pat : str or re.Pattern or array-like of str or re.Pattern |
| 1470 | Character sequence, a string containing a regular expression, |
| 1471 | or a compiled regular expression object. If array-like, it is broadcast. |
| 1472 | case : bool, default: True |
| 1473 | If True, case sensitive. |
| 1474 | Cannot be set if `pat` is a compiled regex. |
| 1475 | Equivalent to setting the `re.IGNORECASE` flag. |
| 1476 | flags : int, default: 0 |
| 1477 | Flags to pass through to the re module, e.g. `re.IGNORECASE`. |
| 1478 | see `compilation-flags <https://docs.python.org/3/howto/regex.html#compilation-flags>`_. |
| 1479 | ``0`` means no flags. Flags can be combined with the bitwise or operator ``|``. |
| 1480 | Cannot be set if `pat` is a compiled regex. |
| 1481 | regex : bool, default: True |
| 1482 | If True, assumes the pat is a regular expression. |
| 1483 | If False, treats the pat as a literal string. |
| 1484 | Cannot be set to `False` if `pat` is a compiled regex. |
| 1485 | |
| 1486 | Returns |
| 1487 | ------- |
| 1488 | contains : array of bool |
| 1489 | An array of boolean values indicating whether the |
| 1490 | given pattern is contained within the string of each element |
| 1491 | of the array. |
| 1492 | """ |
| 1493 | is_compiled_re = _contains_compiled_re(pat) |
| 1494 | if is_compiled_re and not regex: |
| 1495 | raise ValueError( |
| 1496 | "Must use regular expression matching for regular expression object." |
| 1497 | ) |
| 1498 | |
| 1499 | if regex: |
| 1500 | if not is_compiled_re: |
| 1501 | pat = self._re_compile(pat=pat, flags=flags, case=case) |
| 1502 | |
| 1503 | def func(x, ipat): |
| 1504 | if ipat.groups > 0: # pragma: no cover |
| 1505 | raise ValueError("This pattern has match groups.") |
| 1506 | return bool(ipat.search(x)) |
| 1507 |
nothing calls this directly
no test coverage detected