HOME


sh-3ll 1.0
DIR:/usr/local/lib64/python3.6/site-packages/pandas/core/__pycache__/
Upload File :
Current File : //usr/local/lib64/python3.6/site-packages/pandas/core/__pycache__/strings.cpython-36.pyc
3

���hɫ�@s~UddlZddlmZddlZddlZddlmZmZmZm	Z	m
Z
mZmZm
Z
ddlZddlZddljjZddljjZddljjZddlmZmZmZddlmZddl m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ddl,m-Z-m.Z.m/Z/m0Z0ddl1m2Z2dd	l3m4Z4dd
l5m6Z6ddl7m8Z8e�r0ddl9m:Z:duZ;e;dvZ<e=�Z>e	e?e?f>e
e?d�dd�Z@e
e?d�dd�ZAdejBeC�fdd�ZDee?gefdeeed�dd �ZEd!ejFejBeC�fd"d#�ZGdwd$d%�ZHd&dejFd&fd'd(�ZIejFfd)d*�ZJejFfd+d,�ZKdyd.d/�ZLd0d1�ZMd&dejFfee
e?efeNeOed2�d3d4�ZPd&dejFfee
e?efeNeOed2�d5d6�ZQd7d8�ZRd9d:�ZSd;d<�ZTdzd=d>�ZUd{d?d@�ZVd|dAdB�ZWd}dCdD�ZXd~dFdG�ZYdHdI�ZZddJdK�Z[d�dMdN�Z\d�dOdP�Z]d�dRdS�Z^d�dTdU�Z_d�dVdW�Z`d�dXdY�Zad�dZd[�Zbd�d]d^�Zcd_d`�Zddadb�Zedcdd�Zfd�dfdg�Zgd�dhdi�Zhd�djdk�Zidddlgd&fdmdn�Zjd!d!ddlgd&fdodp�Zkdqdr�ZlGdsdt�dte6�ZmdS)��N)�wraps)�
TYPE_CHECKING�Any�Callable�Dict�List�Pattern�Type�Union)�	ArrayLike�Dtype�Scalar)�Appender)�
ensure_object�
is_bool_dtype�is_categorical_dtype�is_extension_array_dtype�
is_integer�is_integer_dtype�is_list_like�is_object_dtype�is_re�	is_scalar�is_string_dtype)�ABCDataFrame�
ABCIndexClass�
ABCMultiIndex�	ABCSeries)�isna)�take_1d)�NoNewAttributesMixin)�
extract_array)�StringArray�utf-8�utf8�latin-1�latin1�
iso-8859-1�mbcs�ascii�utf-16�utf-32)�list_of_columns�sepcCsd|dkr$tj|td�}tj|dd�S|gdt|�d}||ddd�<tj|td�}tj|dd�S)a�
    Auxiliary function for :meth:`str.cat`

    Parameters
    ----------
    list_of_columns : list of numpy arrays
        List of arrays to be concatenated with sep;
        these arrays may not contain NaNs!
    sep : string
        The separator string for concatenating the columns.

    Returns
    -------
    nd.array
        The concatenation of list_of_columns with sep.
    �)�dtyper)�axis��N)�np�asarray�object�sum�len)r,r-Zarr_of_colsZ
list_with_sepZarr_with_sep�r8�5/tmp/pip-build-5_djhm0z/pandas/pandas/core/strings.py�cat_core:sr:cCs\yt||�}WnHtk
rVx2|D]*}tj|dd�}|dkr$td|���d�q$WYnX|S)a"
    Auxiliary function for :meth:`str.cat`.

    Same signature as cat_core, but handles TypeErrors in concatenation, which
    happen if the arrays in list_of columns have the wrong dtypes or content.

    Parameters
    ----------
    list_of_columns : list of numpy arrays
        List of arrays to be concatenated with sep;
        these arrays may not contain NaNs!
    sep : string
        The separator string for concatenating the columns.

    Returns
    -------
    nd.array
        The concatenation of list_of_columns with sep.
    T)�skipna�string�emptyzpConcatenation requires list-likes containing only strings (or missing values). Offending values found in column N)r<r=)r:�	TypeError�lib�infer_dtype)r,r-�result�columnr/r8r8r9�cat_safeUs

rCcCsPt|j�r0|dkrtj}t|�}t||||d�S|dkr>tj}t||d||d�S)N)�na_valuer/T)�na_maskrDr/)	rr/�
libmissing�NAr!�_map_stringarrayr3�nan�_map_object)�f�arrZ	na_resultr/r8r8r9�_na_mapys
rMr")�funcrLrDr/�returncCs�ddlm}m}m}t|�}t||�s*t�tj|�}t	|�sDt
|�r�t	|�rR|}n|}t|�}	|	rfd}tj|||j
d�d|tj|�d�}
|	s�d|dd�<||
|�St|�r�t|�r�tj|||j
d�d|d�}
||
�Stj|||j
d��SdS)	a&
    Map a callable over valid elements of a StringArray.

    Parameters
    ----------
    func : Callable[[str], Any]
        Apply to each valid element.
    arr : StringArray
    na_value : Any
        The value to use for missing values. By default, this is
        the original value (NA).
    dtype : Dtype
        The result dtype to use. Specifying this avoids an intermediate
        object-dtype allocation.

    Returns
    -------
    ArrayLike
        An ExtensionArray for integer or string dtypes, otherwise
        an ndarray.

    r)�BooleanArray�IntegerArrayr"r2�uint8F)�convertrDr/N)rSrD)�
pandas.arraysrPrQr"r�
isinstance�AssertionErrorr3r4rrr?�map_infer_mask�viewr/rr)rNrLrDr/rPrQr"�mask�constructorZna_value_is_narAr8r8r9rH�s4

rHFcs t|�stjd|d�St|t�r&|j}t|tj�s@tj|td�}|�rt|�}tj	|�}yt
j|�|jtj
�|�}Wndttfk
r�}zDd}	t|j�dkr�tj|	|jd�r�|���fdd�}
t|
||d�Sd}~XnX�tjk	�rtj||��|jtk�rt
j|�}|St
j|��SdS)Nr)r/zO((takes)|(missing)) (?(2)from \d+ to )?\d+ (?(3)required )positional arguments?r2cs&y�|�Sttfk
r �SXdS)N)r>�AttributeError)�x)rKrDr8r9�g�sz_map_object.<locals>.g)r7r3�ndarrayrUr�_valuesr4r5r�allr?rWrXrRr>r[�args�re�searchrJrI�putmaskr/Zmaybe_convert_objects�	map_infer)rKrLrErDr/rYrSrA�eZp_errr]r8)rKrDr9rJ�s.
 
rJcs(tj||d���fdd�}t||dd�S)av
    Count occurrences of pattern in each string of the Series/Index.

    This function is used to count the number of times a particular regex
    pattern is repeated in each of the string elements of the
    :class:`~pandas.Series`.

    Parameters
    ----------
    pat : str
        Valid regular expression.
    flags : int, default 0, meaning no flags
        Flags for the `re` module. For a complete list, `see here
        <https://docs.python.org/3/howto/regex.html#compilation-flags>`_.
    **kwargs
        For compatibility with other string methods. Not used.

    Returns
    -------
    Series or Index
        Same type as the calling object containing the integer counts.

    See Also
    --------
    re : Standard library module for regular expressions.
    str.count : Standard library version, without regular expression support.

    Notes
    -----
    Some characters need to be escaped when passing in `pat`.
    eg. ``'$'`` has a special meaning in regex and must be escaped when
    finding this literal character.

    Examples
    --------
    >>> s = pd.Series(['A', 'B', 'Aaba', 'Baca', np.nan, 'CABA', 'cat'])
    >>> s.str.count('a')
    0    0.0
    1    0.0
    2    2.0
    3    2.0
    4    NaN
    5    0.0
    6    1.0
    dtype: float64

    Escape ``'$'`` to find the literal dollar sign.

    >>> s = pd.Series(['$', 'B', 'Aab$', '$$ca', 'C$B$', 'cat'])
    >>> s.str.count('\$')
    0    1
    1    0
    2    1
    3    2
    4    2
    5    0
    dtype: int64

    This is also available on Index

    >>> pd.Index(['A', 'A', 'Aaba', 'cat']).str.count('a')
    Int64Index([0, 0, 2, 1], dtype='int64')
    )�flagscst�j|��S)N)r7�findall)r\)�regexr8r9�<lambda>5szstr_count.<locals>.<lambda>�int64)r/)rb�compilerM)rL�patrgrKr8)rir9�	str_count�s@rnTcs��rH|s|tjO}tj�|d���jdkr:tjdtdd��fdd�}nJ|rZ�fdd�}n8�j���fd	d�}td
d�|�}t|||t	j
t�d�St|||t	j
t�d�S)a%

    Test if pattern or regex is contained within a string of a Series or Index.

    Return boolean Series or Index based on whether a given pattern or regex is
    contained within a string of a Series or Index.

    Parameters
    ----------
    pat : str
        Character sequence or regular expression.
    case : bool, default True
        If True, case sensitive.
    flags : int, default 0 (no flags)
        Flags to pass through to the re module, e.g. re.IGNORECASE.
    na : default NaN
        Fill value for missing values.
    regex : bool, default True
        If True, assumes the pat is a regular expression.

        If False, treats the pat as a literal string.

    Returns
    -------
    Series or Index of boolean values
        A Series or Index of boolean values indicating whether the
        given pattern is contained within the string of each element
        of the Series or Index.

    See Also
    --------
    match : Analogous, but stricter, relying on re.match instead of re.search.
    Series.str.startswith : Test if the start of each string element matches a
        pattern.
    Series.str.endswith : Same as startswith, but tests the end of string.

    Examples
    --------
    Returning a Series of booleans using only a literal pattern.

    >>> s1 = pd.Series(['Mouse', 'dog', 'house and parrot', '23', np.NaN])
    >>> s1.str.contains('og', regex=False)
    0    False
    1     True
    2    False
    3    False
    4      NaN
    dtype: object

    Returning an Index of booleans using only a literal pattern.

    >>> ind = pd.Index(['Mouse', 'dog', 'house and parrot', '23.0', np.NaN])
    >>> ind.str.contains('23', regex=False)
    Index([False, False, False, True, nan], dtype='object')

    Specifying case sensitivity using `case`.

    >>> s1.str.contains('oG', case=True, regex=True)
    0    False
    1    False
    2    False
    3    False
    4      NaN
    dtype: object

    Specifying `na` to be `False` instead of `NaN` replaces NaN values
    with `False`. If Series or Index does not contain NaN values
    the resultant dtype will be `bool`, otherwise, an `object` dtype.

    >>> s1.str.contains('og', na=False, regex=True)
    0    False
    1     True
    2    False
    3    False
    4    False
    dtype: bool

    Returning 'house' or 'dog' when either expression occurs in a string.

    >>> s1.str.contains('house|dog', regex=True)
    0    False
    1     True
    2     True
    3    False
    4      NaN
    dtype: object

    Ignoring case sensitivity using `flags` with regex.

    >>> import re
    >>> s1.str.contains('PARROT', flags=re.IGNORECASE, regex=True)
    0    False
    1    False
    2     True
    3    False
    4      NaN
    dtype: object

    Returning any digit using regular expression.

    >>> s1.str.contains('\d', regex=True)
    0    False
    1    False
    2    False
    3     True
    4      NaN
    dtype: object

    Ensure `pat` is a not a literal pattern when `regex` is set to True.
    Note in the following example one might expect only `s2[1]` and `s2[3]` to
    return `True`. However, '.0' as a regex matches any character
    followed by a 0.

    >>> s2 = pd.Series(['40', '40.0', '41', '41.0', '35'])
    >>> s2.str.contains('.0', regex=True)
    0     True
    1     True
    2    False
    3     True
    4    False
    dtype: bool
    )rgrzKThis pattern has match groups. To actually get the groups, use str.extract.�)�
stacklevelcs�j|�dk	S)N)rc)r\)rir8r9rj�szstr_contains.<locals>.<lambda>cs�|kS)Nr8)r\)rmr8r9rj�scs�|kS)Nr8)r\)�	upper_patr8r9rj�scSs|j�S)N)�upper)r\r8r8r9rj�s)r/)rb�
IGNORECASErl�groups�warnings�warn�UserWarningrrrMr3r/�bool)rLrm�caserg�narirKZupperedr8)rmrirqr9�str_contains9s"z

r{cs"�fdd�}t|||tjt�d�S)a�
    Test if the start of each string element matches a pattern.

    Equivalent to :meth:`str.startswith`.

    Parameters
    ----------
    pat : str
        Character sequence. Regular expressions are not accepted.
    na : object, default NaN
        Object shown if element tested is not a string.

    Returns
    -------
    Series or Index of bool
        A Series of booleans indicating whether the given pattern matches
        the start of each string element.

    See Also
    --------
    str.startswith : Python standard library string method.
    Series.str.endswith : Same as startswith, but tests the end of string.
    Series.str.contains : Tests if string element contains a pattern.

    Examples
    --------
    >>> s = pd.Series(['bat', 'Bear', 'cat', np.nan])
    >>> s
    0     bat
    1    Bear
    2     cat
    3     NaN
    dtype: object

    >>> s.str.startswith('b')
    0     True
    1    False
    2    False
    3      NaN
    dtype: object

    Specifying `na` to be `False` instead of `NaN`.

    >>> s.str.startswith('b', na=False)
    0     True
    1    False
    2    False
    3    False
    dtype: bool
    cs
|j��S)N)�
startswith)r\)rmr8r9rjsz str_startswith.<locals>.<lambda>)r/)rMr3r/rx)rLrmrzrKr8)rmr9�str_startswith�s3r}cs"�fdd�}t|||tjt�d�S)aw
    Test if the end of each string element matches a pattern.

    Equivalent to :meth:`str.endswith`.

    Parameters
    ----------
    pat : str
        Character sequence. Regular expressions are not accepted.
    na : object, default NaN
        Object shown if element tested is not a string.

    Returns
    -------
    Series or Index of bool
        A Series of booleans indicating whether the given pattern matches
        the end of each string element.

    See Also
    --------
    str.endswith : Python standard library string method.
    Series.str.startswith : Same as endswith, but tests the start of string.
    Series.str.contains : Tests if string element contains a pattern.

    Examples
    --------
    >>> s = pd.Series(['bat', 'bear', 'caT', np.nan])
    >>> s
    0     bat
    1    bear
    2     caT
    3     NaN
    dtype: object

    >>> s.str.endswith('t')
    0     True
    1    False
    2    False
    3      NaN
    dtype: object

    Specifying `na` to be `False` instead of `NaN`.

    >>> s.str.endswith('t', na=False)
    0     True
    1    False
    2    False
    3    False
    dtype: bool
    cs
|j��S)N)�endswith)r\)rmr8r9rj7szstr_endswith.<locals>.<lambda>)r/)rMr3r/rx)rLrmrzrKr8)rmr9�str_endswiths3rr2c	s�t�t�pt��std��t��}|r�|rD|dk	s:|dkrbtd��n|dkrPd}|dkrb|tjO}|s~t��dks~|s~t��r��dkr��nd�tj	�|d�����fd	d
�}q���fdd
�}n,|r�td��t��r�td
�����fdd
�}t
||td�S)a�
    Replace each occurrence of pattern/regex in the Series/Index.

    Equivalent to :meth:`str.replace` or :func:`re.sub`, depending on the regex value.

    Parameters
    ----------
    pat : str or compiled regex
        String can be a character sequence or regular expression.
    repl : str or callable
        Replacement string or a callable. The callable is passed the regex
        match object and must return a replacement string to be used.
        See :func:`re.sub`.
    n : int, default -1 (all)
        Number of replacements to make from start.
    case : bool, default None
        Determines if replace is case sensitive:

        - If True, case sensitive (the default if `pat` is a string)
        - Set to False for case insensitive
        - Cannot be set if `pat` is a compiled regex.

    flags : int, default 0 (no flags)
        Regex module flags, e.g. re.IGNORECASE. Cannot be set if `pat` is a compiled
        regex.
    regex : bool, default True
        Determines if assumes the passed-in pattern is a regular expression:

        - If True, assumes the passed-in pattern is a regular expression.
        - If False, treats the pattern as a literal string
        - Cannot be set to False if `pat` is a compiled regex or `repl` is
          a callable.

        .. versionadded:: 0.23.0

    Returns
    -------
    Series or Index of object
        A copy of the object with all matching occurrences of `pat` replaced by
        `repl`.

    Raises
    ------
    ValueError
        * if `regex` is False and `repl` is a callable or `pat` is a compiled
          regex
        * if `pat` is a compiled regex and `case` or `flags` is set

    Notes
    -----
    When `pat` is a compiled regex, all flags should be included in the
    compiled regex. Use of `case`, `flags`, or `regex=False` with a compiled
    regex will raise an error.

    Examples
    --------
    When `pat` is a string and `regex` is True (the default), the given `pat`
    is compiled as a regex. When `repl` is a string, it replaces matching
    regex patterns as with :meth:`re.sub`. NaN value(s) in the Series are
    left as is:

    >>> pd.Series(['foo', 'fuz', np.nan]).str.replace('f.', 'ba', regex=True)
    0    bao
    1    baz
    2    NaN
    dtype: object

    When `pat` is a string and `regex` is False, every `pat` is replaced with
    `repl` as with :meth:`str.replace`:

    >>> pd.Series(['f.o', 'fuz', np.nan]).str.replace('f.', 'ba', regex=False)
    0    bao
    1    fuz
    2    NaN
    dtype: object

    When `repl` is a callable, it is called on every `pat` using
    :func:`re.sub`. The callable should expect one positional argument
    (a regex object) and return a string.

    To get the idea:

    >>> pd.Series(['foo', 'fuz', np.nan]).str.replace('f', repr)
    0    <re.Match object; span=(0, 1), match='f'>oo
    1    <re.Match object; span=(0, 1), match='f'>uz
    2                                            NaN
    dtype: object

    Reverse every lowercase alphabetic word:

    >>> repl = lambda m: m.group(0)[::-1]
    >>> pd.Series(['foo 123', 'bar baz', np.nan]).str.replace(r'[a-z]+', repl)
    0    oof 123
    1    rab zab
    2        NaN
    dtype: object

    Using regex groups (extract second group and swap case):

    >>> pat = r"(?P<one>\w+) (?P<two>\w+) (?P<three>\w+)"
    >>> repl = lambda m: m.group('two').swapcase()
    >>> pd.Series(['One Two Three', 'Foo Bar Baz']).str.replace(pat, repl)
    0    tWO
    1    bAR
    dtype: object

    Using a compiled regex with flags

    >>> import re
    >>> regex_pat = re.compile(r'FUZ', flags=re.IGNORECASE)
    >>> pd.Series(['foo', 'fuz', np.nan]).str.replace(regex_pat, 'bar')
    0    foo
    1    bar
    2    NaN
    dtype: object
    z!repl must be a string or callableNrz9case and flags cannot be set when pat is a compiled regexTFr2)rgcs�j�|�d�S)N)�replr<�count)�sub)r\)�compiled�nr�r8r9rj�szstr_replace.<locals>.<lambda>cs|j����S)N)�replace)r\)r�rmr�r8r9rj�szCCannot use a compiled regex as replacement pattern with regex=Falsez2Cannot use a callable replacement when regex=Falsecs|j����S)N)r�)r\)r�rmr�r8r9rj�s)r/)rU�str�callabler>r�
ValueErrorrbrsr7rlrM)	rLrmr�r�ryrgriZis_compiled_rerKr8)r�r�rmr�r9�str_replace;s0v
r�csTt��r"�fdd�}t||td�Sdd�}tj�td��tjtj|��|�}|SdS)a�
    Duplicate each string in the Series or Index.

    Parameters
    ----------
    repeats : int or sequence of int
        Same value for all (int) or different value per (sequence).

    Returns
    -------
    Series or Index of object
        Series or Index of repeated string objects specified by
        input parameter repeats.

    Examples
    --------
    >>> s = pd.Series(['a', 'b', 'c'])
    >>> s
    0    a
    1    b
    2    c
    dtype: object

    Single int repeats string in Series

    >>> s.str.repeat(repeats=2)
    0    aa
    1    bb
    2    cc
    dtype: object

    Sequence of int repeats corresponding string in Series

    >>> s.str.repeat(repeats=[1, 2, 3])
    0      a
    1     bb
    2    ccc
    dtype: object
    cs.ytj|��Stk
r(tj|��SXdS)N)�bytes�__mul__r>r�)r\)�repeatsr8r9�
scalar_repszstr_repeat.<locals>.scalar_rep)r/cSs<|tjkr|Sytj||�Stk
r6tj||�SXdS)N)rFrGr�r�r>r�)r\�rr8r8r9�rep	s
zstr_repeat.<locals>.repN)rrMr�r3r4r5�libopsZ	vec_binop)rLr�r�r�rAr8)r�r9�
str_repeat�s(r�)rLrmryrgrzcs>|s|tjO}tj||d���fdd�}t|||tjt�d�S)a�
    Determine if each string starts with a match of a regular expression.

    Parameters
    ----------
    pat : str
        Character sequence or regular expression.
    case : bool, default True
        If True, case sensitive.
    flags : int, default 0 (no flags)
        Regex module flags, e.g. re.IGNORECASE.
    na : default NaN
        Fill value for missing values.

    Returns
    -------
    Series/array of boolean values

    See Also
    --------
    fullmatch : Stricter matching that requires the entire string to match.
    contains : Analogous, but less strict, relying on re.search instead of
        re.match.
    extract : Extract matched groups.
    )rgcs�j|�dk	S)N)�match)r\)rir8r9rj;szstr_match.<locals>.<lambda>)r/)rbrsrlrMr3r/rx)rLrmryrgrzrKr8)rir9�	str_matchs
 
r�cs>|s|tjO}tj||d���fdd�}t|||tjt�d�S)a�
    Determine if each string entirely matches a regular expression.

    .. versionadded:: 1.1.0

    Parameters
    ----------
    pat : str
        Character sequence or regular expression.
    case : bool, default True
        If True, case sensitive.
    flags : int, default 0 (no flags)
        Regex module flags, e.g. re.IGNORECASE.
    na : default NaN
        Fill value for missing values.

    Returns
    -------
    Series/array of boolean values

    See Also
    --------
    match : Similar, but also returns `True` when only a *prefix* of the string
        matches the regular expression.
    extract : Extract matched groups.
    )rgcs�j|�dk	S)N)�	fullmatch)r\)rir8r9rjfszstr_fullmatch.<locals>.<lambda>)r/)rbrsrlrMr3r/rx)rLrmryrgrzrKr8)rir9�
str_fullmatch@s
!
r�cCs,yt|jj��j�Stk
r&dSXdS)N)�list�
groupindex�keys�pop�
IndexError)�rxr8r8r9�_get_single_group_nameksr�cs2�jdkrtd��tjg�j���fdd�}|S)z/Used in both extract_noexpand and extract_framerz"pattern contains no capture groupscs6t|t�s�S�j|�}|r.dd�|j�D�S�SdS)NcSsg|]}|dkrtjn|�qS)N)r3rI)�.0�itemr8r8r9�
<listcomp>}sz0_groups_or_na_fun.<locals>.f.<locals>.<listcomp>)rUr�rcrt)r\�m)�	empty_rowrir8r9rKxs

z_groups_or_na_fun.<locals>.f)rtr�r3rI)rirKr8)r�rir9�_groups_or_na_funrs

	r�cCs|jjdkrdStSdS)Nr<)r/�namer5)rLr8r8r9�
_result_dtype�sr�c	s�ddlm}tj||d�}t|��|jdkrRtj�fdd�|D�td�}t	|�}n�t
|t�rdtd��d	}t
t|jj�|jj�����fd
d�t|j�D�}|jr�||td�}n(t|�}|�fdd�|D�||j|d
�}||fS)z�
    Find groups in each string in the Series using passed regular
    expression. This function is called from
    str_extract(expand=False), and can return Series, DataFrame, or
    Index.

    r)�	DataFrame)rgr2csg|]}�|�d�qS)rr8)r��val)�groups_or_nar8r9r��sz)_str_extract_noexpand.<locals>.<listcomp>)r/z,only one regex group is supported with IndexNcsg|]}�jd||��qS)r2)�get)r��i)�namesr8r9r��s)�columnsr/csg|]}�|��qSr8r8)r�r�)r�r8r9r��s)r��indexr/)�pandasr�rbrlr�rtr3�arrayr5r�rUrr��dict�zipr��valuesr��ranger=r�r�)	rLrmrgr�rirAr�r�r/r8)r�r�r9�_str_extract_noexpand�s(


r�cs�ddlm}tj||d�}t|��tt|jj�|jj	�����fdd�t
|j�D�}t|�dkrl||t
d�Sy
|j}Wntk
r�d}YnXt|�}|�fdd�|D�|||d	�S)
z�
    For each subject string in the Series, extract groups from the
    first match of regular expression pat. This function is called from
    str_extract(expand=True), and always returns a DataFrame.

    r)r�)rgcsg|]}�jd||��qS)r2)r�)r�r�)r�r8r9r��sz&_str_extract_frame.<locals>.<listcomp>)r�r/Ncsg|]}�|��qSr8r8)r�r�)r�r8r9r��s)r�r�r/)r�r�rbrlr�r�r�r�r�r�r�rtr7r5r�r[r�)rLrmrgr�rir�Zresult_indexr/r8)r�r�r9�_str_extract_frame�s"

r�cCsNt|t�std��|r&t|j||d�St|j||d�\}}|j|||d�SdS)a*	
    Extract capture groups in the regex `pat` as columns in a DataFrame.

    For each subject string in the Series, extract groups from the
    first match of regular expression `pat`.

    Parameters
    ----------
    pat : str
        Regular expression pattern with capturing groups.
    flags : int, default 0 (no flags)
        Flags from the ``re`` module, e.g. ``re.IGNORECASE``, that
        modify regular expression matching for things like case,
        spaces, etc. For more details, see :mod:`re`.
    expand : bool, default True
        If True, return DataFrame with one column per capture group.
        If False, return a Series/Index if there is one capture group
        or DataFrame if there are multiple capture groups.

    Returns
    -------
    DataFrame or Series or Index
        A DataFrame with one row for each subject string, and one
        column for each group. Any capture group names in regular
        expression pat will be used for column names; otherwise
        capture group numbers will be used. The dtype of each result
        column is always object, even when no match is found. If
        ``expand=False`` and pat has only one capture group, then
        return a Series (if subject is a Series) or Index (if subject
        is an Index).

    See Also
    --------
    extractall : Returns all matches (not just the first match).

    Examples
    --------
    A pattern with two groups will return a DataFrame with two columns.
    Non-matches will be NaN.

    >>> s = pd.Series(['a1', 'b2', 'c3'])
    >>> s.str.extract(r'([ab])(\d)')
         0    1
    0    a    1
    1    b    2
    2  NaN  NaN

    A pattern may contain optional groups.

    >>> s.str.extract(r'([ab])?(\d)')
         0  1
    0    a  1
    1    b  2
    2  NaN  3

    Named groups will become column names in the result.

    >>> s.str.extract(r'(?P<letter>[ab])(?P<digit>\d)')
      letter digit
    0      a     1
    1      b     2
    2    NaN   NaN

    A pattern with one group will return a DataFrame with one column
    if expand=True.

    >>> s.str.extract(r'[ab](\d)', expand=True)
         0
    0    1
    1    2
    2  NaN

    A pattern with one group will return a Series if expand=False.

    >>> s.str.extract(r'[ab](\d)', expand=False)
    0      1
    1      2
    2    NaN
    dtype: object
    zexpand must be True or False)rg)r��expandN)rUrxr�r��_origr��_parent�_wrap_result)rLrmrgr�rAr�r8r8r9�str_extract�sQ
r�csHtj||d�}|jdkr td��t|t�r:|j�jdd�}tt	|j
j�|j
j�����fdd�t
|j�D�}g}g}|jjdk}x�|j�D]x\}}	t|	t�r�|s�|f}xZt|j|	��D]H\}
}t|t�r�|f}d	d�|D�}|j|�t||
f�}
|j|
�q�Wq�Wdd
lm}|j||jjdgd�}t|�}|j||||d
�}|S)a	
    Extract capture groups in the regex `pat` as columns in DataFrame.

    For each subject string in the Series, extract groups from all
    matches of regular expression pat. When each subject string in the
    Series has exactly one match, extractall(pat).xs(0, level='match')
    is the same as extract(pat).

    Parameters
    ----------
    pat : str
        Regular expression pattern with capturing groups.
    flags : int, default 0 (no flags)
        A ``re`` module flag, for example ``re.IGNORECASE``. These allow
        to modify regular expression matching for things like case, spaces,
        etc. Multiple flags can be combined with the bitwise OR operator,
        for example ``re.IGNORECASE | re.MULTILINE``.

    Returns
    -------
    DataFrame
        A ``DataFrame`` with one row for each match, and one column for each
        group. Its rows have a ``MultiIndex`` with first levels that come from
        the subject ``Series``. The last level is named 'match' and indexes the
        matches in each item of the ``Series``. Any capture group names in
        regular expression pat will be used for column names; otherwise capture
        group numbers will be used.

    See Also
    --------
    extract : Returns first match only (not all matches).

    Examples
    --------
    A pattern with one group will return a DataFrame with one column.
    Indices with no matches will not appear in the result.

    >>> s = pd.Series(["a1a2", "b1", "c1"], index=["A", "B", "C"])
    >>> s.str.extractall(r"[ab](\d)")
             0
      match
    A 0      1
      1      2
    B 0      1

    Capture group names are used for column names of the result.

    >>> s.str.extractall(r"[ab](?P<digit>\d)")
            digit
      match
    A 0         1
      1         2
    B 0         1

    A pattern with two groups will return a DataFrame with two columns.

    >>> s.str.extractall(r"(?P<letter>[ab])(?P<digit>\d)")
            letter digit
      match
    A 0          a     1
      1          a     2
    B 0          b     1

    Optional groups that do not match are NaN in the result.

    >>> s.str.extractall(r"(?P<letter>[ab])?(?P<digit>\d)")
            letter digit
      match
    A 0          a     1
      1          a     2
    B 0          b     1
    C 0        NaN     1
    )rgrz"pattern contains no capture groupsT)Zdropcsg|]}�jd||��qS)r2)r�)r�r�)r�r8r9r�{sz"str_extractall.<locals>.<listcomp>r2cSsg|]}|dkrtjn|�qS)r.)r3�NaN)r��groupr8r8r9r��s)�
MultiIndexr�)r�)r�r�r/)rbrlrtr�rUrZ	to_seriesZreset_indexr�r�r�r�r�r�r��nlevels�itemsr��	enumeraterh�append�tupler�r��from_tuplesr�r��_constructor_expanddim)rLrmrgrir�Z
match_listZ
index_listZis_miZsubject_key�subjectZmatch_iZmatch_tupleZna_tupleZ
result_keyr�r�r/rAr8)r�r9�str_extractall(s6J




r��|cs�|jd�}y|||}Wn&tk
r@||jt�|}YnXt�}x|jj|�D]}|j|�qVWt|dh�}tj	t
|�t
|�ftjd�}xDt|�D]8\}}|||�t
j|j��fdd��|dd�|f<q�W||fS)a�
    Return DataFrame of dummy/indicator variables for Series.

    Each string in Series is split by sep and returned as a DataFrame
    of dummy/indicator variables.

    Parameters
    ----------
    sep : str, default "|"
        String to split on.

    Returns
    -------
    DataFrame
        Dummy variables corresponding to values of the Series.

    See Also
    --------
    get_dummies : Convert categorical variable into dummy/indicator
        variables.

    Examples
    --------
    >>> pd.Series(['a|b', 'a', 'a|c']).str.get_dummies()
       a  b  c
    0  1  1  0
    1  1  0  0
    2  1  0  1

    >>> pd.Series(['a|b', np.nan, 'a|c']).str.get_dummies()
       a  b  c
    0  1  1  0
    1  0  0  0
    2  1  0  1
    r.)r/cs�|kS)Nr8)r\)rmr8r9rj�sz!str_get_dummies.<locals>.<lambda>N)Zfillnar>�astyper��set�split�update�sortedr3r=r7rkr�r?reZto_numpy)rLr-�tags�tsZdummiesr��tr8)rmr9�str_get_dummies�s$
(r�cCst|j|td�S)a�
    Join lists contained as elements in the Series/Index with passed delimiter.

    If the elements of a Series are lists themselves, join the content of these
    lists using the delimiter passed to the function.
    This function is an equivalent to :meth:`str.join`.

    Parameters
    ----------
    sep : str
        Delimiter to use between list entries.

    Returns
    -------
    Series/Index: object
        The list entries concatenated by intervening occurrences of the
        delimiter.

    Raises
    ------
    AttributeError
        If the supplied Series contains neither strings nor lists.

    See Also
    --------
    str.join : Standard library version of this method.
    Series.str.split : Split strings around given separator/delimiter.

    Notes
    -----
    If any of the list items is not a string object, the result of the join
    will be `NaN`.

    Examples
    --------
    Example with a list that contains non-string elements.

    >>> s = pd.Series([['lion', 'elephant', 'zebra'],
    ...                [1.1, 2.2, 3.3],
    ...                ['cat', np.nan, 'dog'],
    ...                ['cow', 4.5, 'goat'],
    ...                ['duck', ['swan', 'fish'], 'guppy']])
    >>> s
    0        [lion, elephant, zebra]
    1                [1.1, 2.2, 3.3]
    2                [cat, nan, dog]
    3               [cow, 4.5, goat]
    4    [duck, [swan, fish], guppy]
    dtype: object

    Join all lists using a '-'. The lists containing object(s) of types other
    than str will produce a NaN.

    >>> s.str.join('-')
    0    lion-elephant-zebra
    1                    NaN
    2                    NaN
    3                    NaN
    4                    NaN
    dtype: object
    )r/)rM�joinr�)rLr-r8r8r9�str_join�s>r�cCstj||d�}t|j|�S)a8	
    Find all occurrences of pattern or regular expression in the Series/Index.

    Equivalent to applying :func:`re.findall` to all the elements in the
    Series/Index.

    Parameters
    ----------
    pat : str
        Pattern or regular expression.
    flags : int, default 0
        Flags from ``re`` module, e.g. `re.IGNORECASE` (default is 0, which
        means no flags).

    Returns
    -------
    Series/Index of lists of strings
        All non-overlapping matches of pattern or regular expression in each
        string of this Series/Index.

    See Also
    --------
    count : Count occurrences of pattern or regular expression in each string
        of the Series/Index.
    extractall : For each string in the Series, extract groups from all matches
        of regular expression and return a DataFrame with one row for each
        match and one column for each group.
    re.findall : The equivalent ``re`` function to all non-overlapping matches
        of pattern or regular expression in string, as a list of strings.

    Examples
    --------
    >>> s = pd.Series(['Lion', 'Monkey', 'Rabbit'])

    The search for the pattern 'Monkey' returns one match:

    >>> s.str.findall('Monkey')
    0          []
    1    [Monkey]
    2          []
    dtype: object

    On the other hand, the search for the pattern 'MONKEY' doesn't return any
    match:

    >>> s.str.findall('MONKEY')
    0    []
    1    []
    2    []
    dtype: object

    Flags can be added to the pattern or regular expression. For instance,
    to find the pattern 'MONKEY' ignoring the case:

    >>> import re
    >>> s.str.findall('MONKEY', flags=re.IGNORECASE)
    0          []
    1    [Monkey]
    2          []
    dtype: object

    When the pattern matches more than one string in the Series, all matches
    are returned:

    >>> s.str.findall('on')
    0    [on]
    1    [on]
    2      []
    dtype: object

    Regular expressions are supported too. For instance, the search for all the
    strings ending with the word 'on' is shown next:

    >>> s.str.findall('on$')
    0    [on]
    1      []
    2      []
    dtype: object

    If the pattern is found more than once in the same string, then a list of
    multiple strings is returned:

    >>> s.str.findall('b')
    0        []
    1        []
    2    [b, b]
    dtype: object
    )rg)rbrlrMrh)rLrmrgrir8r8r9�str_findallsYr��leftcs�t�t�s"dt��j��}t|��|dkr0d�n|dkr>d�ntd���dkr`���fdd	�}n����fd
d	�}t||tjd�d�S)
a�
    Return indexes in each strings in the Series/Index where the
    substring is fully contained between [start:end]. Return -1 on failure.

    Parameters
    ----------
    sub : str
        Substring being searched.
    start : int
        Left edge index.
    end : int
        Right edge index.
    side : {'left', 'right'}, default 'left'
        Specifies a starting side, equivalent to ``find`` or ``rfind``.

    Returns
    -------
    Series or Index
        Indexes where substring is found.
    zexpected a string object, not r��find�right�rfindzInvalid sideNcst|�����S)N)�getattr)r\)�method�startr�r8r9rj�szstr_find.<locals>.<lambda>cst|������S)N)r�)r\)�endr�r�r�r8r9rj�srk)r/)	rUr��type�__name__r>r�rMr3r/)rLr�r�r��side�msgrKr8)r�r�r�r�r9�str_findns
r�cs�t�t�s"dt��j��}t|��|dkr0d�n|dkr>d�ntd���dkr`���fdd�}n����fd	d�}t||tjd
�d�S)Nzexpected a string object, not r�r�r��rindexzInvalid sidecst|�����S)N)r�)r\)r�r�r�r8r9rj�szstr_index.<locals>.<lambda>cst|������S)N)r�)r\)r�r�r�r�r8r9rj�srk)r/)	rUr�r�r�r>r�rMr3r/)rLr�r�r�r�r�rKr8)r�r�r�r�r9�	str_index�s
r�� cs�t�t�s"dt��j��}t|��t��dkr6td��t��sVdt��j��}t|��|dkrn��fdd�}n8|dkr���fd	d�}n |d
kr���fdd�}ntd��t||td
�S)a=
    Pad strings in the Series/Index up to width.

    Parameters
    ----------
    width : int
        Minimum width of resulting string; additional characters will be filled
        with character defined in `fillchar`.
    side : {'left', 'right', 'both'}, default 'left'
        Side from which to fill resulting string.
    fillchar : str, default ' '
        Additional character for filling, default is whitespace.

    Returns
    -------
    Series or Index of object
        Returns Series or Index with minimum number of char in object.

    See Also
    --------
    Series.str.rjust : Fills the left side of strings with an arbitrary
        character. Equivalent to ``Series.str.pad(side='left')``.
    Series.str.ljust : Fills the right side of strings with an arbitrary
        character. Equivalent to ``Series.str.pad(side='right')``.
    Series.str.center : Fills boths sides of strings with an arbitrary
        character. Equivalent to ``Series.str.pad(side='both')``.
    Series.str.zfill : Pad strings in the Series/Index by prepending '0'
        character. Equivalent to ``Series.str.pad(side='left', fillchar='0')``.

    Examples
    --------
    >>> s = pd.Series(["caribou", "tiger"])
    >>> s
    0    caribou
    1      tiger
    dtype: object

    >>> s.str.pad(width=10)
    0       caribou
    1         tiger
    dtype: object

    >>> s.str.pad(width=10, side='right', fillchar='-')
    0    caribou---
    1    tiger-----
    dtype: object

    >>> s.str.pad(width=10, side='both', fillchar='-')
    0    -caribou--
    1    --tiger---
    dtype: object
    z"fillchar must be a character, not r2z%fillchar must be a character, not strz#width must be of integer type, not r�cs|j���S)N)�rjust)r\)�fillchar�widthr8r9rj�szstr_pad.<locals>.<lambda>r�cs|j���S)N)�ljust)r\)r�r�r8r9rj�s�bothcs|j���S)N)�center)r\)r�r�r8r9rj�szInvalid side)r/)	rUr�r�r�r>r7rr�rM)rLr�r�r�r�rKr8)r�r�r9�str_pad�s 5
r�cs��dkr,�dks�dkrd���fdd�}n\t��dkr\�dksH�dkrLd���fdd�}n,�dksl�d	krpd�tj�����fdd�}t||�}|S)
Nrr2cs|j���S)N)r�)r\)r�rmr8r9rj�szstr_split.<locals>.<lambda>cs|j���S)N)r�)r\)r�rmr8r9rjscs�j|�d�S)N)�maxsplit)r�)r\)r�rir8r9rjs���r�r�)r7rbrlrM)rLrmr�rK�resr8)r�rmrir9�	str_split�s

r�cs0�dks�dkrd���fdd�}t||�}|S)Nrr2cs|j���S)N)�rsplit)r\)r�rmr8r9rjszstr_rsplit.<locals>.<lambda>r�)rM)rLrmr�rKr�r8)r�rmr9�
str_rsplit
s

r�cs&t|||���fdd�}t||td�S)a�
    Slice substrings from each element in the Series or Index.

    Parameters
    ----------
    start : int, optional
        Start position for slice operation.
    stop : int, optional
        Stop position for slice operation.
    step : int, optional
        Step size for slice operation.

    Returns
    -------
    Series or Index of object
        Series or Index from sliced substring from original string object.

    See Also
    --------
    Series.str.slice_replace : Replace a slice with a string.
    Series.str.get : Return element at position.
        Equivalent to `Series.str.slice(start=i, stop=i+1)` with `i`
        being the position.

    Examples
    --------
    >>> s = pd.Series(["koala", "fox", "chameleon"])
    >>> s
    0        koala
    1          fox
    2    chameleon
    dtype: object

    >>> s.str.slice(start=1)
    0        oala
    1          ox
    2    hameleon
    dtype: object

    >>> s.str.slice(start=-1)
    0           a
    1           x
    2           n
    dtype: object

    >>> s.str.slice(stop=2)
    0    ko
    1    fo
    2    ch
    dtype: object

    >>> s.str.slice(step=2)
    0      kaa
    1       fx
    2    caeen
    dtype: object

    >>> s.str.slice(start=0, stop=5, step=3)
    0    kl
    1     f
    2    cm
    dtype: object

    Equivalent behaviour to:

    >>> s.str[0:5:3]
    0    kl
    1     f
    2    cm
    dtype: object
    cs|�S)Nr8)r\)�objr8r9rj\szstr_slice.<locals>.<lambda>)r/)�slicerMr�)rLr��stop�steprKr8)r�r9�	str_slicesHr�cs*�dkrd����fdd�}t||td�S)a
    Replace a positional slice of a string with another value.

    Parameters
    ----------
    start : int, optional
        Left index position to use for the slice. If not specified (None),
        the slice is unbounded on the left, i.e. slice from the start
        of the string.
    stop : int, optional
        Right index position to use for the slice. If not specified (None),
        the slice is unbounded on the right, i.e. slice until the
        end of the string.
    repl : str, optional
        String for replacement. If not specified (None), the sliced region
        is replaced with an empty string.

    Returns
    -------
    Series or Index
        Same type as the original object.

    See Also
    --------
    Series.str.slice : Just slicing without replacement.

    Examples
    --------
    >>> s = pd.Series(['a', 'ab', 'abc', 'abdc', 'abcde'])
    >>> s
    0        a
    1       ab
    2      abc
    3     abdc
    4    abcde
    dtype: object

    Specify just `start`, meaning replace `start` until the end of the
    string with `repl`.

    >>> s.str.slice_replace(1, repl='X')
    0    aX
    1    aX
    2    aX
    3    aX
    4    aX
    dtype: object

    Specify just `stop`, meaning the start of the string to `stop` is replaced
    with `repl`, and the rest of the string is included.

    >>> s.str.slice_replace(stop=2, repl='X')
    0       X
    1       X
    2      Xc
    3     Xdc
    4    Xcde
    dtype: object

    Specify `start` and `stop`, meaning the slice from `start` to `stop` is
    replaced with `repl`. Everything before or after `start` and `stop` is
    included as is.

    >>> s.str.slice_replace(start=1, stop=3, repl='X')
    0      aX
    1      aX
    2      aX
    3     aXc
    4    aXde
    dtype: object
    Nr.csZ|���dkr�}n�}d}�dk	r6||d��7}|�7}�dk	rV|||d�7}|S)Nr.r8)r\Z
local_stop�y)r�r�r�r8r9rK�szstr_slice_replace.<locals>.f)r/)rMr�)rLr�r�r�rKr8)r�r�r�r9�str_slice_replace`sH
r�r�csX|dkr�fdd�}n4|dkr,�fdd�}n|dkrB�fdd�}ntd��t||td	�S)
z�
    Strip whitespace (including newlines) from each string in the
    Series/Index.

    Parameters
    ----------
    to_strip : str or unicode
    side : {'left', 'right', 'both'}, default 'both'

    Returns
    -------
    Series or Index
    r�cs
|j��S)N)�strip)r\)�to_stripr8r9rj�szstr_strip.<locals>.<lambda>r�cs
|j��S)N)�lstrip)r\)r�r8r9rj�sr�cs
|j��S)N)�rstrip)r\)r�r8r9rj�szInvalid side)r/)r�rMr�)rLr�r�rKr8)r�r9�	str_strip�sr�cs*||d<tjf|��t�fdd�|td�S)a�
    Wrap strings in Series/Index at specified line width.

    This method has the same keyword parameters and defaults as
    :class:`textwrap.TextWrapper`.

    Parameters
    ----------
    width : int
        Maximum line width.
    expand_tabs : bool, optional
        If True, tab characters will be expanded to spaces (default: True).
    replace_whitespace : bool, optional
        If True, each whitespace character (as defined by string.whitespace)
        remaining after tab expansion will be replaced by a single space
        (default: True).
    drop_whitespace : bool, optional
        If True, whitespace that, after wrapping, happens to end up at the
        beginning or end of a line is dropped (default: True).
    break_long_words : bool, optional
        If True, then words longer than width will be broken in order to ensure
        that no lines are longer than width. If it is false, long words will
        not be broken, and some lines may be longer than width (default: True).
    break_on_hyphens : bool, optional
        If True, wrapping will occur preferably on whitespace and right after
        hyphens in compound words, as it is customary in English. If false,
        only whitespaces will be considered as potentially good places for line
        breaks, but you need to set break_long_words to false if you want truly
        insecable words (default: True).

    Returns
    -------
    Series or Index

    Notes
    -----
    Internally, this method uses a :class:`textwrap.TextWrapper` instance with
    default settings. To achieve behavior matching R's stringr library str_wrap
    function, use the arguments:

    - expand_tabs = False
    - replace_whitespace = True
    - drop_whitespace = True
    - break_long_words = False
    - break_on_hyphens = False

    Examples
    --------
    >>> s = pd.Series(['line to be wrapped', 'another line to be wrapped'])
    >>> s.str.wrap(12)
    0             line to be\nwrapped
    1    another line\nto be\nwrapped
    dtype: object
    r�csdj�j|��S)N�
)r��wrap)�s)�twr8r9rjszstr_wrap.<locals>.<lambda>)r/)�textwrap�TextWrapperrMr�)rLr��kwargsr8)r�r9�str_wrap�s7rcst�fdd�|td�S)a�
    Map all characters in the string through the given mapping table.

    Equivalent to standard :meth:`str.translate`.

    Parameters
    ----------
    table : dict
        Table is a mapping of Unicode ordinals to Unicode ordinals, strings, or
        None. Unmapped characters are left untouched.
        Characters mapped to None are deleted. :meth:`str.maketrans` is a
        helper function for making translation tables.

    Returns
    -------
    Series or Index
    cs
|j��S)N)�	translate)r\)�tabler8r9rj$szstr_translate.<locals>.<lambda>)r/)rMr�)rLrr8)rr9�
str_translatesrcs�fdd�}t||�S)a�
    Extract element from each component at specified position.

    Extract element from lists, tuples, or strings in each element in the
    Series/Index.

    Parameters
    ----------
    i : int
        Position of element to extract.

    Returns
    -------
    Series or Index

    Examples
    --------
    >>> s = pd.Series(["String",
    ...               (1, 2, 3),
    ...               ["a", "b", "c"],
    ...               123,
    ...               -456,
    ...               {1: "Hello", "2": "World"}])
    >>> s
    0                        String
    1                     (1, 2, 3)
    2                     [a, b, c]
    3                           123
    4                          -456
    5    {1: 'Hello', '2': 'World'}
    dtype: object

    >>> s.str.get(1)
    0        t
    1        2
    2        b
    3      NaN
    4      NaN
    5    Hello
    dtype: object

    >>> s.str.get(-1)
    0      g
    1      3
    2      c
    3    NaN
    4    NaN
    5    None
    dtype: object
    csDt|t�r|j��St|��ko0t|�knr>|�StjS)N)rUr�r�r7r3rI)r\)r�r8r9rK[s


"zstr_get.<locals>.f)rM)rLr�rKr8)r�r9�str_get's4r�strictcs:�tkr��fdd�}ntj�����fdd�}t||�S)a#
    Decode character string in the Series/Index using indicated encoding.

    Equivalent to :meth:`str.decode` in python2 and :meth:`bytes.decode` in
    python3.

    Parameters
    ----------
    encoding : str
    errors : str, optional

    Returns
    -------
    Series or Index
    cs|j���S)N)�decode)r\)�encoding�errorsr8r9rjwszstr_decode.<locals>.<lambda>cs�|��dS)Nrr8)r\)�decoderrr8r9rjzs)�_cpython_optimized_decoders�codecs�
getdecoderrM)rLr
rrKr8)rr
rr9�
str_decodees

rcs:�tkr��fdd�}ntj�����fdd�}t||�S)a
    Encode character string in the Series/Index using indicated encoding.

    Equivalent to :meth:`str.encode`.

    Parameters
    ----------
    encoding : str
    errors : str, optional

    Returns
    -------
    encoded : Series/Index of objects
    cs|j���S)N)�encode)r\)r
rr8r9rj�szstr_encode.<locals>.<lambda>cs�|��dS)Nrr8)r\)�encoderrr8r9rj�s)�_cpython_optimized_encodersr�
getencoderrM)rLr
rrKr8)rr
rr9�
str_encode~s

rcs8|dkrgn|}dddddht|����fdd�}|S)	a�
    Decorator to forbid specific types for a method of StringMethods.

    For calling `.str.{method}` on a Series or Index, it is necessary to first
    initialize the :class:`StringMethods` object, and then call the method.
    However, different methods allow different input types, and so this can not
    be checked during :meth:`StringMethods.__init__`, but must be done on a
    per-method basis. This decorator exists to facilitate this process, and
    make it explicit which (inferred) types are disallowed by the method.

    :meth:`StringMethods.__init__` allows the *union* of types its different
    methods allow (after skipping NaNs; see :meth:`StringMethods._validate`),
    namely: ['string', 'empty', 'bytes', 'mixed', 'mixed-integer'].

    The default string types ['string', 'empty'] are allowed for all methods.
    For the additional types ['bytes', 'mixed', 'mixed-integer'], each method
    then needs to forbid the types it is not intended for.

    Parameters
    ----------
    forbidden : list-of-str or None
        List of forbidden non-string types, may be one or more of
        `['bytes', 'mixed', 'mixed-integer']`.
    name : str, default None
        Name of the method to use in the error message. By default, this is
        None, in which case the name from the method being wrapped will be
        copied. However, for working with further wrappers (like _pat_wrapper
        and _noarg_wrapper), it is necessary to specify the name.

    Returns
    -------
    func : wrapper
        The method to which the decorator is applied, with an added check that
        enforces the inferred type to not be in the list of forbidden types.

    Raises
    ------
    TypeError
        If the inferred type of the underlying data is in `forbidden`.
    Nr<r=r��mixedz
mixed-integercs4�dkr�jn��t�����fdd��}�|_|S)Ncs6|j�kr&d��d|j�d�}t|���|f|�|�S)NzCannot use .str.z  with values of inferred dtype 'z'.)�_inferred_dtyper>)�selfrarr�)�
allowed_typesrN�	func_namer8r9�wrapper�s
zHforbid_nonstring_types.<locals>._forbid_nonstring_types.<locals>.wrapper)r�r)rNr)rr�)rNrr9�_forbid_nonstring_types�s
z7forbid_nonstring_types.<locals>._forbid_nonstring_types)r�)�	forbiddenr�rr8)rr�r9�forbid_nonstring_types�s
*rr�csLt||d����fdd��}|dkr*�jn||_|dk	r@||_ntd��|S)N)r�cst�|jf��}|j|�d�S)N)�returns_string)rMr�r�)rrA)rKrrr8r9r�sz_noarg_wrapper.<locals>.wrapperzProvide docstring)rr��__doc__r�)rKr��	docstring�forbidden_typesrrrr8)rKrrr9�_noarg_wrapper�sr#cs�t||d���fdd��}t||d�d	��fdd�	�}t||d�tjf��fdd�	�}	|r^|	n
|rf|n|}
|dkrx�jn||
_�jr��j|
_|
S)
N)r�cs�|j|�}|j|�d�S)N)r)r�r�)rrmrA)rKrr8r9�wrapper1�sz_pat_wrapper.<locals>.wrapper1rcs&�|j|fd|i|��}|j|�d�S)Nrg)r)r�r�)rrmrgrrA)rKrr8r9�wrapper2�sz_pat_wrapper.<locals>.wrapper2cs �|j||d�}|j|�|d�S)N)rz)r�
fill_value)r�r�)rrmrzrA)rKrr8r9�wrapper3sz_pat_wrapper.<locals>.wrapper3)r)rr3rIr�r )rKrgrzr�r"rrr$r%r'rr8)rKrr9�_pat_wrapper�s	

r(cs�fdd�}|S)z:Copy a docstring from another source function (if present)cs�jr�j|_|S)N)r )�target)�sourcer8r9�do_copyszcopy.<locals>.do_copyr8)r*r+r8)r*r9�copysr,c@s�eZdZUdZdd�Zedd��Zdd�Zdd	�Zd
dde	j
d
fdd
�Zdd�Ze
dddg�d�dd��Zded<eedddd��e
dg�d�dd���Zeeddd d��e
dg�d�d!d"���Zd#ed$<eed$d%d&d'd(��e
dg�d�d*d+���Zeed$d,d-d.d(��e
dg�d�d/d0���Zee�d1d2��Zee�e
dg�d3d4���Zee�e
dg�d
d5e	j
d
fd6d7���Zee�e
dg�d
d5e	j
fd8d9���Zee�e
dg�d
d5e	j
fd:d;���Zee �e
dg�d�d<d=���Z!ee"�e
dg�d>d?���Z#ee$�e
dg�d�d@dA���Z%dBedC<eedCe&dDdEd��e
dg�d�dFdG���Z'eedCe&dHdId��e
dg�d�dJdK���Z(eedCe&ddLd��e
dg�d�dMdN���Z)e
dg�dOdP��Z*ee+�d�dQdR��Z,ee-�e
dg�d�dSdT���Z.ee/�d�dVdW��Z0ee1�e
dg�d�dXdY���Z2dZed[<eed[e&d\d]d^d_��e
dg�d�d`da���Z3eed[e&dbdcddd_��e
dg�d�dedf���Z4eed[e&dgdhdid_��e
dg�d�djdk���Z5ee6�e
dg�dldm���Z7ee8�e
dg�d�dodp���Z9ee:�e
dg�dqdr���Z;e<e=d
dsddt�Z>e<e?d
duddv�Z@e<eAd
dwddv�ZBe<eCd
dxddt�ZDeeE�e
dg�d�dydz���ZFeeG�e
dg�d�d{d|���ZHd}ed~<eed~e&dd~d�d���e
dg�d�d�d����ZIeed~e&d�d�d�d���e
dg�d�d�d����ZJe
dg�d�d���ZKd�ed�<eed�e&dd~d�d�d���e
dg�d�d�d����ZLeed�e&d�d�d�d�d���e
dg�d�d�d����ZMd�ed�<eNeOed�de	jPd��dd��ZOd�ed�<iZQeReSeReSeSffQe&d�d�d�d��eQd�<e&d�d�d�d��eQd�<e&d�d�d�d��eQd�<e&d�d�d�d��eQd�<e&d�d�d�d��eQd�<e&d�d�d�d��eQd�<eNd�d��d�ed�eQd�eSd��ZTeNd�d��d�ed�eQd�eSd��ZUeNd�d��d�ed�eQd�eSd��ZVeNd�d��d�ed�eQd�eSd��ZWeNd�d��d�ed�eQd�eSd��ZXeNd�d��d�ed�eQd�eSd��ZYd�ed�<e&d�d�d��eQd�<e&d�d�d��eQd�<e&d�d�d��eQd�<e&d�d�d��eQd�<e&d�d�d��eQd�<e&d�d�d��eQd�<e&d�d�d��eQd�<e&d�d�d��eQd�<e&d�d�d��eQd�<eNd�d��d�ed�eQd�de	jPeZ�dōZ[eNd�d��d�ed�eQd�de	jPeZ�dōZ\eNd�d��d�ed�eQd�de	jPeZ�dōZ]eNd�d��d�ed�eQd�de	jPeZ�dōZ^eNd�d��d�ed�eQd�de	jPeZ�dōZ_eNd�d��d�ed�eQd�de	jPeZ�dōZ`eNd�d��d�ed�eQd�de	jPeZ�dōZaeNd�d��d�ed�eQd�de	jPeZ�dōZbeNd�d��d�ed�eQd�de	jPeZ�dōZcedd�dτ�ZedS)��
StringMethodsa�
    Vectorized string functions for Series and Index.

    NAs stay NA unless handled otherwise by a particular method.
    Patterned after Python's string methods, with some inspiration from
    R's stringr package.

    Examples
    --------
    >>> s = pd.Series(["A_Str_Series"])
    >>> s
    0    A_Str_Series
    dtype: object

    >>> s.str.split("_")
    0    [A, Str, Series]
    dtype: object

    >>> s.str.replace("_", "")
    0    AStrSeries
    dtype: object
    cCsL|j|�|_t|j�|_|jjdk|_|jr4|jjn||_	||_
|j�dS)Nr<)�	_validaterrr/�_is_categoricalr��
_is_stringr_�
categoriesr�r�Z_freeze)r�datar8r8r9�__init__3szStringMethods.__init__cCs�ddlm}t|t�rtd��dddddg}t|d	|�}t|d
|�}t|j|�rTdSytj|dd�}Wnt	k
r~d
}YnX||kr�td��|S)a0
        Auxiliary function for StringMethods, infers and checks dtype of data.

        This is a "first line of defence" at the creation of the StringMethods-
        object (see _make_accessor), and just checks that the dtype is in the
        *union* of the allowed types over all string methods below; this
        restriction is then refined on a per-method basis using the decorator
        @forbid_nonstring_types (more info in the corresponding docstring).

        This really should exclude all series/index with any non-string values,
        but that isn't practical for performance reasons until we have a str
        dtype (GH 9343 / 13877)

        Parameters
        ----------
        data : The content of the Series

        Returns
        -------
        dtype : inferred dtype of data
        r)�StringDtypez5Can only use .str accessor with Index, not MultiIndexr<r=r�rz
mixed-integerr�r1T)r;Nz.Can only use .str accessor with string values!)
r�r4rUrr[r�r/r?r@r�)r2r4rr�Zinferred_dtyper8r8r9r.>s 

zStringMethods._validatecCs.t|t�r |j|j|j|jd�S|j|�SdS)N)r�r�r�)rUr�r�r�r�r�)r�keyr8r8r9�__getitem__ps
zStringMethods.__getitem__ccsLtjdtdd�d}|j|�}x(|j�j�rF|V|d7}|j|�}q WdS)NzIColumnar iteration over characters will be deprecated in future releases.r1)rprr2)rurv�
FutureWarningr�Znotna�any)rr�r]r8r8r9�__iter__vs
zStringMethods.__iter__TNcs�ddlm}m}m}	|r:|jr:t||	|jdd�jj|d�}t	|d�sRt	|d�rV|S|j
dksdt�|jrt|rtd	}
nd}
|dkr�|j
d
k}nX|dkr�t
|jt�r�dd
���fdd�|D�}|r�tdd�|D����fdd�|D�}t
|t�s�td��|dk�r(|dk�rt|dd�}|dk�r(|jj}t
|jt��r�t|��rD|S|�rzt|�}|j||d�}|jd
k�rv|jd�}|S|||d�SnD|jj}|�r�|jj}
|
||||
d�}n|jj}
|
||||
d�}|SdS)Nr)�Indexr��SeriesF)r,)r&�ndimr/ror<r2TcSst|�r|S|gSdS)N)r)r\r8r8r9�cons_row�sz,StringMethods._wrap_result.<locals>.cons_rowcsg|]}�|��qSr8r8)r�r\)r=r8r9r��sz.StringMethods._wrap_result.<locals>.<listcomp>css|]}t|�VqdS)N)r7)r�r\r8r8r9�	<genexpr>�sz-StringMethods._wrap_result.<locals>.<genexpr>cs2g|]*}t|�dks"|dtjkr*|�n|�qS)r)r7r3rI)r�r\)�max_lenr8r9r��szexpand must be True or Falser�)r�)r�)r�r�r/)r�r�r/)r�r:r�r;r/rr��cat�codes�hasattrr<rVr0rUr�maxrxr�r�r�rr�r�r�Zget_level_valuesr�r�Z_constructor)rrA�	use_codesr�r�r&rr:r�r;r/�outr��consr8)r=r?r9r��sT








zStringMethods._wrap_resultcs ddlm}m}t|jt�r"|jn|jj}t�t�r:�gSt�t�rT|�j|d�gSt�t	�rp�fdd��D�St�t
j�r��jdkr�|�|d���fdd��D�St
�dd	��rt���td
d��D��r�g}x�r�||j�jd��}q�W|Stdd��D���r|�|d�gStd
��dS)a�
        Auxiliary function for :meth:`str.cat`. Turn potentially mixed input
        into a list of Series (elements without an index must match the length
        of the calling Series/Index).

        Parameters
        ----------
        others : Series, DataFrame, np.ndarray, list-like or list-like of
            Objects that are either Series, Index or np.ndarray (1-dim).

        Returns
        -------
        list of Series
            Others transformed into list of Series.
        r)r�r;)r�csg|]}�|�qSr8r8)r�r\)�othersr8r9r�	sz2StringMethods._get_series_list.<locals>.<listcomp>r1csg|]}�|�qSr8r8)r�r\)rGr8r9r�	sF)Z
allow_setscss2|]*}t|ttf�p(t|tj�o(|jdkVqdS)r2N)rUrrr3r^r<)r�r\r8r8r9r>	sz1StringMethods._get_series_list.<locals>.<genexpr>css|]}t|�VqdS)N)r)r�r\r8r8r9r>	sz�others must be Series, Index, DataFrame, np.ndarray or list-like (either containing only strings or containing only objects of type Series/Index/np.ndarray[1-dim])N)r�r�r;rUr�rr�rr_rr3r^r<rr�r`�_get_series_listr�r>)rrGr�r;�idxZlosr8)rGr9rH�s0



zStringMethods._get_series_listr�rz
mixed-integerr�cs�ddlm}m}m}t�t�r&td��|dkr2d}t|jt�rP||j|jd��n|j��dkr�t	���t
��}�dkr�|j�r��|�n�dk	r�|j�r�tj
|����|j��Sy|j���Wn,tk
r�}	ztd�|	�WYdd}	~	XnXt�fdd	��D���rT|�d
|dk�r|ndtt���d
d
d���j�|d�\���fdd��D��dd��g�D�}
tjdd�|
D��}tjj|dd�}�dk�r�|j��r�tjt��td�}
tj|
|tj�|�t�fdd�|
D�|�|
�<nB�dk	�r|j��r�fdd�t||
�D�}
t|
|�}
n
t|
|�}
t|jt��rJ||
t|jjd�}
n2t|jj��r^d}n|jj}||
|�j|jjd�}
|
S)a�
        Concatenate strings in the Series/Index with given separator.

        If `others` is specified, this function concatenates the Series/Index
        and elements of `others` element-wise.
        If `others` is not passed, then all values in the Series/Index are
        concatenated into a single string with a given `sep`.

        Parameters
        ----------
        others : Series, Index, DataFrame, np.ndarray or list-like
            Series, Index, DataFrame, np.ndarray (one- or two-dimensional) and
            other list-likes of strings must have the same length as the
            calling Series/Index, with the exception of indexed objects (i.e.
            Series/Index/DataFrame) if `join` is not None.

            If others is a list-like that contains a combination of Series,
            Index or np.ndarray (1-dim), then all elements will be unpacked and
            must satisfy the above criteria individually.

            If others is None, the method returns the concatenation of all
            strings in the calling Series/Index.
        sep : str, default ''
            The separator between the different elements/columns. By default
            the empty string `''` is used.
        na_rep : str or None, default None
            Representation that is inserted for all missing values:

            - If `na_rep` is None, and `others` is None, missing values in the
              Series/Index are omitted from the result.
            - If `na_rep` is None, and `others` is not None, a row containing a
              missing value in any of the columns (before concatenation) will
              have a missing value in the result.
        join : {'left', 'right', 'outer', 'inner'}, default 'left'
            Determines the join-style between the calling Series/Index and any
            Series/Index/DataFrame in `others` (objects without an index need
            to match the length of the calling Series/Index). To disable
            alignment, use `.values` on any Series/Index/DataFrame in `others`.

            .. versionadded:: 0.23.0
            .. versionchanged:: 1.0.0
                Changed default of `join` from None to `'left'`.

        Returns
        -------
        str, Series or Index
            If `others` is None, `str` is returned, otherwise a `Series/Index`
            (same type as caller) of objects is returned.

        See Also
        --------
        split : Split each string in the Series/Index.
        join : Join lists contained as elements in the Series/Index.

        Examples
        --------
        When not passing `others`, all values are concatenated into a single
        string:

        >>> s = pd.Series(['a', 'b', np.nan, 'd'])
        >>> s.str.cat(sep=' ')
        'a b d'

        By default, NA values in the Series are ignored. Using `na_rep`, they
        can be given a representation:

        >>> s.str.cat(sep=' ', na_rep='?')
        'a b ? d'

        If `others` is specified, corresponding values are concatenated with
        the separator. Result will be a Series of strings.

        >>> s.str.cat(['A', 'B', 'C', 'D'], sep=',')
        0    a,A
        1    b,B
        2    NaN
        3    d,D
        dtype: object

        Missing values will remain missing in the result, but can again be
        represented using `na_rep`

        >>> s.str.cat(['A', 'B', 'C', 'D'], sep=',', na_rep='-')
        0    a,A
        1    b,B
        2    -,C
        3    d,D
        dtype: object

        If `sep` is not specified, the values are concatenated without
        separation.

        >>> s.str.cat(['A', 'B', 'C', 'D'], na_rep='-')
        0    aA
        1    bB
        2    -C
        3    dD
        dtype: object

        Series with different indexes can be aligned before concatenation. The
        `join`-keyword works as in other methods.

        >>> t = pd.Series(['d', 'a', 'e', 'c'], index=[3, 0, 4, 2])
        >>> s.str.cat(t, join='left', na_rep='-')
        0    aa
        1    b-
        2    -c
        3    dd
        dtype: object
        >>>
        >>> s.str.cat(t, join='outer', na_rep='-')
        0    aa
        1    b-
        2    -c
        3    dd
        4    -e
        dtype: object
        >>>
        >>> s.str.cat(t, join='inner', na_rep='-')
        0    aa
        2    -c
        3    dd
        dtype: object
        >>>
        >>> s.str.cat(t, join='right', na_rep='-')
        3    dd
        0    aa
        4    -e
        2    -c
        dtype: object

        For more examples, see :ref:`here <text.concatenate>`.
        r)r:r;�concatz'Did you mean to supply a `sep` keyword?Nr.)r�z�If `others` contains arrays or lists (or other list-likes without an index), these must all be of the same length as the calling Series/Index.c3s|]}�jj|j�VqdS)N)r��equals)r�r\)r2r8r9r>�	sz$StringMethods.cat.<locals>.<genexpr>r2�inner�outerF)r0r�r��sortr,)r�csg|]}�|�qSr8r8)r�r\)rGr8r9r��	sz%StringMethods.cat.<locals>.<listcomp>cSsg|]}t|��qSr8)r)r�r\r8r8r9r��	scSsg|]}t|��qSr8)r)r�r\r8r8r9r��	s)r0)r/csg|]}|��qSr8r8)r�r\)�
not_maskedr8r9r��	scsg|]\}}tj|�|��qSr8)r3�where)r��nm�col)�na_repr8r9r��	s)r/r�)r/r�r�) r�r:r;rJrUr�r�r�rrrr8r3rPr�rHr�r7Zalignr��
logical_or�reducer=r5rdrIrCr�r�rr/r�)rrGr-rSr�r:r;rJrE�errZall_colsZna_masksZ
union_maskrAr/r8)r2rSrOrGr9r@ 	sh



zStringMethods.cata�
    Split strings around given separator/delimiter.

    Splits the string in the Series/Index from the %(side)s,
    at the specified delimiter string. Equivalent to :meth:`str.%(method)s`.

    Parameters
    ----------
    pat : str, optional
        String or regular expression to split on.
        If not specified, split on whitespace.
    n : int, default -1 (all)
        Limit number of splits in output.
        ``None``, 0 and -1 will be interpreted as return all splits.
    expand : bool, default False
        Expand the split strings into separate columns.

        * If ``True``, return DataFrame/MultiIndex expanding dimensionality.
        * If ``False``, return Series/Index, containing lists of strings.

    Returns
    -------
    Series, Index, DataFrame or MultiIndex
        Type matches caller unless ``expand=True`` (see Notes).

    See Also
    --------
    Series.str.split : Split strings around given separator/delimiter.
    Series.str.rsplit : Splits string around given separator/delimiter,
        starting from the right.
    Series.str.join : Join lists contained as elements in the Series/Index
        with passed delimiter.
    str.split : Standard library version for split.
    str.rsplit : Standard library version for rsplit.

    Notes
    -----
    The handling of the `n` keyword depends on the number of found splits:

    - If found splits > `n`,  make first `n` splits only
    - If found splits <= `n`, make all splits
    - If for a certain row the number of found splits < `n`,
      append `None` for padding up to `n` if ``expand=True``

    If using ``expand=True``, Series and Index callers return DataFrame and
    MultiIndex objects, respectively.

    Examples
    --------
    >>> s = pd.Series(
    ...     [
    ...         "this is a regular sentence",
    ...         "https://docs.python.org/3/tutorial/index.html",
    ...         np.nan
    ...     ]
    ... )
    >>> s
    0                       this is a regular sentence
    1    https://docs.python.org/3/tutorial/index.html
    2                                              NaN
    dtype: object

    In the default setting, the string is split by whitespace.

    >>> s.str.split()
    0                   [this, is, a, regular, sentence]
    1    [https://docs.python.org/3/tutorial/index.html]
    2                                                NaN
    dtype: object

    Without the `n` parameter, the outputs of `rsplit` and `split`
    are identical.

    >>> s.str.rsplit()
    0                   [this, is, a, regular, sentence]
    1    [https://docs.python.org/3/tutorial/index.html]
    2                                                NaN
    dtype: object

    The `n` parameter can be used to limit the number of splits on the
    delimiter. The outputs of `split` and `rsplit` are different.

    >>> s.str.split(n=2)
    0                     [this, is, a regular sentence]
    1    [https://docs.python.org/3/tutorial/index.html]
    2                                                NaN
    dtype: object

    >>> s.str.rsplit(n=2)
    0                     [this is a, regular, sentence]
    1    [https://docs.python.org/3/tutorial/index.html]
    2                                                NaN
    dtype: object

    The `pat` parameter can be used to split by other characters.

    >>> s.str.split(pat="/")
    0                         [this is a regular sentence]
    1    [https:, , docs.python.org, 3, tutorial, index...
    2                                                  NaN
    dtype: object

    When using ``expand=True``, the split elements will expand out into
    separate columns. If NaN is present, it is propagated throughout
    the columns during the split.

    >>> s.str.split(expand=True)
                                                   0     1     2        3         4
    0                                           this    is     a  regular  sentence
    1  https://docs.python.org/3/tutorial/index.html  None  None     None      None
    2                                            NaN   NaN   NaN      NaN       NaN

    For slightly more complex use cases like splitting the html document name
    from a url, a combination of parameter settings can be used.

    >>> s.str.rsplit("/", n=1, expand=True)
                                        0           1
    0          this is a regular sentence        None
    1  https://docs.python.org/3/tutorial  index.html
    2                                 NaN         NaN

    Remember to escape special characters when explicitly using regular
    expressions.

    >>> s = pd.Series(["1+1=2"])
    >>> s
    0    1+1=2
    dtype: object
    >>> s.str.split(r"\+|=", expand=True)
         0    1    2
    0    1    1    2
    r�Z	beginningr�)r�r�r2FcCs t|j||d�}|j|||d�S)N)r�)r�r)r�r�r�)rrmr�r�rAr8r8r9r�~
szStringMethods.splitr�r�cCs t|j||d�}|j|||d�S)N)r�)r�r)r�r�r�)rrmr�r�rAr8r8r9r��
szStringMethods.rsplita;
    Split the string at the %(side)s occurrence of `sep`.

    This method splits the string at the %(side)s occurrence of `sep`,
    and returns 3 elements containing the part before the separator,
    the separator itself, and the part after the separator.
    If the separator is not found, return %(return)s.

    Parameters
    ----------
    sep : str, default whitespace
        String to split on.
    expand : bool, default True
        If True, return DataFrame/MultiIndex expanding dimensionality.
        If False, return Series/Index.

    Returns
    -------
    DataFrame/MultiIndex or Series/Index of objects

    See Also
    --------
    %(also)s
    Series.str.split : Split strings around given separators.
    str.partition : Standard library version.

    Examples
    --------

    >>> s = pd.Series(['Linda van der Berg', 'George Pitt-Rivers'])
    >>> s
    0    Linda van der Berg
    1    George Pitt-Rivers
    dtype: object

    >>> s.str.partition()
            0  1             2
    0   Linda     van der Berg
    1  George      Pitt-Rivers

    To partition by the last space instead of the first one:

    >>> s.str.rpartition()
                   0  1            2
    0  Linda van der            Berg
    1         George     Pitt-Rivers

    To partition by something different than a space:

    >>> s.str.partition('-')
                        0  1       2
    0  Linda van der Berg
    1         George Pitt  -  Rivers

    To return a Series containing tuples instead of a DataFrame:

    >>> s.str.partition('-', expand=False)
    0    (Linda van der Berg, , )
    1    (George Pitt, -, Rivers)
    dtype: object

    Also available on indices:

    >>> idx = pd.Index(['X 123', 'Y 999'])
    >>> idx
    Index(['X 123', 'Y 999'], dtype='object')

    Which will create a MultiIndex:

    >>> idx.str.partition()
    MultiIndex([('X', ' ', '123'),
                ('Y', ' ', '999')],
               )

    Or an index with tuples with ``expand=False``:

    >>> idx.str.partition(expand=False)
    Index([('X', ' ', '123'), ('Y', ' ', '999')], dtype='object')
    Z
str_partition�firstzF3 elements containing the string itself, followed by two empty stringsz>rpartition : Split the string at the last occurrence of `sep`.)r�rO�alsor�cs(�fdd�}t||j�}|j|||d�S)Ncs
|j��S)N)�	partition)r\)r-r8r9rj�
sz)StringMethods.partition.<locals>.<lambda>)r�r)rMr�r�)rr-r�rKrAr8)r-r9rY�
szStringMethods.partition�lastzF3 elements containing two empty strings, followed by the string itselfz>partition : Split the string at the first occurrence of `sep`.cs(�fdd�}t||j�}|j|||d�S)Ncs
|j��S)N)�
rpartition)r\)r-r8r9rj�
sz*StringMethods.rpartition.<locals>.<lambda>)r�r)rMr�r�)rr-r�rKrAr8)r-r9r[�
szStringMethods.rpartitioncCst|j|�}|j|�S)N)rr�r�)rr�rAr8r8r9r��
szStringMethods.getcCst|j|�}|j|�S)N)r�r�r�)rr-rAr8r8r9r��
szStringMethods.joinrcCs&t|j|||||d�}|j||dd�S)N)ryrgrzriF)r&r)r{r�r�)rrmryrgrzrirAr8r8r9�containsszStringMethods.containscCs$t|j||||d�}|j||dd�S)N)ryrgrzF)r&r)r�r�r�)rrmryrgrzrAr8r8r9r�
szStringMethods.matchcCs$t|j||||d�}|j||dd�S)N)ryrgrzF)r&r)r�r�r�)rrmryrgrzrAr8r8r9r�szStringMethods.fullmatchc	Cs"t|j||||||d�}|j|�S)N)r�ryrgri)r�r�r�)rrmr�r�ryrgrirAr8r8r9r�szStringMethods.replacecCst|j|�}|j|�S)N)r�r�r�)rr�rAr8r8r9�repeat!szStringMethods.repeatcCst|j|||d�}|j|�S)N)r�r�)r�r�r�)rr�r�r�rAr8r8r9�pad'szStringMethods.pada�
    Pad %(side)s side of strings in the Series/Index.

    Equivalent to :meth:`str.%(method)s`.

    Parameters
    ----------
    width : int
        Minimum width of resulting string; additional characters will be filled
        with ``fillchar``.
    fillchar : str
        Additional character for filling, default is whitespace.

    Returns
    -------
    filled : Series/Index of objects.
    r�zleft and rightr�cCs|j|d|d�S)Nr�)r�r�)r^)rr�r�r8r8r9r�AszStringMethods.centerr�r�cCs|j|d|d�S)Nr�)r�r�)r^)rr�r�r8r8r9r�FszStringMethods.ljustr�cCs|j|d|d�S)Nr�)r�r�)r^)rr�r�r8r8r9r�KszStringMethods.rjustcCst|j|ddd�}|j|�S)a2
        Pad strings in the Series/Index by prepending '0' characters.

        Strings in the Series/Index are padded with '0' characters on the
        left of the string to reach a total string length  `width`. Strings
        in the Series/Index with length greater or equal to `width` are
        unchanged.

        Parameters
        ----------
        width : int
            Minimum length of resulting string; strings with length less
            than `width` be prepended with '0' characters.

        Returns
        -------
        Series/Index of objects.

        See Also
        --------
        Series.str.rjust : Fills the left side of strings with an arbitrary
            character.
        Series.str.ljust : Fills the right side of strings with an arbitrary
            character.
        Series.str.pad : Fills the specified sides of strings with an arbitrary
            character.
        Series.str.center : Fills boths sides of strings with an arbitrary
            character.

        Notes
        -----
        Differs from :meth:`str.zfill` which has special handling
        for '+'/'-' in the string.

        Examples
        --------
        >>> s = pd.Series(['-1', '1', '1000', 10, np.nan])
        >>> s
        0      -1
        1       1
        2    1000
        3      10
        4     NaN
        dtype: object

        Note that ``10`` and ``NaN`` are not strings, therefore they are
        converted to ``NaN``. The minus sign in ``'-1'`` is treated as a
        regular character and the zero is added to the left of it
        (:meth:`str.zfill` would have moved it to the left). ``1000``
        remains unchanged as it is longer than `width`.

        >>> s.str.zfill(3)
        0     0-1
        1     001
        2    1000
        3     NaN
        4     NaN
        dtype: object
        r��0)r�r�)r�r�r�)rr�rAr8r8r9�zfillPs=zStringMethods.zfillcCst|j|||�}|j|�S)N)r�r�r�)rr�r�r�rAr8r8r9r��szStringMethods.slicecCst|j|||�}|j|�S)N)r�r�r�)rr�r�r�rAr8r8r9�
slice_replace�szStringMethods.slice_replacercCst|j||�}|j|dd�S)NF)r)rr�r�)rr
rrAr8r8r9r	�szStringMethods.decodecCst|j||�}|j|dd�S)NF)r)rr�r�)rr
rrAr8r8r9r�szStringMethods.encodeat
    Remove %(position)s characters.

    Strip whitespaces (including newlines) or a set of specified characters
    from each string in the Series/Index from %(side)s.
    Equivalent to :meth:`str.%(method)s`.

    Parameters
    ----------
    to_strip : str or None, default None
        Specifying the set of characters to be removed.
        All combinations of this set of characters will be stripped.
        If None then whitespaces are removed.

    Returns
    -------
    Series or Index of object

    See Also
    --------
    Series.str.strip : Remove leading and trailing characters in Series/Index.
    Series.str.lstrip : Remove leading characters in Series/Index.
    Series.str.rstrip : Remove trailing characters in Series/Index.

    Examples
    --------
    >>> s = pd.Series(['1. Ant.  ', '2. Bee!\n', '3. Cat?\t', np.nan])
    >>> s
    0    1. Ant.
    1    2. Bee!\n
    2    3. Cat?\t
    3          NaN
    dtype: object

    >>> s.str.strip()
    0    1. Ant.
    1    2. Bee!
    2    3. Cat?
    3        NaN
    dtype: object

    >>> s.str.lstrip('123.')
    0    Ant.
    1    Bee!\n
    2    Cat?\t
    3       NaN
    dtype: object

    >>> s.str.rstrip('.!? \n\t')
    0    1. Ant
    1    2. Bee
    2    3. Cat
    3       NaN
    dtype: object

    >>> s.str.strip('123.!? \n\t')
    0    Ant
    1    Bee
    2    Cat
    3    NaN
    dtype: object
    r�zleft and right sidesr�zleading and trailing)r�r��positioncCst|j|dd�}|j|�S)Nr�)r�)r�r�r�)rr�rAr8r8r9r��szStringMethods.stripz	left sider��leadingcCst|j|dd�}|j|�S)Nr�)r�)r�r�r�)rr�rAr8r8r9r��szStringMethods.lstripz
right sider�ZtrailingcCst|j|dd�}|j|�S)Nr�)r�)r�r�r�)rr�rAr8r8r9r��szStringMethods.rstripcKst|j|f|�}|j|�S)N)rr�r�)rr�rrAr8r8r9r�szStringMethods.wrapr�cCs>|jr|jjt�n|j}t||�\}}|j||j|ddd�S)NTF)rDr�r�r)r/r�r�r�r�r�r�)rr-r2rAr�r8r8r9�get_dummiesszStringMethods.get_dummiescCst|j|�}|j|�S)N)rr�r�)rrrAr8r8r9rszStringMethods.translater�)rgr�rr|)rzr�rr~rhcCst||||d�S)N)rgr�)r�)rrmrgr�r8r8r9�extract,szStringMethods.extractcCst|j||d�S)N)rg)r�r�)rrmrgr8r8r9�
extractall1szStringMethods.extractalla
    Return %(side)s indexes in each strings in the Series/Index.

    Each of returned indexes corresponds to the position where the
    substring is fully contained between [start:end]. Return -1 on
    failure. Equivalent to standard :meth:`str.%(method)s`.

    Parameters
    ----------
    sub : str
        Substring being searched.
    start : int
        Left edge index.
    end : int
        Right edge index.

    Returns
    -------
    Series or Index of int.

    See Also
    --------
    %(also)s
    r�Zlowestz/rfind : Return highest indexes in each strings.)r�r�rXcCs"t|j|||dd�}|j|dd�S)Nr�)r�r�r�F)r)r�r�r�)rr�r�r�rAr8r8r9r�Qs
zStringMethods.findZhighestr�z-find : Return lowest indexes in each strings.cCs"t|j|||dd�}|j|dd�S)Nr�)r�r�r�F)r)r�r�r�)rr�r�r�rAr8r8r9r�^s
zStringMethods.rfindcs0ddl���fdd�}t||jtd�}|j|�S)am
        Return the Unicode normal form for the strings in the Series/Index.

        For more information on the forms, see the
        :func:`unicodedata.normalize`.

        Parameters
        ----------
        form : {'NFC', 'NFKC', 'NFD', 'NFKD'}
            Unicode form.

        Returns
        -------
        normalized : Series/Index of objects
        rNcs�j�|�S)N)�	normalize)r\)�form�unicodedatar8r9rj~sz)StringMethods.normalize.<locals>.<lambda>)r/)rirMr�r�r�)rrhrKrAr8)rhrir9rgkszStringMethods.normalizeau
    Return %(side)s indexes in each string in Series/Index.

    Each of the returned indexes corresponds to the position where the
    substring is fully contained between [start:end]. This is the same
    as ``str.%(similar)s`` except instead of returning -1, it raises a
    ValueError when the substring is not found. Equivalent to standard
    ``str.%(method)s``.

    Parameters
    ----------
    sub : str
        Substring being searched.
    start : int
        Left edge index.
    end : int
        Right edge index.

    Returns
    -------
    Series or Index of object

    See Also
    --------
    %(also)s
    r�z0rindex : Return highest indexes in each strings.)r�Zsimilarr�rXcCs"t|j|||dd�}|j|dd�S)Nr�)r�r�r�F)r)r�r�r�)rr�r�r�rAr8r8r9r��szStringMethods.indexr�z.index : Return lowest indexes in each strings.cCs"t|j|||dd�}|j|dd�S)Nr�)r�r�r�F)r)r�r�r�)rr�r�r�rAr8r8r9r��szStringMethods.rindexa�
    Compute the length of each element in the Series/Index.

    The element may be a sequence (such as a string, tuple or list) or a collection
    (such as a dictionary).

    Returns
    -------
    Series or Index of int
        A Series or Index of integer values indicating the length of each
        element in the Series or Index.

    See Also
    --------
    str.len : Python built-in function returning the length of an object.
    Series.size : Returns the length of the Series.

    Examples
    --------
    Returns the length (number of characters) in a string. Returns the
    number of entries for dictionaries, lists or tuples.

    >>> s = pd.Series(['dog',
    ...                 '',
    ...                 5,
    ...                 {'foo' : 'bar'},
    ...                 [2, 3, 5, 7],
    ...                 ('one', 'two', 'three')])
    >>> s
    0                  dog
    1
    2                    5
    3       {'foo': 'bar'}
    4         [2, 3, 5, 7]
    5    (one, two, three)
    dtype: object
    >>> s.str.len()
    0    3.0
    1    0.0
    2    NaN
    3    1.0
    4    4.0
    5    3.0
    dtype: float64
    r7rk)r!r"r/ra�
    Convert strings in the Series/Index to %(type)s.
    %(version)s
    Equivalent to :meth:`str.%(method)s`.

    Returns
    -------
    Series or Index of object

    See Also
    --------
    Series.str.lower : Converts all characters to lowercase.
    Series.str.upper : Converts all characters to uppercase.
    Series.str.title : Converts first character of each word to uppercase and
        remaining to lowercase.
    Series.str.capitalize : Converts first character to uppercase and
        remaining to lowercase.
    Series.str.swapcase : Converts uppercase to lowercase and lowercase to
        uppercase.
    Series.str.casefold: Removes all case distinctions in the string.

    Examples
    --------
    >>> s = pd.Series(['lower', 'CAPITALS', 'this is a sentence', 'SwApCaSe'])
    >>> s
    0                 lower
    1              CAPITALS
    2    this is a sentence
    3              SwApCaSe
    dtype: object

    >>> s.str.lower()
    0                 lower
    1              capitals
    2    this is a sentence
    3              swapcase
    dtype: object

    >>> s.str.upper()
    0                 LOWER
    1              CAPITALS
    2    THIS IS A SENTENCE
    3              SWAPCASE
    dtype: object

    >>> s.str.title()
    0                 Lower
    1              Capitals
    2    This Is A Sentence
    3              Swapcase
    dtype: object

    >>> s.str.capitalize()
    0                 Lower
    1              Capitals
    2    This is a sentence
    3              Swapcase
    dtype: object

    >>> s.str.swapcase()
    0                 LOWER
    1              capitals
    2    THIS IS A SENTENCE
    3              sWaPcAsE
    dtype: object
    ZcasemethodsZ	lowercase�lowerr.)r�r��versionZ	uppercaserrZ	titlecase�titlezbe capitalized�
capitalizezbe swapcased�swapcasez
be casefolded�casefoldz
    .. versionadded:: 0.25.0
cCs|j�S)N)rj)r\r8r8r9rjF
szStringMethods.<lambda>)r�r!r/cCs|j�S)N)rr)r\r8r8r9rjL
scCs|j�S)N)rl)r\r8r8r9rjR
scCs|j�S)N)rm)r\r8r8r9rjX
scCs|j�S)N)rn)r\r8r8r9rj^
scCs|j�S)N)ro)r\r8r8r9rjd
su�

    Check whether all characters in each string are %(type)s.

    This is equivalent to running the Python string method
    :meth:`str.%(method)s` for each element of the Series/Index. If a string
    has zero characters, ``False`` is returned for that check.

    Returns
    -------
    Series or Index of bool
        Series or Index of boolean values with the same length as the original
        Series/Index.

    See Also
    --------
    Series.str.isalpha : Check whether all characters are alphabetic.
    Series.str.isnumeric : Check whether all characters are numeric.
    Series.str.isalnum : Check whether all characters are alphanumeric.
    Series.str.isdigit : Check whether all characters are digits.
    Series.str.isdecimal : Check whether all characters are decimal.
    Series.str.isspace : Check whether all characters are whitespace.
    Series.str.islower : Check whether all characters are lowercase.
    Series.str.isupper : Check whether all characters are uppercase.
    Series.str.istitle : Check whether all characters are titlecase.

    Examples
    --------
    **Checks for Alphabetic and Numeric Characters**

    >>> s1 = pd.Series(['one', 'one1', '1', ''])

    >>> s1.str.isalpha()
    0     True
    1    False
    2    False
    3    False
    dtype: bool

    >>> s1.str.isnumeric()
    0    False
    1    False
    2     True
    3    False
    dtype: bool

    >>> s1.str.isalnum()
    0     True
    1     True
    2     True
    3    False
    dtype: bool

    Note that checks against characters mixed with any additional punctuation
    or whitespace will evaluate to false for an alphanumeric check.

    >>> s2 = pd.Series(['A B', '1.5', '3,000'])
    >>> s2.str.isalnum()
    0    False
    1    False
    2    False
    dtype: bool

    **More Detailed Checks for Numeric Characters**

    There are several different but overlapping sets of numeric characters that
    can be checked for.

    >>> s3 = pd.Series(['23', '³', '⅕', ''])

    The ``s3.str.isdecimal`` method checks for characters used to form numbers
    in base 10.

    >>> s3.str.isdecimal()
    0     True
    1    False
    2    False
    3    False
    dtype: bool

    The ``s.str.isdigit`` method is the same as ``s3.str.isdecimal`` but also
    includes special digits, like superscripted and subscripted digits in
    unicode.

    >>> s3.str.isdigit()
    0     True
    1     True
    2    False
    3    False
    dtype: bool

    The ``s.str.isnumeric`` method is the same as ``s3.str.isdigit`` but also
    includes other characters that can represent quantities such as unicode
    fractions.

    >>> s3.str.isnumeric()
    0     True
    1     True
    2     True
    3    False
    dtype: bool

    **Checks for Whitespace**

    >>> s4 = pd.Series([' ', '\t\r\n ', ''])
    >>> s4.str.isspace()
    0     True
    1     True
    2    False
    dtype: bool

    **Checks for Character Case**

    >>> s5 = pd.Series(['leopard', 'Golden Eagle', 'SNAKE', ''])

    >>> s5.str.islower()
    0     True
    1    False
    2    False
    3    False
    dtype: bool

    >>> s5.str.isupper()
    0    False
    1    False
    2     True
    3    False
    dtype: bool

    The ``s5.str.istitle`` method checks for whether all words are in title
    case (whether only the first letter of each word is capitalized). Words are
    assumed to be as any sequence of non-numeric characters separated by
    whitespace characters.

    >>> s5.str.istitle()
    0    False
    1     True
    2    False
    3    False
    dtype: bool
    Z	ismethodsZalphanumeric�isalnum)r�r�Z
alphabetic�isalpha�digits�isdigit�
whitespace�isspace�islower�isupper�istitle�numeric�	isnumeric�decimal�	isdecimalcCs|j�S)N)rp)r\r8r8r9rjs)r�r!rr/cCs|j�S)N)rq)r\r8r8r9rj
scCs|j�S)N)rs)r\r8r8r9rjscCs|j�S)N)ru)r\r8r8r9rjscCs|j�S)N)rv)r\r8r8r9rjscCs|j�S)N)rw)r\r8r8r9rj&scCs|j�S)N)rx)r\r8r8r9rj-scCs|j�S)N)rz)r\r8r8r9rj4scCs|j�S)N)r|)r\r8r8r9rj;scCs|j|�||�S)N)r.)�clsr2r8r8r9�_make_accessorBs
zStringMethods._make_accessor)NNNr�r�)Nr�Fr�)Nr�F)r�T)r�Tr�)r�NrT)r�r�)r�)r�)r�)NNN)NNN)r)r)N)N)N)r�)rT)r)rN)rN)rN)rN)fr��
__module__�__qualname__r r3�staticmethodr.r6r9r3rIr�rHrr@�_shared_docsrr�r�rYr[r,rr�r�r�r{r\r�r�r�r�r�r�r�r]r�r^r�r�r�r�r`r�r�r�rarr	rrr�r�r�rr�r�rdrrr(rnr�r}r|rr~r�rhr�rer�rfr�r�rgr�r�r#r7r/Z	_doc_argsrr�rjrrrlrmrnrorxrprqrsrurvrwrxrzr|�classmethodr~r8r8r8r9r-s
2]9]T

@C


2

2Fr-)r#r$r%r&r'r(r))r*r+)rr�)r�NrT)r)r)rT)r)r�)r)rNr�)rNr�)r�r�)NN)NN)NNN)NNN)Nr�)r)r)N)nr�	functoolsrrbrZtypingrrrrrrr	r
ruZnumpyr3Zpandas._libs.libZ_libsr?Zpandas._libs.missing�missingrFZpandas._libs.ops�opsr�Zpandas._typingrrr
Zpandas.util._decoratorsrZpandas.core.dtypes.commonrrrrrrrrrrrZpandas.core.dtypes.genericrrrrZpandas.core.dtypes.missingrZpandas.core.algorithmsrZpandas.core.baser Zpandas.core.constructionr!rTr"rr
r�r�r�r:rCr/r5rMrHrIrJrnr{r}rr�r�rx�intr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrr#r(r,r-r8r8r8r9�<module>s�(4
$
D)
E77
C$($&

#

Z
q
7A
]
(

L

	
M
[
>>


E