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

Method _str_extract

pandas/core/strings/object_array.py:506–529  ·  view source on GitHub ↗
(self, pat: str, flags: int = 0, expand: bool = True)

Source from the content-addressed store, hash-verified

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))

Callers 1

extractMethod · 0.45

Calls 2

_str_mapMethod · 0.95
fFunction · 0.50

Tested by

no test coverage detected