| 504 | return self._str_map(lambda x: x.removesuffix(suffix)) |
| 505 | |
| 506 | def _str_extract(self, pat: str, flags: int = 0, expand: bool = True): |
| 507 | regex = re.compile(pat, flags=flags) |
| 508 | na_value = self.dtype.na_value # type: ignore[attr-defined] |
| 509 | |
| 510 | if not expand: |
| 511 | |
| 512 | def g(x): |
| 513 | m = regex.search(x) |
| 514 | return m.groups()[0] if m else na_value |
| 515 | |
| 516 | return self._str_map(g, convert=False) |
| 517 | |
| 518 | empty_row = [na_value] * regex.groups |
| 519 | |
| 520 | def f(x): |
| 521 | if not isinstance(x, str): |
| 522 | return empty_row |
| 523 | m = regex.search(x) |
| 524 | if m: |
| 525 | return [na_value if item is None else item for item in m.groups()] |
| 526 | else: |
| 527 | return empty_row |
| 528 | |
| 529 | return [f(val) for val in np.asarray(self)] |
| 530 | |
| 531 | def _str_zfill(self, width: int): |
| 532 | return self._str_map(lambda x: x.zfill(width)) |