Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
defchararray.py1415 linesDownload Raw Back to _core
1"""
2This module contains a set of functions for vectorized string
3operations and methods.
4
5.. note::
6   The `chararray` class exists for backwards compatibility with
7   Numarray, it is not recommended for new development. Starting from numpy
8   1.4, if one needs arrays of strings, it is recommended to use arrays of
9   `dtype` `object_`, `bytes_` or `str_`, and use the free functions
10   in the `numpy.char` module for fast vectorized string operations.
11
12Some methods will only be available if the corresponding string method is
13available in your version of Python.
14
15The preferred alias for `defchararray` is `numpy.char`.
16
17"""
18import functools
19
20import numpy as np
21from numpy._core import overrides
22from numpy._core.multiarray import compare_chararrays
23from numpy._core.strings import (
24    _join as join,
25    _rsplit as rsplit,
26    _split as split,
27    _splitlines as splitlines,
28)
29from numpy._utils import set_module
30from numpy.strings import *
31from numpy.strings import (
32    multiply as strings_multiply,
33    partition as strings_partition,
34    rpartition as strings_rpartition,
35)
36
37from .numeric import array as narray, asarray as asnarray, ndarray
38from .numerictypes import bytes_, character, str_
39
40__all__ = [
41    'equal', 'not_equal', 'greater_equal', 'less_equal',
42    'greater', 'less', 'str_len', 'add', 'multiply', 'mod', 'capitalize',
43    'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs',
44    'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace',
45    'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition',
46    'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit',
47    'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase',
48    'title', 'translate', 'upper', 'zfill', 'isnumeric', 'isdecimal',
49    'array', 'asarray', 'compare_chararrays', 'chararray'
50    ]
51
52
53array_function_dispatch = functools.partial(
54    overrides.array_function_dispatch, module='numpy.char')
55
56
57def _binary_op_dispatcher(x1, x2):
58    return (x1, x2)
59
60
61@array_function_dispatch(_binary_op_dispatcher)
62def equal(x1, x2):
63    """
64    Return (x1 == x2) element-wise.
65
66    Unlike `numpy.equal`, this comparison is performed by first
67    stripping whitespace characters from the end of the string.  This
68    behavior is provided for backward-compatibility with numarray.
69
70    Parameters
71    ----------
72    x1, x2 : array_like of str or unicode
73        Input arrays of the same shape.
74
75    Returns
76    -------
77    out : ndarray
78        Output array of bools.
79
80    Examples
81    --------
82    >>> import numpy as np
83    >>> y = "aa "
84    >>> x = "aa"
85    >>> np.char.equal(x, y)
86    array(True)
87
88    See Also
89    --------
90    not_equal, greater_equal, less_equal, greater, less
91    """
92    return compare_chararrays(x1, x2, '==', True)
93
94
95@array_function_dispatch(_binary_op_dispatcher)
96def not_equal(x1, x2):
97    """
98    Return (x1 != x2) element-wise.
99
100    Unlike `numpy.not_equal`, this comparison is performed by first
101    stripping whitespace characters from the end of the string.  This
102    behavior is provided for backward-compatibility with numarray.
103
104    Parameters
105    ----------
106    x1, x2 : array_like of str or unicode
107        Input arrays of the same shape.
108
109    Returns
110    -------
111    out : ndarray
112        Output array of bools.
113
114    See Also
115    --------
116    equal, greater_equal, less_equal, greater, less
117
118    Examples
119    --------
120    >>> import numpy as np
121    >>> x1 = np.array(['a', 'b', 'c'])
122    >>> np.char.not_equal(x1, 'b')
123    array([ True, False,  True])
124
125    """
126    return compare_chararrays(x1, x2, '!=', True)
127
128
129@array_function_dispatch(_binary_op_dispatcher)
130def greater_equal(x1, x2):
131    """
132    Return (x1 >= x2) element-wise.
133
134    Unlike `numpy.greater_equal`, this comparison is performed by
135    first stripping whitespace characters from the end of the string.
136    This behavior is provided for backward-compatibility with
137    numarray.
138
139    Parameters
140    ----------
141    x1, x2 : array_like of str or unicode
142        Input arrays of the same shape.
143
144    Returns
145    -------
146    out : ndarray
147        Output array of bools.
148
149    See Also
150    --------
151    equal, not_equal, less_equal, greater, less
152
153    Examples
154    --------
155    >>> import numpy as np
156    >>> x1 = np.array(['a', 'b', 'c'])
157    >>> np.char.greater_equal(x1, 'b')
158    array([False,  True,  True])
159
160    """
161    return compare_chararrays(x1, x2, '>=', True)
162
163
164@array_function_dispatch(_binary_op_dispatcher)
165def less_equal(x1, x2):
166    """
167    Return (x1 <= x2) element-wise.
168
169    Unlike `numpy.less_equal`, this comparison is performed by first
170    stripping whitespace characters from the end of the string.  This
171    behavior is provided for backward-compatibility with numarray.
172
173    Parameters
174    ----------
175    x1, x2 : array_like of str or unicode
176        Input arrays of the same shape.
177
178    Returns
179    -------
180    out : ndarray
181        Output array of bools.
182
183    See Also
184    --------
185    equal, not_equal, greater_equal, greater, less
186
187    Examples
188    --------
189    >>> import numpy as np
190    >>> x1 = np.array(['a', 'b', 'c'])
191    >>> np.char.less_equal(x1, 'b')
192    array([ True,  True, False])
193
194    """
195    return compare_chararrays(x1, x2, '<=', True)
196
197
198@array_function_dispatch(_binary_op_dispatcher)
199def greater(x1, x2):
200    """
201    Return (x1 > x2) element-wise.
202
203    Unlike `numpy.greater`, this comparison is performed by first
204    stripping whitespace characters from the end of the string.  This
205    behavior is provided for backward-compatibility with numarray.
206
207    Parameters
208    ----------
209    x1, x2 : array_like of str or unicode
210        Input arrays of the same shape.
211
212    Returns
213    -------
214    out : ndarray
215        Output array of bools.
216
217    See Also
218    --------
219    equal, not_equal, greater_equal, less_equal, less
220
221    Examples
222    --------
223    >>> import numpy as np
224    >>> x1 = np.array(['a', 'b', 'c'])
225    >>> np.char.greater(x1, 'b')
226    array([False, False,  True])
227
228    """
229    return compare_chararrays(x1, x2, '>', True)
230
231
232@array_function_dispatch(_binary_op_dispatcher)
233def less(x1, x2):
234    """
235    Return (x1 < x2) element-wise.
236
237    Unlike `numpy.greater`, this comparison is performed by first
238    stripping whitespace characters from the end of the string.  This
239    behavior is provided for backward-compatibility with numarray.
240
241    Parameters
242    ----------
243    x1, x2 : array_like of str or unicode
244        Input arrays of the same shape.
245
246    Returns
247    -------
248    out : ndarray
249        Output array of bools.
250
251    See Also
252    --------
253    equal, not_equal, greater_equal, less_equal, greater
254
255    Examples
256    --------
257    >>> import numpy as np
258    >>> x1 = np.array(['a', 'b', 'c'])
259    >>> np.char.less(x1, 'b')
260    array([True, False, False])
261
262    """
263    return compare_chararrays(x1, x2, '<', True)
264
265
266@set_module("numpy.char")
267def multiply(a, i):
268    """
269    Return (a * i), that is string multiple concatenation,
270    element-wise.
271
272    Values in ``i`` of less than 0 are treated as 0 (which yields an
273    empty string).
274
275    Parameters
276    ----------
277    a : array_like, with `np.bytes_` or `np.str_` dtype
278
279    i : array_like, with any integer dtype
280
281    Returns
282    -------
283    out : ndarray
284        Output array of str or unicode, depending on input types
285
286    Notes
287    -----
288    This is a thin wrapper around np.strings.multiply that raises
289    `ValueError` when ``i`` is not an integer. It only
290    exists for backwards-compatibility.
291
292    Examples
293    --------
294    >>> import numpy as np
295    >>> a = np.array(["a", "b", "c"])
296    >>> np.strings.multiply(a, 3)
297    array(['aaa', 'bbb', 'ccc'], dtype='<U3')
298    >>> i = np.array([1, 2, 3])
299    >>> np.strings.multiply(a, i)
300    array(['a', 'bb', 'ccc'], dtype='<U3')
301    >>> np.strings.multiply(np.array(['a']), i)
302    array(['a', 'aa', 'aaa'], dtype='<U3')
303    >>> a = np.array(['a', 'b', 'c', 'd', 'e', 'f']).reshape((2, 3))
304    >>> np.strings.multiply(a, 3)
305    array([['aaa', 'bbb', 'ccc'],
306           ['ddd', 'eee', 'fff']], dtype='<U3')
307    >>> np.strings.multiply(a, i)
308    array([['a', 'bb', 'ccc'],
309           ['d', 'ee', 'fff']], dtype='<U3')
310
311    """
312    try:
313        return strings_multiply(a, i)
314    except TypeError:
315        raise ValueError("Can only multiply by integers")
316
317
318@set_module("numpy.char")
319def partition(a, sep):
320    """
321    Partition each element in `a` around `sep`.
322
323    Calls :meth:`str.partition` element-wise.
324
325    For each element in `a`, split the element as the first
326    occurrence of `sep`, and return 3 strings containing the part
327    before the separator, the separator itself, and the part after
328    the separator. If the separator is not found, return 3 strings
329    containing the string itself, followed by two empty strings.
330
331    Parameters
332    ----------
333    a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
334        Input array
335    sep : {str, unicode}
336        Separator to split each string element in `a`.
337
338    Returns
339    -------
340    out : ndarray
341        Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
342        depending on input types. The output array will have an extra
343        dimension with 3 elements per input element.
344
345    Examples
346    --------
347    >>> import numpy as np
348    >>> x = np.array(["Numpy is nice!"])
349    >>> np.char.partition(x, " ")
350    array([['Numpy', ' ', 'is nice!']], dtype='<U8')
351
352    See Also
353    --------
354    str.partition
355
356    """
357    return np.stack(strings_partition(a, sep), axis=-1)
358
359
360@set_module("numpy.char")
361def rpartition(a, sep):
362    """
363    Partition (split) each element around the right-most separator.
364
365    Calls :meth:`str.rpartition` element-wise.
366
367    For each element in `a`, split the element as the last
368    occurrence of `sep`, and return 3 strings containing the part
369    before the separator, the separator itself, and the part after
370    the separator. If the separator is not found, return 3 strings
371    containing the string itself, followed by two empty strings.
372
373    Parameters
374    ----------
375    a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
376        Input array
377    sep : str or unicode
378        Right-most separator to split each element in array.
379
380    Returns
381    -------
382    out : ndarray
383        Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
384        depending on input types. The output array will have an extra
385        dimension with 3 elements per input element.
386
387    See Also
388    --------
389    str.rpartition
390
391    Examples
392    --------
393    >>> import numpy as np
394    >>> a = np.array(['aAaAaA', '  aA  ', 'abBABba'])
395    >>> np.char.rpartition(a, 'A')
396    array([['aAaAa', 'A', ''],
397       ['  a', 'A', '  '],
398       ['abB', 'A', 'Bba']], dtype='<U5')
399
400    """
401    return np.stack(strings_rpartition(a, sep), axis=-1)
402
403
404@set_module("numpy.char")
405class chararray(ndarray):
406    """
407    chararray(shape, itemsize=1, unicode=False, buffer=None, offset=0,
408              strides=None, order=None)
409
410    Provides a convenient view on arrays of string and unicode values.
411
412    .. note::
413       The `chararray` class exists for backwards compatibility with
414       Numarray, it is not recommended for new development. Starting from numpy
415       1.4, if one needs arrays of strings, it is recommended to use arrays of
416       `dtype` `~numpy.object_`, `~numpy.bytes_` or `~numpy.str_`, and use
417       the free functions in the `numpy.char` module for fast vectorized
418       string operations.
419
420    Versus a NumPy array of dtype `~numpy.bytes_` or `~numpy.str_`, this
421    class adds the following functionality:
422
423    1) values automatically have whitespace removed from the end
424       when indexed
425
426    2) comparison operators automatically remove whitespace from the
427       end when comparing values
428
429    3) vectorized string operations are provided as methods
430       (e.g. `.endswith`) and infix operators (e.g. ``"+", "*", "%"``)
431
432    chararrays should be created using `numpy.char.array` or
433    `numpy.char.asarray`, rather than this constructor directly.
434
435    This constructor creates the array, using `buffer` (with `offset`
436    and `strides`) if it is not ``None``. If `buffer` is ``None``, then
437    constructs a new array with `strides` in "C order", unless both
438    ``len(shape) >= 2`` and ``order='F'``, in which case `strides`
439    is in "Fortran order".
440
441    Methods
442    -------
443    astype
444    argsort
445    copy
446    count
447    decode
448    dump
449    dumps
450    encode
451    endswith
452    expandtabs
453    fill
454    find
455    flatten
456    getfield
457    index
458    isalnum
459    isalpha
460    isdecimal
461    isdigit
462    islower
463    isnumeric
464    isspace
465    istitle
466    isupper
467    item
468    join
469    ljust
470    lower
471    lstrip
472    nonzero
473    put
474    ravel
475    repeat
476    replace
477    reshape
478    resize
479    rfind
480    rindex
481    rjust
482    rsplit
483    rstrip
484    searchsorted
485    setfield
486    setflags
487    sort
488    split
489    splitlines
490    squeeze
491    startswith
492    strip
493    swapaxes
494    swapcase
495    take
496    title
497    tofile
498    tolist
499    translate
500    transpose
501    upper
502    view
503    zfill
504
505    Parameters
506    ----------
507    shape : tuple
508        Shape of the array.
509    itemsize : int, optional
510        Length of each array element, in number of characters. Default is 1.
511    unicode : bool, optional
512        Are the array elements of type unicode (True) or string (False).
513        Default is False.
514    buffer : object exposing the buffer interface or str, optional
515        Memory address of the start of the array data.  Default is None,
516        in which case a new array is created.
517    offset : int, optional
518        Fixed stride displacement from the beginning of an axis?
519        Default is 0. Needs to be >=0.
520    strides : array_like of ints, optional
521        Strides for the array (see `~numpy.ndarray.strides` for
522        full description). Default is None.
523    order : {'C', 'F'}, optional
524        The order in which the array data is stored in memory: 'C' ->
525        "row major" order (the default), 'F' -> "column major"
526        (Fortran) order.
527
528    Examples
529    --------
530    >>> import numpy as np
531    >>> charar = np.char.chararray((3, 3))
532    >>> charar[:] = 'a'
533    >>> charar
534    chararray([[b'a', b'a', b'a'],
535               [b'a', b'a', b'a'],
536               [b'a', b'a', b'a']], dtype='|S1')
537
538    >>> charar = np.char.chararray(charar.shape, itemsize=5)
539    >>> charar[:] = 'abc'
540    >>> charar
541    chararray([[b'abc', b'abc', b'abc'],
542               [b'abc', b'abc', b'abc'],
543               [b'abc', b'abc', b'abc']], dtype='|S5')
544
545    """
546    def __new__(subtype, shape, itemsize=1, unicode=False, buffer=None,
547                offset=0, strides=None, order='C'):
548        if unicode:
549            dtype = str_
550        else:
551            dtype = bytes_
552
553        # force itemsize to be a Python int, since using NumPy integer
554        # types results in itemsize.itemsize being used as the size of
555        # strings in the new array.
556        itemsize = int(itemsize)
557
558        if isinstance(buffer, str):
559            # unicode objects do not have the buffer interface
560            filler = buffer
561            buffer = None
562        else:
563            filler = None
564
565        if buffer is None:
566            self = ndarray.__new__(subtype, shape, (dtype, itemsize),
567                                   order=order)
568        else:
569            self = ndarray.__new__(subtype, shape, (dtype, itemsize),
570                                   buffer=buffer,
571                                   offset=offset, strides=strides,
572                                   order=order)
573        if filler is not None:
574            self[...] = filler
575
576        return self
577
578    def __array_wrap__(self, arr, context=None, return_scalar=False):
579        # When calling a ufunc (and some other functions), we return a
580        # chararray if the ufunc output is a string-like array,
581        # or an ndarray otherwise
582        if arr.dtype.char in "SUbc":
583            return arr.view(type(self))
584        return arr
585
586    def __array_finalize__(self, obj):
587        # The b is a special case because it is used for reconstructing.
588        if self.dtype.char not in 'VSUbc':
589            raise ValueError("Can only create a chararray from string data.")
590
591    def __getitem__(self, obj):
592        val = ndarray.__getitem__(self, obj)
593        if isinstance(val, character):
594            return val.rstrip()
595        return val
596
597    # IMPLEMENTATION NOTE: Most of the methods of this class are
598    # direct delegations to the free functions in this module.
599    # However, those that return an array of strings should instead
600    # return a chararray, so some extra wrapping is required.
601
602    def __eq__(self, other):
603        """
604        Return (self == other) element-wise.
605
606        See Also
607        --------
608        equal
609        """
610        return equal(self, other)
611
612    def __ne__(self, other):
613        """
614        Return (self != other) element-wise.
615
616        See Also
617        --------
618        not_equal
619        """
620        return not_equal(self, other)
621
622    def __ge__(self, other):
623        """
624        Return (self >= other) element-wise.
625
626        See Also
627        --------
628        greater_equal
629        """
630        return greater_equal(self, other)
631
632    def __le__(self, other):
633        """
634        Return (self <= other) element-wise.
635
636        See Also
637        --------
638        less_equal
639        """
640        return less_equal(self, other)
641
642    def __gt__(self, other):
643        """
644        Return (self > other) element-wise.
645
646        See Also
647        --------
648        greater
649        """
650        return greater(self, other)
651
652    def __lt__(self, other):
653        """
654        Return (self < other) element-wise.
655
656        See Also
657        --------
658        less
659        """
660        return less(self, other)
661
662    def __add__(self, other):
663        """
664        Return (self + other), that is string concatenation,
665        element-wise for a pair of array_likes of str or unicode.
666
667        See Also
668        --------
669        add
670        """
671        return add(self, other)
672
673    def __radd__(self, other):
674        """
675        Return (other + self), that is string concatenation,
676        element-wise for a pair of array_likes of `bytes_` or `str_`.
677
678        See Also
679        --------
680        add
681        """
682        return add(other, self)
683
684    def __mul__(self, i):
685        """
686        Return (self * i), that is string multiple concatenation,
687        element-wise.
688
689        See Also
690        --------
691        multiply
692        """
693        return asarray(multiply(self, i))
694
695    def __rmul__(self, i):
696        """
697        Return (self * i), that is string multiple concatenation,
698        element-wise.
699
700        See Also
701        --------
702        multiply
703        """
704        return asarray(multiply(self, i))
705
706    def __mod__(self, i):
707        """
708        Return (self % i), that is pre-Python 2.6 string formatting
709        (interpolation), element-wise for a pair of array_likes of `bytes_`
710        or `str_`.
711
712        See Also
713        --------
714        mod
715        """
716        return asarray(mod(self, i))
717
718    def __rmod__(self, other):
719        return NotImplemented
720
721    def argsort(self, axis=-1, kind=None, order=None, *, stable=None):
722        """
723        Return the indices that sort the array lexicographically.
724
725        For full documentation see `numpy.argsort`, for which this method is
726        in fact merely a "thin wrapper."
727
728        Examples
729        --------
730        >>> c = np.array(['a1b c', '1b ca', 'b ca1', 'Ca1b'], 'S5')
731        >>> c = c.view(np.char.chararray); c
732        chararray(['a1b c', '1b ca', 'b ca1', 'Ca1b'],
733              dtype='|S5')
734        >>> c[c.argsort()]
735        chararray(['1b ca', 'Ca1b', 'a1b c', 'b ca1'],
736              dtype='|S5')
737
738        """
739        return self.__array__().argsort(axis, kind, order, stable=stable)
740    argsort.__doc__ = ndarray.argsort.__doc__
741
742    def capitalize(self):
743        """
744        Return a copy of `self` with only the first character of each element
745        capitalized.
746
747        See Also
748        --------
749        char.capitalize
750
751        """
752        return asarray(capitalize(self))
753
754    def center(self, width, fillchar=' '):
755        """
756        Return a copy of `self` with its elements centered in a
757        string of length `width`.
758
759        See Also
760        --------
761        center
762        """
763        return asarray(center(self, width, fillchar))
764
765    def count(self, sub, start=0, end=None):
766        """
767        Returns an array with the number of non-overlapping occurrences of
768        substring `sub` in the range [`start`, `end`].
769
770        See Also
771        --------
772        char.count
773
774        """
775        return count(self, sub, start, end)
776
777    def decode(self, encoding=None, errors=None):
778        """
779        Calls ``bytes.decode`` element-wise.
780
781        See Also
782        --------
783        char.decode
784
785        """
786        return decode(self, encoding, errors)
787
788    def encode(self, encoding=None, errors=None):
789        """
790        Calls :meth:`str.encode` element-wise.
791
792        See Also
793        --------
794        char.encode
795
796        """
797        return encode(self, encoding, errors)
798
799    def endswith(self, suffix, start=0, end=None):
800        """
801        Returns a boolean array which is `True` where the string element
802        in `self` ends with `suffix`, otherwise `False`.
803
804        See Also
805        --------
806        char.endswith
807
808        """
809        return endswith(self, suffix, start, end)
810
811    def expandtabs(self, tabsize=8):
812        """
813        Return a copy of each string element where all tab characters are
814        replaced by one or more spaces.
815
816        See Also
817        --------
818        char.expandtabs
819
820        """
821        return asarray(expandtabs(self, tabsize))
822
823    def find(self, sub, start=0, end=None):
824        """
825        For each element, return the lowest index in the string where
826        substring `sub` is found.
827
828        See Also
829        --------
830        char.find
831
832        """
833        return find(self, sub, start, end)
834
835    def index(self, sub, start=0, end=None):
836        """
837        Like `find`, but raises :exc:`ValueError` when the substring is not
838        found.
839
840        See Also
841        --------
842        char.index
843
844        """
845        return index(self, sub, start, end)
846
847    def isalnum(self):
848        """
849        Returns true for each element if all characters in the string
850        are alphanumeric and there is at least one character, false
851        otherwise.
852
853        See Also
854        --------
855        char.isalnum
856
857        """
858        return isalnum(self)
859
860    def isalpha(self):
861        """
862        Returns true for each element if all characters in the string
863        are alphabetic and there is at least one character, false
864        otherwise.
865
866        See Also
867        --------
868        char.isalpha
869
870        """
871        return isalpha(self)
872
873    def isdigit(self):
874        """
875        Returns true for each element if all characters in the string are
876        digits and there is at least one character, false otherwise.
877
878        See Also
879        --------
880        char.isdigit
881
882        """
883        return isdigit(self)
884
885    def islower(self):
886        """
887        Returns true for each element if all cased characters in the
888        string are lowercase and there is at least one cased character,
889        false otherwise.
890
891        See Also
892        --------
893        char.islower
894
895        """
896        return islower(self)
897
898    def isspace(self):
899        """
900        Returns true for each element if there are only whitespace
901        characters in the string and there is at least one character,
902        false otherwise.
903
904        See Also
905        --------
906        char.isspace
907
908        """
909        return isspace(self)
910
911    def istitle(self):
912        """
913        Returns true for each element if the element is a titlecased
914        string and there is at least one character, false otherwise.
915
916        See Also
917        --------
918        char.istitle
919
920        """
921        return istitle(self)
922
923    def isupper(self):
924        """
925        Returns true for each element if all cased characters in the
926        string are uppercase and there is at least one character, false
927        otherwise.
928
929        See Also
930        --------
931        char.isupper
932
933        """
934        return isupper(self)
935
936    def join(self, seq):
937        """
938        Return a string which is the concatenation of the strings in the
939        sequence `seq`.
940
941        See Also
942        --------
943        char.join
944
945        """
946        return join(self, seq)
947
948    def ljust(self, width, fillchar=' '):
949        """
950        Return an array with the elements of `self` left-justified in a
951        string of length `width`.
952
953        See Also
954        --------
955        char.ljust
956
957        """
958        return asarray(ljust(self, width, fillchar))
959
960    def lower(self):
961        """
962        Return an array with the elements of `self` converted to
963        lowercase.
964
965        See Also
966        --------
967        char.lower
968
969        """
970        return asarray(lower(self))
971
972    def lstrip(self, chars=None):
973        """
974        For each element in `self`, return a copy with the leading characters
975        removed.
976
977        See Also
978        --------
979        char.lstrip
980
981        """
982        return lstrip(self, chars)
983
984    def partition(self, sep):
985        """
986        Partition each element in `self` around `sep`.
987
988        See Also
989        --------
990        partition
991        """
992        return asarray(partition(self, sep))
993
994    def replace(self, old, new, count=None):
995        """
996        For each element in `self`, return a copy of the string with all
997        occurrences of substring `old` replaced by `new`.
998
999        See Also
1000        --------
1001        char.replace
1002
1003        """
1004        return replace(self, old, new, count if count is not None else -1)
1005
1006    def rfind(self, sub, start=0, end=None):
1007        """
1008        For each element in `self`, return the highest index in the string
1009        where substring `sub` is found, such that `sub` is contained
1010        within [`start`, `end`].
1011
1012        See Also
1013        --------
1014        char.rfind
1015
1016        """
1017        return rfind(self, sub, start, end)
1018
1019    def rindex(self, sub, start=0, end=None):
1020        """
1021        Like `rfind`, but raises :exc:`ValueError` when the substring `sub` is
1022        not found.
1023
1024        See Also
1025        --------
1026        char.rindex
1027
1028        """
1029        return rindex(self, sub, start, end)
1030
1031    def rjust(self, width, fillchar=' '):
1032        """
1033        Return an array with the elements of `self`
1034        right-justified in a string of length `width`.
1035
1036        See Also
1037        --------
1038        char.rjust
1039
1040        """
1041        return asarray(rjust(self, width, fillchar))
1042
1043    def rpartition(self, sep):
1044        """
1045        Partition each element in `self` around `sep`.
1046
1047        See Also
1048        --------
1049        rpartition
1050        """
1051        return asarray(rpartition(self, sep))
1052
1053    def rsplit(self, sep=None, maxsplit=None):
1054        """
1055        For each element in `self`, return a list of the words in
1056        the string, using `sep` as the delimiter string.
1057
1058        See Also
1059        --------
1060        char.rsplit
1061
1062        """
1063        return rsplit(self, sep, maxsplit)
1064
1065    def rstrip(self, chars=None):
1066        """
1067        For each element in `self`, return a copy with the trailing
1068        characters removed.
1069
1070        See Also
1071        --------
1072        char.rstrip
1073
1074        """
1075        return rstrip(self, chars)
1076
1077    def split(self, sep=None, maxsplit=None):
1078        """
1079        For each element in `self`, return a list of the words in the
1080        string, using `sep` as the delimiter string.
1081
1082        See Also
1083        --------
1084        char.split
1085
1086        """
1087        return split(self, sep, maxsplit)
1088
1089    def splitlines(self, keepends=None):
1090        """
1091        For each element in `self`, return a list of the lines in the
1092        element, breaking at line boundaries.
1093
1094        See Also
1095        --------
1096        char.splitlines
1097
1098        """
1099        return splitlines(self, keepends)
1100
1101    def startswith(self, prefix, start=0, end=None):
1102        """
1103        Returns a boolean array which is `True` where the string element
1104        in `self` starts with `prefix`, otherwise `False`.
1105
1106        See Also
1107        --------
1108        char.startswith
1109
1110        """
1111        return startswith(self, prefix, start, end)
1112
1113    def strip(self, chars=None):
1114        """
1115        For each element in `self`, return a copy with the leading and
1116        trailing characters removed.
1117
1118        See Also
1119        --------
1120        char.strip
1121
1122        """
1123        return strip(self, chars)
1124
1125    def swapcase(self):
1126        """
1127        For each element in `self`, return a copy of the string with
1128        uppercase characters converted to lowercase and vice versa.
1129
1130        See Also
1131        --------
1132        char.swapcase
1133
1134        """
1135        return asarray(swapcase(self))
1136
1137    def title(self):
1138        """
1139        For each element in `self`, return a titlecased version of the
1140        string: words start with uppercase characters, all remaining cased
1141        characters are lowercase.
1142
1143        See Also
1144        --------
1145        char.title
1146
1147        """
1148        return asarray(title(self))
1149
1150    def translate(self, table, deletechars=None):
1151        """
1152        For each element in `self`, return a copy of the string where
1153        all characters occurring in the optional argument
1154        `deletechars` are removed, and the remaining characters have
1155        been mapped through the given translation table.
1156
1157        See Also
1158        --------
1159        char.translate
1160
1161        """
1162        return asarray(translate(self, table, deletechars))
1163
1164    def upper(self):
1165        """
1166        Return an array with the elements of `self` converted to
1167        uppercase.
1168
1169        See Also
1170        --------
1171        char.upper
1172
1173        """
1174        return asarray(upper(self))
1175
1176    def zfill(self, width):
1177        """
1178        Return the numeric string left-filled with zeros in a string of
1179        length `width`.
1180
1181        See Also
1182        --------
1183        char.zfill
1184
1185        """
1186        return asarray(zfill(self, width))
1187
1188    def isnumeric(self):
1189        """
1190        For each element in `self`, return True if there are only
1191        numeric characters in the element.
1192
1193        See Also
1194        --------
1195        char.isnumeric
1196
1197        """
1198        return isnumeric(self)
1199
1200    def isdecimal(self):

Showing the first 1,200 of 1415 lines. Download the file for the rest.

codekingpro/portable-devtools · Team Ai