MCPcopy
hub / github.com/pydata/xarray / slice_replace

Method slice_replace

xarray/core/accessor_str.py:387–432  ·  view source on GitHub ↗

Replace a positional slice of a string with another value. If `start`, `stop`, or 'repl` is array-like, they are broadcast against the array and applied elementwise. Parameters ---------- start : int or array-like of int, optional Left i

(
        self,
        start: int | Any | None = None,
        stop: int | Any | None = None,
        repl: str | bytes | Any = "",
    )

Source from the content-addressed store, hash-verified

385 return self._apply(func=f, func_args=(start, stop, step))
386
387 def slice_replace(
388 self,
389 start: int | Any | None = None,
390 stop: int | Any | None = None,
391 repl: str | bytes | Any = "",
392 ) -> T_DataArray:
393 """
394 Replace a positional slice of a string with another value.
395
396 If `start`, `stop`, or 'repl` is array-like, they are broadcast
397 against the array and applied elementwise.
398
399 Parameters
400 ----------
401 start : int or array-like of int, optional
402 Left index position to use for the slice. If not specified (None),
403 the slice is unbounded on the left, i.e. slice from the start
404 of the string. If array-like, it is broadcast.
405 stop : int or array-like of int, optional
406 Right index position to use for the slice. If not specified (None),
407 the slice is unbounded on the right, i.e. slice until the
408 end of the string. If array-like, it is broadcast.
409 repl : str or array-like of str, default: ""
410 String for replacement. If not specified, the sliced region
411 is replaced with an empty string. If array-like, it is broadcast.
412
413 Returns
414 -------
415 replaced : same type as values
416 """
417 repl = self._stringify(repl)
418
419 def func(x, istart, istop, irepl):
420 if len(x[istart:istop]) == 0:
421 local_stop = istart
422 else:
423 local_stop = istop
424 y = self._stringify("")
425 if istart is not None:
426 y += x[:istart]
427 y += irepl
428 if istop is not None:
429 y += x[local_stop:]
430 return y
431
432 return self._apply(func=func, func_args=(start, stop, repl))
433
434 def cat(self, *others, sep: str | bytes | Any = "") -> T_DataArray:
435 """

Callers 2

test_slice_replaceFunction · 0.80

Calls 2

_stringifyMethod · 0.95
_applyMethod · 0.95

Tested by 2

test_slice_replaceFunction · 0.64