Return a copy of each string element where all tab characters are replaced by one or more spaces. Calls :meth:`str.expandtabs` element-wise. Return a copy of each string element where all tab characters are replaced by one or more spaces, depending on the current column an
(a, tabsize=8)
| 634 | @set_module("numpy.strings") |
| 635 | @array_function_dispatch(_expandtabs_dispatcher) |
| 636 | def expandtabs(a, tabsize=8): |
| 637 | """ |
| 638 | Return a copy of each string element where all tab characters are |
| 639 | replaced by one or more spaces. |
| 640 | |
| 641 | Calls :meth:`str.expandtabs` element-wise. |
| 642 | |
| 643 | Return a copy of each string element where all tab characters are |
| 644 | replaced by one or more spaces, depending on the current column |
| 645 | and the given `tabsize`. The column number is reset to zero after |
| 646 | each newline occurring in the string. This doesn't understand other |
| 647 | non-printing characters or escape sequences. |
| 648 | |
| 649 | Parameters |
| 650 | ---------- |
| 651 | a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype |
| 652 | Input array |
| 653 | tabsize : int, optional |
| 654 | Replace tabs with `tabsize` number of spaces. If not given defaults |
| 655 | to 8 spaces. |
| 656 | |
| 657 | Returns |
| 658 | ------- |
| 659 | out : ndarray |
| 660 | Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype, |
| 661 | depending on input type |
| 662 | |
| 663 | See Also |
| 664 | -------- |
| 665 | str.expandtabs |
| 666 | |
| 667 | Examples |
| 668 | -------- |
| 669 | >>> import numpy as np |
| 670 | >>> a = np.array(['\t\tHello\tworld']) |
| 671 | >>> np.strings.expandtabs(a, tabsize=4) # doctest: +SKIP |
| 672 | array([' Hello world'], dtype='<U21') # doctest: +SKIP |
| 673 | |
| 674 | """ |
| 675 | a = np.asanyarray(a) |
| 676 | tabsize = np.asanyarray(tabsize) |
| 677 | |
| 678 | if a.dtype.char == "T": |
| 679 | return _expandtabs(a, tabsize) |
| 680 | |
| 681 | buffersizes = _expandtabs_length(a, tabsize) |
| 682 | out_dtype = f"{a.dtype.char}{buffersizes.max()}" |
| 683 | out = np.empty_like(a, shape=buffersizes.shape, dtype=out_dtype) |
| 684 | return _expandtabs(a, tabsize, out=out) |
| 685 | |
| 686 | |
| 687 | def _just_dispatcher(a, width, fillchar=None): |
no test coverage detected
searching dependent graphs…