3
pd
             ,   @   s  d dl m Z mZ d dlZd dlZd dlmZ d dlZd dlm	Z	 d dl
Zd dl
mZmZmZmZmZmZmZ d dljZd dljjZdd Zdf d	d
ifdeedfd
ddfddpi fddqi fddri fddsi fddti fddui fddvddifddwddifddxddifddyddifddzi fdd{i fdd|i fd d}i fd!d~i fd#di fd$di fd%di fd&di fd'di fd)di fd*dddifd*dddifd,di fd.di fd0di fd1di fd2di fd3dddifd3dddifd4di fd6di fd7dddifd7dddifd8di fd8dddifd8dddifd9d:d;ifi fd<di fd>di fg*eed?dd@dAdBdCdDdEdFdGdHdIdJdKdLd*d3dMdNd4d6d7dOdPdQdRdSgf gd; i gd;  Zee \ZZZdTdU eej D e!e Z"e" st#ej$eedVdWdX Z%dYdej&dZgfd[d\ej&d]gfd^ej&ej&ej&gfd^g fd_dej&d=gfgZ'ee' \ZZej$e'edVd`da Z(G dbdc dcZ)ddde Z*ej+j,dfdd=dgfdd dgfd!d dgfd1d=dgfgdgdh Z-ej+j,dfdDdddgfdBdddgfdAdddgfdDdddgfgdidj Z.dkdl Z/ej+j,dme0eej1ejejgdndo Z2dS )    )datetime	timedeltaN)randint)lib)	DataFrameIndex
MultiIndexSeriesconcatisnanotnac             C   s(   t | trtj| | ntj| | d S )N)
isinstancer	   tmassert_series_equalassert_index_equal)leftright r   ;/tmp/pip-build-7vycvbft/pandas/pandas/tests/test_strings.pyassert_series_or_index_equal   s    
r   catsep,Zzyxr   )r   joincenter
   containsacountdecodeUTF-8encodeendswithnaTFextract([a-z]*)expand
extractallfindfindallgetindex r   ljustmatch	fullmatch	normalizeNFCpad	partition repeat   replacezrfindrindexrjust
rpartitionslice   slice_replacesplit
startswith	translatea   d   wrap   zfill
capitalizeget_dummiesisalnumisalpha	isdecimalisdigitislower	isnumericisspaceistitleisupperlenlowerlstriprsplitrstripstripswapcasetitleuppercasefoldc             C   s   h | ]}|j d s|qS )_)rA   ).0fr   r   r   	<setcomp>m   s   r`   )paramsidsc             C   s   | j S )a  
    Fixture for all public methods of `StringMethods`

    This fixture returns a tuple of the method name and sample arguments
    necessary to call the method.

    Returns
    -------
    method_name : str
        The name of the method in `StringMethods`
    args : tuple
        Sample values for the positional arguments
    kwargs : dict
        Sample values for the keyword arguments

    Examples
    --------
    >>> def test_something(any_string_method):
    ...     s = pd.Series(['a', 'b', np.nan, 'd'])
    ...
    ...     method_name, args, kwargs = any_string_method
    ...     method = getattr(s.str, method_name)
    ...     # will not raise
    ...     method(*args, **kwargs)
    )param)requestr   r   r   any_string_methods   s    re   stringcbytes   a   cemptyzmixed-integerc             C   s    | j \}}tj|td}||fS )aA  
    Fixture for all (inferred) dtypes allowed in StringMethods.__init__

    The covered (inferred) types are:
    * 'string'
    * 'empty'
    * 'bytes'
    * 'mixed'
    * 'mixed-integer'

    Returns
    -------
    inferred_dtype : str
        The string for the inferred dtype from _libs.lib.infer_dtype
    values : np.ndarray
        An array of object dtype that will be inferred to have
        `inferred_dtype`

    Examples
    --------
    >>> import pandas._libs.lib as lib
    >>>
    >>> def test_something(any_allowed_skipna_inferred_dtype):
    ...     inferred_dtype, values = any_allowed_skipna_inferred_dtype
    ...     # will pass
    ...     assert lib.infer_dtype(values, skipna=True) == inferred_dtype
    ...
    ...     # constructor for .str-accessor will also pass
    ...     pd.Series(values).str
    )dtype)rc   nparrayobject)rd   inferred_dtypevaluesr   r   r   !any_allowed_skipna_inferred_dtype   s     
rr   c               @   sd  e Zd Zdd Zdd Zejjdedgdd Z	ejjdedgd	d
 Z
dd Zdd Zdd Zdd Zdd Zejjddeegdd Zdd Zdd Zejjdddgejjdd dgejjd!d dgd"d# Zejjd$d%d&d'gd(d)d*gd%d&d+ggd,d-d.gd/ejjd0eeed1d2 gd3d4d5d6gd/d7d8 Zd9d: Zejjd;d<d=d>d?gd@dA Zejjd;d<d=d>d?gdBdC ZdDdE ZdFdG ZdHdI ZdJdK ZdLdM ZdNdO Z ejjdddgejjdPde!j"e#j$gejjdQdRdSgdTdU Z%ejjdddgejjdPde!j"e#j$gejjdQdRdSgdVdW Z&dXdY Z'dZd[ Z(d\d] Z)d^d_ Z*d`da Z+dbdc Z,ddde Z-dfdg Z.dhdi Z/djdk Z0dldm Z1dndo Z2dpdq Z3drds Z4dtdu Z5dvdw Z6dxdy Z7dzd{ Z8d|d} Z9d~d Z:dd Z;dd Z<dd Z=ejjdg d$fg d%fg d&fg d'fdddgd(fdddgd)fdddgd*fdddgd+fgdd Z>dd Z?dd Z@dd ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQejjddddddgdd ZRdd ZSdd ZTdd ZUddÄ ZVddń ZWddǄ ZXddɄ ZYdd˄ ZZdd̈́ Z[ddτ Z\ddф Z]ddӄ Z^ddՄ Z_ddׄ Z`ddل Zaddۄ Zbdd݄ Zcdd߄ Zddd Zedd Zfdd Zgdd Zhejjdd&ddedde!j"dgfdd'd,edde!j"dgfddd-edde!j"dgfd'dd&edde!j"dgfd'dd.edde!j"dgfgdd Zidd Zjdd Zkdd Zldd  Zmdd Zndd Zodd Zpejjdeqee!jrgdd	 Zsd
d Ztdd Zudd Zvdd Zwdd Zxdd Zydd Zzdd Z{dd Z|dd Z}dd Z~d d! Zd"d# ZdS (/  TestStringMethodsc             C   s,   t jtjksttt dgjtjs(td S )Nr,   )r	   strstringsStringMethodsAssertionErrorr   )selfr   r   r   test_api   s    zTestStringMethods.test_apic          
   C   sJ   t jdddgg}d}tjt|d |j W d Q R X t|d sFtd S )Nr   brg   z5Can only use .str accessor with Index, not MultiIndex)r.   rt   )r   Zfrom_arrayspytestraisesAttributeErrorrt   hasattrrw   )rx   mimsgr   r   r   test_api_mi_raises   s
    z$TestStringMethods.test_api_mi_raisesrl   categoryc       
   
   C   s|   |}|\}}|||d}ddddddg}||krDt |jtjsxtn4d}	tjt|	d	 |j W d Q R X t|d
 sxtd S )N)rl   rf   unicoderk   rh   mixedzmixed-integerz/Can only use .str accessor with string values.*)r.   rt   )	r   rt   ru   rv   rw   r{   r|   r}   r~   )
rx   index_or_seriesrl   Zany_skipna_inferred_dtypeboxrp   rq   tZtypes_passing_constructorr   r   r   r   test_api_per_dtype   s    z$TestStringMethods.test_api_per_dtypec          
   C   sP  |}|\}}|\}	}
}d }|t krn|jdkrn|	dkrF|jddrFd}q|	dkr`|jdd r`d}q|	d	krd
}n$|t kr|dkr|tkr|	d	krd
}|d k	rtjj|d}|jj| |||d}t	|j
|	}|	dk}|	dk}dddgdg|  ddg|  }||kr||
| n:d|	 dt| d}tjt|d ||
| W d Q R X d S )Nr   r3   r<   r&   Tz#Method cannot deal with empty Indexr@   z,Split fails on empty Series when expand=TruerI   z(Need to fortify get_dummies corner casesrk   )reason)rl   r   r*   rS   r=   r   rf   r   rh   r   zmixed-integerzCannot use .str.z with values of inferred dtype .)r.   )r3   r<   )r   r*   rS   r=   )r   )r   sizer*   ro   r{   markZxfailnodeZ
add_markergetattrrt   reprr|   	TypeError)rx   r   rl   rr   re   rd   r   rp   rq   method_nameargskwargsr   r   r   methodZbytes_allowedZmixed_allowedZallowed_typesr   r   r   r   test_api_per_method   s8    
 
z%TestStringMethods.test_api_per_methodc       	      C   s   t td}|d | }|jd}t|jtjs4t|\}}}t|j|||}t|j|||}t|t	rzt
j|| n$t|t rt
j|| n||kstd S )NZaabbr4   r   )r	   listastyper   rt   ru   rv   rw   r   r   r   assert_frame_equalr   )	rx   re   srg   r   r   r   resultexpectedr   r   r   test_api_for_categorical.  s    



z*TestStringMethods.test_api_for_categoricalc             C   s   d}t |}tjtX xP|jD ]F}t|t s2ttj|j|j x"|D ]}t|tsHt	|sHtqHW q W W d Q R X |j
 jj dkstd S )Ngoogle	wikimedia	wikipedia
wikitravell)r   r   r   r   )r	   r   assert_produces_warningFutureWarningrt   r   rw   r   r+   r   dropnarq   item)rx   strsdsr   elr   r   r   	test_iterB  s    
(zTestStringMethods.test_iterc          
   C   s^   t g td}d\}}tjt xt|jD ]\}}q,W W d Q R X |dksNt|dksZtd S )N)rl   rD   r>   )rD   r>   )r	   ro   r   r   r   	enumeratert   rw   )rx   r   ir   r   r   r   test_iter_emptyY  s    z!TestStringMethods.test_iter_emptyc          
   C   sR   t dg}tjt xt|jD ]\}}q"W W d Q R X | sBttj|| d S )Nr   )r	   r   r   r   r   rt   rw   r   )rx   r   r   r   r   r   r   test_iter_single_elementg  s    

z*TestStringMethods.test_iter_single_elementc          
   C   sh   t dd tdD }d\}}tjt xt|jD ]\}}q6W W d Q R X |dksXt|dksdtd S )Nc             S   s"   g | ]}t d tdtddqS )Nr      )r=   r   )r^   r]   r   r   r   
<listcomp>r  s    zATestStringMethods.test_iter_object_try_string.<locals>.<listcomp>   rD   h)rD   r   )r	   ranger   r   r   r   rt   rw   )rx   r   r   r   r   r   r   test_iter_object_try_stringq  s    z-TestStringMethods.test_iter_object_try_stringotherNc             C   sH   |}ddg}|r||}n|}||ddj j|dd}|jdksDtd S )Nr   rz   name)r   r   )r   )rt   r   r   rw   )rx   r   r   r   rq   r   r   r   r   test_str_cat_name}  s    
z#TestStringMethods.test_str_cat_namec       	      C   sD  |}|dddddt jg}|jj }d}||ks4t|jjdd}d}||ksRt|jjdd	d
}d}||ksrtt jdt jdddt jgtd}|ddddddg}|jj|dd}t|| |jjt|dd}t|| d}t	dddg}t
jt|d |jj|j W d Q R X t
jt|d |jjt| W d Q R X d S )Nr   rz   rg   Zaabbc-)na_repzaabbc-r]   NA)r   r   Za_a_b_b_c_NAdfoo)rl   aaza-bbZbdZcfooz--z<If `others` contains arrays or lists \(or other list-likes.*123)r.   )rm   nanrt   r   rw   rn   ro   r   r   r	   r{   r|   
ValueErrorrq   )	rx   r   r   r   r   r   r   rgxr8   r   r   r   test_str_cat  s.    


zTestStringMethods.test_str_catc             C   sh   |}|ddddg}d}t jt|d |jjd W d Q R X t jt|d |jjd W d Q R X d S )	Nr   rz   rg   r   z'Did you mean to supply a `sep` keyword?)r.   |z    )r{   r|   r   rt   r   )rx   r   r   r   messager   r   r   #test_str_cat_raises_intuitive_error  s    z5TestStringMethods.test_str_cat_raises_intuitive_errorr   r,   dtype_targetro   dtype_callerc       
      C   s.  |}t ddddg|d}|t kr$|n
t||d}t ddddg|d}t dddd	g}|t kr`|n
t||d}|jj|j|d
}	t|	| t|j|d}|jj||d
}	t|	| |jj|j|d
}	t|	| t|j|jd}t dddddg}|t kr|nt||jd d d}|jj||d
}	t|	| d S )Nr   rz   )rl   )r+   rg   abr   r   ac)r   r>   )r   r	   rt   r   rq   r   )
rx   r   r   r   r   r   r   r   r   r   r   r   r   test_str_cat_categorical  s$    


"z*TestStringMethods.test_str_cat_categoricaldatar>   rF   r6   g?g?g333333?rz   ZintegersZfloatsr   )rb   r   c             C   s   t j| tdS )N)rl   )rm   rn   ro   )xr   r   r   <lambda>  s    zTestStringMethods.<lambda>r	   r   r   znp.arrayc             C   sJ   t dddg}||}d}tjt|d |jj|ddd W d Q R X d S )	Nr   rz   rg   z;Concatenation requires list-likes containing only strings.*)r.   outerr   )r   r   )r	   r{   r|   r   rt   r   )rx   r   r   r   r   r   r   r   r   test_str_cat_wrong_dtype_raises  s
    z1TestStringMethods.test_str_cat_wrong_dtype_raisesc          R   C   s  |}t ddddg}|t kr |n
t||d}tdddd	g|jd}t|t||dgd
d}t ddddg}|t krv|nt|j|jd}|jj|}t|| |jj|j}t|| |jj||g}t|| |jj||jg}t|| ddddg|_|ddddg}|t kr|nt|j|jd}|jj||g}t|| |jj||jg}t|| ddddg|_|ddddg}|t kr|nt|j|jd}|jj|}t|| d}tdddg}	t|	|	gd
d}
tj	t
|d |jj|
j W d Q R X tj	t
|d |jj|	j|jg W d Q R X tj	t
|d |jj|	j|g W d Q R X d}tdtjdd g}tj	t|d |jj|dg W d Q R X tj	t|d |jj||g W d Q R X tj	t|d |jj||jg W d Q R X tj	t|d |jj|||gg W d Q R X tj	t|d |jjt| W d Q R X tj	t|d |jj|t|g W d Q R X tj	t|d |jjd
 W d Q R X tj	t|d  |jjt|jt|g W d Q R X d S )Nr   rz   rg   r   )r+   ABCDr>   )axisZaAaZbBbZcCcZdDdZaDaZbAbZcBcZdCdZaDdZbAaZcBbZdCcz<If `others` contains arrays or lists \(or other list-likes.*r   r   r   )r.   z*others must be Series, Index, DataFrame,.*u)r   r	   rq   r
   rt   r   r   r+   r{   r|   r   rm   r   r   setiterr   )rx   r   r   r   r   r   r   r   r   r8   er   r   r   r   test_str_cat_mixed_inputs  sl    






z+TestStringMethods.test_str_cat_mixed_inputsr   r   r   innerr   c       
      C   s   |}t ddddgddddgd}t dddd	gddd
dgd}|j||d\}}|jj|dd}|tkr~t|}t|}t|}|jj||dd}	t|	| d S )Nr   rz   rg   r   )r+   r   r   Er   r   )r   r   )r   )r   r   )r	   Zalignrt   r   r   r   )
rx   r   r   r   r   r   satar   r   r   r   r   test_str_cat_align_indexed\  s    z,TestStringMethods.test_str_cat_align_indexedc             C   s  t ddddg}t ddddgdddd	gd
}t||gd	d}t dddddg}|j|jj|j|d }|jj||g|dd}tj|| |jj||dd}tj|| t	j
ddddg}t dddddg}|dkr|j|j@ n
|j|jB }	|j|jj|	|d }|jj||g|dd}tj|| tjtdd |jj|t|g|d  W d Q R X d!}
t d"d#d$gj}tjt|
d |jj||d  W d Q R X tjt|
d |jj||g|d  W d Q R X d S )%Nr   rz   rg   r   r   r6   r   r   r>   )r+   )r   aaabbbzc--dddz-ee)howr   )r   r   r   r   r   r   ZaaAZbbBzc-CZddDz-e-r   zothers must be Series,.*)r.   )r   z<If `others` contains arrays or lists \(or other list-likes.*r   r   r   )r	   r
   locr+   r   rt   r   r   r   rm   rn   r{   r|   r   r   rq   r   )rx   r   r   r   r   Zexpected_outerr   r   r   Zrhs_idxr   r8   r   r   r   test_str_cat_align_mixed_inputso  s.     "z1TestStringMethods.test_str_cat_align_mixed_inputsc       	      C   s   |}|}t ddddg}|t kr$|n
t||d}|tjgd td}|t krP|n
t||d}|tkr~ttjgd |jtd}nt tjgd td}|jj|d	d
}t|| |tkrttjgd t|jd}|jj|d	d
}t	j
|| d S )Nr   rz   rg   r   )r+   r   )rl   )r+   rl   r   )r   )rl   r+   )r   r	   rm   r   ro   r+   rt   r   r   r   r   )	rx   r   Zindex_or_series2r   r   r   r   r   r   r   r   r   test_str_cat_all_na  s    
z%TestStringMethods.test_str_cat_all_nac             C   s   t ddddg}t ddddgdddd	gd
}t dddddg}|jjt||jgddd}tj|| t ddgddgd
}|jj|jdg |jdg gddd}tj|| d S )Nr   rz   rg   r   r   r6   r   r   r>   )r+   r   r   zc-cr   z-e-r   r   )r   r   zaa-zd-dr   )r	   rt   r   r   rq   r   r   r   )rx   r   r   r   r   r   r   r   test_str_cat_special_cases  s    &z,TestStringMethods.test_str_cat_special_casesc             C   s   t tjddgdddggddgdd	}|j }||jdk }|jjd
}|jjd
}|jj|dd}|j	d dksvt
|jj||gdd}|j	d dkst
d S )Ni  i  r>   rF   r6   yearmonth)names)r+   rt   r4   )r   z2011 2z2011 2 2)r   r   Zfrom_productZreset_indexr   r   r   rt   r   r   rw   )rx   ZdfZstr_yearZ	str_monthZstr_bothZstr_multipler   r   r   test_cat_on_filtered_index  s     z,TestStringMethods.test_cat_on_filtered_indexc          
   C   s>  t jddt jdgt jd}tj|d}t jddt jdg}tj|| t|j	j
d}tddt jdg}t|tsvttj|| t jd	t jd
dtj dd ddg	td}tj|d	}t jdt jdt jt jdt jt jt jg	}tj|| t|j	j
d	}tdt jdt jt jdt jt jt jg	}t|ts.ttj|| d S )Nr   ZfoofooZfoooofooofommmfoo)rl   zf[o]+r>   rF   r   r   rz   Tg       @r   )rm   rn   r   object_ru   Z	str_countr   assert_numpy_array_equalr	   rt   r   r   rw   r   r   todayro   )rx   rq   r   expr   rsxpr   r   r   
test_count  s&    (&zTestStringMethods.test_countc          
   C   s  t jdt jdddgt jd}d}tj||}t jdt jdddgt jd}tj|| tj||dd	}t jdt jdddgt jd}tj|| t jdd
ddgtd}tj||}t jddddg}|j	t j
ksttj|| t jddddgtd}tj|ddd}t jddddg}tj|| tj|dddd}t jddddg}tj|| t jdt jddtj dd ddg	td}tj|d}t jdt jdt jt jdt jt jt jg	t jd}tj|| t|jjd}tdt jdt jt jdt jt jt jg	}t|tsttj|| t jdt jddgt jd}d}tj||}t jdt jddgt jd}tj|| tj||dd}t jddddg}tj|| t jdd
ddgt jd}tj||}t jddddg}|j	t j
ksttj|| d S )Nr   Zfooommm__fooZmmm_zfoommm[_]+bar)rl   zmmm[_]+FT)regexZxyzFooZxYzZfOOomMm__fOoZMMM_zFOO|mmm)case)r   r   r   rz   r>   g       @o)r#   )rm   rn   r   r   ru   Zstr_containsr   r   ro   rl   bool_rw   r   r   r	   rt   r   r   r   )rx   rq   patr   r   r   r   r   r   r   r   test_contains  s^     
$zTestStringMethods.test_containsc             C   s   t ddddtjgdd}|jjddd}t dddddg}tj|| |jjddd}t dddddg}tj|| t ddddtjg}|jjddd}t dddddg}tj|| |jjddd}t dddddg}tj|| d S )	Nr   rz   rg   r   )rl   T)r#   F)r	   rm   r   rt   r   r   r   )rx   rq   r   r   r   r   r   !test_contains_for_object_category6  s    z3TestStringMethods.test_contains_for_object_category
null_valuer#   TFc       
   
   C   sB  t d|ddd|dg|d}|jjd}t dtjdddtjdg}tj|| |jjd|d	}t d|ddd|dg}tj|| tjd
tjddtj	 dd ddg	tj
d}tj|d}tjdtjdtjtjdtjtjtjg	tj
d}	tj||	 t |jjd}t|t stt dtjdtjtjdtjtjtjg	}	tj||	 d S )Nomfoo_nomnombar_foor   )rl   FT)r#   r   rz   r>   g       @r_   )r	   rt   rA   rm   r   r   r   rn   r   r   r   ru   Zstr_startswithr   r   rw   )
rx   rl   r   r#   rq   r   r   r   r   r   r   r   r   test_startswithM  s,    
 
$z!TestStringMethods.test_startswithc       
   
   C   s@  t d|ddd|dg|d}|jjd}t dtjdddtjdg}tj|| |jjd|d	}t d|ddd|dg}tj|| tjd
tjddtj	 dd ddg	t
d}tj|d}tjdtjdtjtjdtjtjtjg	tjd}	tj||	 t |jjd}t dtjdtjtjdtjtjtjg	}	t|t s0ttj||	 d S )Nr   r   r   r   r   )rl   FT)r#   r   rz   r>   g       @r_   )r	   rt   r"   rm   r   r   r   rn   r   r   ro   ru   Zstr_endswithr   r   r   rw   )
rx   rl   r   r#   rq   r   r   r   r   r   r   r   r   test_endswithr  s,     
$zTestStringMethods.test_endswithc          
   C   s   t ddtjddg}|jj }t ddtjddg}tj|| t dtjdd	tj d
d ddg	}|jj }t dtjdtjtjdtjtjtjg	}tj	|| d S )NFOOBARBlahblurgr   BarBlurgbarTblahr>   g       @)
r	   rm   r   rt   rZ   r   r   r   r   assert_almost_equal)rx   rq   r   r   r   r   r   r   
test_title  s    

$zTestStringMethods.test_titlec          
   C   s   t dtjddg}|jj }t dtjddg}tj|| |jj }tj|| t dtjddtj	 dd d	d
g	}|jj }t |jj }t dtjdtjtjdtjtjtjg	}t
|t sttj|| d S )Nr   r   ZOMZNOMr   rz   Tr   r>   g       @)r	   rm   r   rt   r[   r   r   rT   r   r   r   rw   )rx   rq   r   r   r   r   r   r   r   r   test_lower_upper  s    

 
&z"TestStringMethods.test_lower_upperc          
   C   s   t ddtjddg}|jj }t ddtjddg}tj|| t dtjdd	tj d
d ddg	}|jj }t dtjdtjtjdtjtjtjg	}tj	|| d S )Nr  r  r  r  r   r  r  r	  Tr
  r>   g       @)
r	   rm   r   rt   rH   r   r   r   r   r  )rx   rq   r   r   r   r   r   r   test_capitalize  s    

$z!TestStringMethods.test_capitalizec          
   C   s   t ddtjddg}|jj }t ddtjddg}tj|| t dtjdd	tj dd d
dg	}|jj }t dtjdtjtjdtjtjtjg	}tj	|| d S )Nr  r  r  r  r   r	  ZbLAHZBLURGTr>   g       @)
r	   rm   r   rt   rY   r   r   r   r   r  )rx   rq   r   r   r   r   r   r   test_swapcase  s    

$zTestStringMethods.test_swapcasec             C   s   dddddg}t |}|jj j dd |D ks6t|jj j dd |D ksVt|jj j d	d |D ksvt|jj j d
d |D kst|jj j dd |D kstd S )Nr   r   ZCCCZDdddZeEEEc             S   s   g | ]}|j  qS r   )rT   )r^   vr   r   r   r     s    z6TestStringMethods.test_casemethods.<locals>.<listcomp>c             S   s   g | ]}|j  qS r   )r[   )r^   r  r   r   r   r     s    c             S   s   g | ]}|j  qS r   )rZ   )r^   r  r   r   r   r     s    c             S   s   g | ]}|j  qS r   )rH   )r^   r  r   r   r   r     s    c             S   s   g | ]}|j  qS r   )rY   )r^   r  r   r   r   r     s    )	r	   rt   rT   tolistrw   r[   rZ   rH   rY   )rx   rq   r   r   r   r   test_casemethods  s        z"TestStringMethods.test_casemethodsc             C   s  t dtjg}|jjdd}t dtjg}tj|| |jjdddd}t dtjg}tj|| t dtjd	d
tj dd ddg	}t |jjdd}t dtjdtjtjdtjtjtjg	}t	|t st
tj|| t djdg}t djdg}|jjddtjd}tj|| d}x~t tfD ]r}xjd dddifD ]X}	xPddd gddddgfD ]6}
||
}tjt|d |jjd|	 W d Q R X qRW q6W q"W d S )NfooBAD__barBADzBAD[_]*r,   foobarr>   )n	foobarBADaBADbBADTfooBADg       @r   rz   r   s   abcd,àzutf-8s   abcd, àz(?<=\w),(?=\w)z, )flagsz!repl must be a string or callabler6   rg   ad)r.   )r	   rm   r   rt   r7   r   r   r   r   r   rw   r  r   reUNICODEr   r{   r|   r   )rx   rq   r   r   r   r   r   r   klassreplr   r   r   r   test_replace  s0    &zTestStringMethods.test_replacec             C   s  t dtjg}dd }|jjd|dd}t dtjg}tj|| d}d	d }tjt	|d
 |jjd| W d Q R X dd }tjt	|d
 |jjd| W d Q R X ddd}tjt	|d
 |jjd| W d Q R X t dtjg}d}dd }|jj||}t dtjg}tj|| d S )Nr  c             S   s   | j dj S )Nr   )grouprY   )mr   r   r   r     s    z9TestStringMethods.test_replace_callable.<locals>.<lambda>z[a-z][A-Z]{2}rF   )r  foObaD__baRbaDzO((takes)|(missing)) (?(2)from \d+ to )?\d+ (?(3)required )positional arguments?c               S   s   d S )Nr   r   r   r   r   r     s    )r.   r   c             S   s   d S )Nr   )r"  r   r   r   r   r     s    c             S   s   d S )Nr   )r"  r   yr   r   r   r     s    zFoo Bar Bazz,(?P<first>\w+) (?P<middle>\w+) (?P<last>\w+)c             S   s   | j dj S )NZmiddle)r!  rY   )r"  r   r   r   r   &  s    ZbAR)N)
r	   rm   r   rt   r7   r   r   r{   r|   r   )rx   rq   r  r   r   Zp_errr   r   r   r   test_replace_callable  s*    
z'TestStringMethods.test_replace_callablec       	      C   s  t dtjg}tjd}|jj|d}t dtjg}tj|| |jj|ddd}t dtjg}tj|| t dtjd	d
t	j
 dd ddg	}t |jj|d}t dtjdtjtjdtjtjtjg	}t|t sttj|| t djdg}t djdg}tjdtjd}|jj|d}tj|| t dtjg}tjd}tjtdd |jj|dtjd}W d Q R X tjtdd |jj|ddd}W d Q R X tjtdd |jj|dd
d}W d Q R X t dtjg}dd }tjd}|jj||dd}t dtjg}tj|| d S ) Nr  zBAD[_]*r,   r  r>   )r  r  r  r  Tr  g       @r   rz   r   s   abcd,àzutf-8s   abcd, àz(?<=\w),(?=\w))r  z, ZfooBAD__barBAD__badzcase and flags cannot be)r.   F)r   c             S   s   | j dj S )Nr   )r!  rY   )r"  r   r   r   r   Z  s    z?TestStringMethods.test_replace_compiled_regex.<locals>.<lambda>z[a-z][A-Z]{2}rF   r#  )r	   rm   r   r  compilert   r7   r   r   r   r   r   rw   r  r   r  r{   r|   r   
IGNORECASE)	rx   rq   r   r   r   r   r   r   r  r   r   r   test_replace_compiled_regex+  sB    
&

z-TestStringMethods.test_replace_compiled_regexc             C   s   t ddtjg}t ddtjg}|jjdd}tj|| t ddtjg}|jjdddd}tj|| dd	 }tjd
}d}t	j
t|d |jjd|dd W d Q R X d}t	j
t|d |jj|ddd W d Q R X d S )Nzf.or   Zbaozf.baF)r   c             S   s   | j dj S )Nr   )r!  rY   )r"  r   r   r   r   m  s    z8TestStringMethods.test_replace_literal.<locals>.<lambda>z[a-z][A-Z]{2}z2Cannot use a callable replacement when regex=False)r.   abczCCannot use a compiled regex as replacement pattern with regex=Falser,   )r	   rm   r   rt   r7   r   r   r  r&  r{   r|   r   )rx   rq   r   r   Zcallable_replZcompiled_patr   r   r   r   test_replace_literal`  s    
z&TestStringMethods.test_replace_literalc          
   C   s   t ddtjdtjdg}|jjd}t ddtjdtjd	g}tj|| |jjd
dddddg}t ddtjdtjdg}tj|| t dtjddtj dd d
dg	}t |jjd}t dtjdtjtjdtjtjtjg	}t	|t st
tj|| d S )Nr   rz   rg   r   r6   r   r   cccr   r>   rF   r         r   ccccZddddddTr   g       @Z	foofoofoo)r	   rm   r   rt   r5   r   r   r   r   r   rw   )rx   rq   r   r   r   r   r   r   r   r   test_repeatx  s     $zTestStringMethods.test_repeatc             C   s|   t dd gdd}|jjddg}t dd gdd}tj|| t ddgdd}|jjdd g}t dd gdd}tj|| d S )Nr   rf   )rl   r6   r   r   rz   )r	   rt   r5   r   r   )rx   rq   r   r   r   r   r   test_repeat_with_null  s    z'TestStringMethods.test_repeat_with_nullc          
   C   sT  t dtjdg}|jjd}t dtjdg}tj|| t ddtjdg}|jjd}t ddtjdg}tj|| t dtjd	dtj dd d
dg	}t |jjd}t dtjdtjtjdtjtjtjg	}t	|t st
tj|| t ddtjgjjddd}t dddg}tj|| t ddtjgjjd}t dtjtjg}tj|| d S )Nr  r   z.*(BAD[_]+).*(BAD)TFBAD_BADleroybrownz.*BAD[_]+.*BADaBAD_BAD	BAD_b_BADr>   g       @r   r   )r#   )r	   rm   r   rt   r.   r   r   r   r   r   rw   )rx   rq   r   r   r   r   r   resr   r   r   
test_match  s8    &zTestStringMethods.test_matchc             C   s   t ddtjdg}|jjd}t ddtjdg}tj|| t ddtjdgdd}|jjd}t ddtjdgd	d}tj|| d S )
Nr  r2  r   z.*BAD[_]+.*BADTFrf   )rl   boolean)r	   rm   r   rt   r/   r   r   )rx   rq   r   r   Zstring_valuesZ
string_expr   r   r   test_fullmatch  s    z TestStringMethods.test_fullmatchc             C   s>   t dtjdg}tjtdd |jjdd d W d Q R X d S )Nr  r   zexpand must be True or False)r.   z.*(BAD[_]+).*(BAD))r&   )r	   rm   r   r{   r|   r   rt   r$   )rx   rq   r   r   r   test_extract_expand_None  s    z*TestStringMethods.test_extract_expand_Nonec             C   sJ   t dtjdg}|jjd}t|ts*t|jjddd}tj	|| d S )Nr  r   z.*(BAD[_]+).*T)r&   )
r	   rm   r   rt   r$   r   r   rw   r   r   )rx   rq   Zresult_unspecifiedZresult_truer   r   r   test_extract_expand_unspecified  s
    z1TestStringMethods.test_extract_expand_unspecifiedc             C   s:  t dtjdg}tjtjg}|jjddd}tddg||g}tj|| t dtjd	d
tj	 dd ddg	}t |jjddd}tddg|ddg||||||g	}tj|| t dtjdg}|jjddd}tddg||g}tj|| t
dddddg}tjtdd |jjddd W d Q R X xt t
gD ]}|dddg}	d}
tjt|
d |	jjddd W d Q R X tjt|
d |	jjddd W d Q R X |ddg}	|	jjddd}|jdkst|ddgdd}|t krtj|| ntj|| q0W t dddg}|jjddd}t tjtjtjgtd }tj|| |jjd!dd}ttjtjgtjtjgtjtjggtd }tj|| |jjd"dd}t dd#tjg}tj|| |jjddd}tdd$gd#d%gtjtjgg}tj|| |jjd&dd}t dd#tjgd'd}tj|| |jjd(dd}tdd$gd#d%gtjtjggd'd)gd*}tj|| |jjd+dd}tdd$gd#d%gtjtjggd,d)gd*}tj|| |jjd-dd}t dd#tjg}tj|| t d.d/d0gjjd1dd}tdd$gd#d%gtjtjgg}tj|| t ddd2gjjd3dd}tdd$gd#d%gtjd2ggd'd)gd*}tj|| t ddd4gjjd5dd}tdd$gd#d%gd4tjggd'd)gd*}tj|| d6d7 }tjtjtjtjtjtjg}x|D ]}||  qW t d8d9d:gd;d}|jjd<dd}t d=d>d?gd@d}tj|| |j|jks6td S )ANr  r   z.*(BAD[_]+).*(BAD)F)r&   BAD__BADr3  r4  Tr>   g       @BAD_A1A2A3ZA4ZB5	supported)r.   z([AB])([123])B2C3z"pattern contains no capture groupsz
[ABC][123]z
(?:[AB]).*z(?P<uno>A)\dunor   )r   z(_))rl   z(_)(_)z([AB])[123]r   r   r   z(?P<letter>[AB])letterz!(?P<letter>[AB])(?P<number>[123])number)columnsz([AB])(?P<number>[123])r   z([AB])(?:[123])A11B22C33z([AB])([123])(?:[123])r   z"(?P<letter>[AB])?(?P<number>[123])r   z#(?P<letter>[ABC])(?P<number>[123])?c             S   s   dddg}| d t | } t|| d}|jjddd}tdd	tjg| d}tj|| t|| djjd
dd}ddgdd	gdtjgg}t|ddg| d}tj	|| d S )Nr>  rB  r   )r+   z(\d)F)r&   r   r   z(?P<letter>\D)(?P<number>\d)?r   r   rE  rF  )rG  r+   )
rS   r	   rt   r$   rm   r   r   r   r   r   )r+   r   r   r   r   e_listr   r   r   check_indexg  s    

z@TestStringMethods.test_extract_expand_False.<locals>.check_indexa3b3c2Zbobz(?P<sue>[a-z])r   rz   rg   Zsue)r	   rm   r   rt   r$   r   r   r   r   r   r   r{   r|   r   r   rw   r   r   ro   makeStringIndexmakeUnicodeIndexmakeIntIndexmakeDateIndexmakePeriodIndexmakeRangeIndex)rx   rq   err   r   r   r   idxr  s_or_idxr   r   rL  i_funsr+   rr   r   r   r   test_extract_expand_False  s    "
($$

"
"
z+TestStringMethods.test_extract_expand_Falsec             C   st  t dtjdg}tjtjg}|jjddd}tddg||g}tj|| t dtjd	dtj	 dd d
dg	}t |jjddd}tddg|ddg||||||g	}tj|| xt t
gD ]}|dddg}d}	tjt|	d |jjddd W d Q R X tjt|	d |jjddd W d Q R X |ddg}|jjddd}
t|
tsLt|
d }tj|t ddgdd qW d S )Nr  r   z.*(BAD[_]+).*(BAD)T)r&   r;  r<  r3  r4  r>   g       @r=  r>  rB  rC  z"pattern contains no capture groups)r.   z
[ABC][123]z
(?:[AB]).*r?  z(?P<uno>A)\drD  r   )r   )r	   rm   r   rt   r$   r   r   r   r   r   r   r{   r|   r   r   rw   r   )rx   rq   rV  r   r   r   r   r  rX  r   Z	result_dfZresult_seriesr   r   r   test_extract_expand_True  s<    "z*TestStringMethods.test_extract_expand_Truec             C   s  xdD ]}t dddg|d}|jjddd}ttjtjtjgtd	}tj|| |jjd
dd}ttjtjgtjtjgtjtjggtd	}tj|| |jjddd}tddtjg}tj|| |jjddd}tddgddgtjtjgg}tj|| |jjddd}tdddtjgi}tj|| |jjddd}ddgddgtjtjgg}t|ddgd}tj|| |jjddd}t|ddgd}tj|| |jjddd}tddtjg}tj|| qW d S )Nseries_namer>  rB  rC  )r   z(_)T)r&   )rl   z(_)(_)z([AB])[123]r   r   z([AB])([123])r   r   z(?P<letter>[AB])rE  z!(?P<letter>[AB])(?P<number>[123])rF  )rG  z([AB])(?P<number>[123])r   z([AB])(?:[123]))Nr]  )	r	   rt   r$   r   rm   r   ro   r   r   )rx   r]  r   r   r   rK  r   r   r   test_extract_series  s8    (z%TestStringMethods.test_extract_seriesc             C   s"  t dddgjjddd}tddgd	d
gtjtjgg}tj|| t dddgjjddd}ddgd	d
gtjdgg}t|ddgd}tj|| t dddgjjddd}ddgd	d
gdtjgg}t|ddgd}tj|| dd }tjtj	tj
tjtjtjg}x|D ]}||  q
W d S )NrH  rI  rJ  z([AB])([123])(?:[123])T)r&   r   r   r   r   r>  rB  r   z"(?P<letter>[AB])?(?P<number>[123])rE  rF  )rG  r   z#(?P<letter>[ABC])(?P<number>[123])?c             S   s   dddg}| d t | } t|| djjddd}tdd	tjg| d}tj|| t|| djjd
dd}ddgdd	gdtjgg}t|ddg| d}tj|| d S )Nr>  rB  r   )r+   z(\d)T)r&   r   r   z(?P<letter>\D)(?P<number>\d)?r   r   rE  rF  )rG  r+   )	rS   r	   rt   r$   r   rm   r   r   r   )r+   r   r   r   rK  r   r   r   rL    s    

zCTestStringMethods.test_extract_optional_groups.<locals>.check_index)r	   rt   r$   r   rm   r   r   r   rP  rQ  rR  rS  rT  rU  )rx   r   r   rK  rL  rY  r+   r   r   r   test_extract_optional_groups  s.    



z.TestStringMethods.test_extract_optional_groupsc             C   sD   t dddgdd}|jjddd}td	d
ddgi}tj|| d S )NrM  rN  rO  r]  )r   z(?P<letter>[a-z])T)r&   rE  r   rz   rg   )r	   rt   r$   r   r   r   )rx   r   rZ  r   r   r   r   'test_extract_single_group_returns_frame  s    z9TestStringMethods.test_extract_single_group_returns_framec             C   s  dddddt jdg}d7d8d9d:d;d<d=d>g}d}dddg}t|}tjd?d@dAdBdCdDdEdFgdGd}t|||}|jj|tj	}t
j|| tjdHdIdJdKdLdMdNg}	t||	}
tjdOdPdQdRdSdTdUdVgdWd}t|||}|
jj|tj	}t
j|| t||	}dX|j_dY|_t|||}|jj|tj	}t
j|| dd,d-g}d.}t|jj|}tjdZd[d\gd]d}td^t jd1ft jd2fg|d3d4gd5}t
j|| d6}t|jj|}td_t jd1ft jd2fg|dd4gd5}t
j|| d S )`Nzdave@google.comztdhock5@gmail.comzmaudelaperriere@gmail.comz'rob@gmail.com some text steve@gmail.comz%a@b.com some text c@d.com and e@f.comr,   daver   comtdhock5gmailmaudelaperriererobstever   rz   rg   r   r   r_   zq
        (?P<user>[a-z0-9]+)
        @
        (?P<domain>[a-z]+)
        \.
        (?P<tld>[a-z]{2,4})
        userdomaintldr   r>   rF   r6   r   r.   )r   singleDaveTobyMaudemultiplerobAndSteveabcdefnonemissingrk   matchesdescriptionr>  Z32z"(?P<letter>[AB])?(?P<number>[123])r   r   r   r   rE  rF  )rG  z([AB])?(?P<number>[123]))ra  r   rb  )rc  rd  rb  )re  rd  rb  )rf  rd  rb  )rg  rd  rb  )r   rz   rb  )rg   r   rb  )r   r_   rb  )r   r   )r>   r   )rF   r   )r6   r   )r6   r>   )r   r   )r   r>   )r   rF   )Nr.   )rk  rl  )rk  rm  )rk  rn  )ro  rp  )ro  rq  )rr  rs  )rr  rk   )rk  rl  r   )rk  rm  r   )rk  rn  r   )ro  rp  r   )ro  rp  r>   )ro  rq  r   )ro  rq  r>   )ro  rq  rF   )NNr.   )rt  ru  )rt  ru  r.   )r>   r   )rF   r   )rF   r>   )Nr.   )r   r   )r   r   )rm   r   r	   r   from_tuplesr   rt   r'   r  VERBOSEr   r   r+   r   )rx   Zsubject_listZexpected_tuplesZnamed_patternZexpected_columnsSZexpected_indexZexpected_dfZcomputed_dfZseries_indexZSiZSnpatternr   r   r   test_extractall$  s    



z!TestStringMethods.test_extractallc             C   s   t dddgdd}|jjd}tjddddgdd}tdddddgi|}tj|| |jjd}tddddg|}tj|| d S )NrM  rN  d4c2r]  )r   z(?P<letter>[a-z])r   r>   rF   r.   )r   rE  r   rz   r   rg   z([a-z]))r   r   )r>   r   )rF   r   )rF   r>   )Nr.   )r	   rt   r'   r   rv  r   r   r   )rx   r   rZ  r   r   r   r   r   test_extractall_single_group  s    z.TestStringMethods.test_extractall_single_groupc             C   sV   t dddgdd}|jjd}tjddddgdd}tddddg|}tj|| d S )NZab3Zabc3Zd4cd2r]  )r   z([a-z]+)r   r>   rF   r.   )r   r   r*  r   Zcd)r   r   )r>   r   )rF   r   )rF   r>   )Nr.   )r	   rt   r'   r   rv  r   r   r   )rx   r   rZ  r   r   r   r   r   ,test_extractall_single_group_with_quantifier  s    z>TestStringMethods.test_extractall_single_group_with_quantifierzdata, namesi1i2rM  rN  r{  c       	         s8  t | t |dkr*tt |d d}n$ fddt D }tj||d}t|d|dd	}tjg |d d}|jjd}tdg|d}t	j
|| |jjd}tddg|d}t	j
|| |jjd}tdg|d}t	j
|| |jjd}tddg|d}t	j
|| |jjd}tddg|d}t	j
|| d S )Nr>   r   )r   c             3   s    | ]}t |g d   V  qdS )r>   N)tuple)r^   r   )r  r   r   	<genexpr>  s    z?TestStringMethods.test_extractall_no_matches.<locals>.<genexpr>)r   r]  ro   )r   r+   rl   r.   z(z))rG  r+   z(z)(z)z(?P<first>z)firstz(?P<first>z)(?P<second>z)secondz(z)(?P<second>z))r.   )rS   r   r   r   rv  r	   rt   r'   r   r   r   )	rx   r   r   r   r   r   eirZ  r   r   )r  r   test_extractall_no_matches  s,    z,TestStringMethods.test_extractall_no_matchesc             C   s  t dddgdd}|jjd}tjdddgd d	gd
}tddddgi|d}tj|| x@tdddgtdddgddgD ]}|jjd}tj|| qzW t dddgdtdddgddd}|jjd}tjdddgdd	gd
}tddddgi|d}tj|| d S )NZa1a2Zb1c1xxx)r   z[ab](?P<digit>\d)r   r>   r.   )r   digitr   r   )r+   Zs_nameXXyyzzZidx_name)r   r+   )r   r   )r   r>   )r>   r   )r  r   )r  r>   )r  r   )	r	   rt   r'   r   rv  r   r   r   r   )rx   r   r5  Zexp_idxr   rW  r   r   r   test_extractall_stringindex  s(    z-TestStringMethods.test_extractall_stringindexc          	   C   s<   t dddgdd}tjtdd |jjd W d Q R X d S )	NrM  rN  r{  r]  )r   zno capture groups)r.   z[a-z])r	   r{   r|   r   rt   r'   )rx   r   r   r   r   test_extractall_errors  s    z(TestStringMethods.test_extractall_errorsc             C   s   t dddgdddgdd}|jjjd	d
d}tdddg}tj|| |jjjdd
d}dddg}t|ddgd}tj|| d S )NrM  rN  r{  r@  ZB3ZD4r]  )r+   r   z([A-Z])T)r&   r   r   r   z!(?P<letter>[A-Z])(?P<digit>[0-9])r   4rE  r  )rG  )r   r   )r   r   )r   r  )r	   r+   rt   r$   r   r   r   )rx   r   rZ  r   rK  r   r   r   !test_extract_index_one_two_groups  s    
z3TestStringMethods.test_extract_index_one_two_groupsc             C   s   t dddgdd}d}|jj|dd}|jj|}|jd	d
d}tj|| d}|jj|dd}|jj|}|jd	d
d}tj|| d}|jj|dd}	|jj|}|jd	d
d}tj|	| d}
|jj|
dd}|jj|
}|jd	d
d}tj|| d S )NrM  rN  rO  r]  )r   z([a-z])([0-9])T)r&   r   r.   )levelz!(?P<letter>[a-z])(?P<digit>[0-9])z(?P<group_name>[a-z])z([a-z]))r	   rt   r$   r'   xsr   r   )rx   r   pattern_two_nonameextract_two_nonameZhas_multi_indexZno_multi_indexpattern_two_namedextract_two_namedpattern_one_namedextract_one_namedpattern_one_nonameextract_one_nonamer   r   r   test_extractall_same_as_extract  s*    z1TestStringMethods.test_extractall_same_as_extractc             C   s  t jdddgdd	}td
ddg|dd}d}|jj|dd}|jj|}|jddd}tj|| d}|jj|dd}|jj|}|jddd}tj|| d}	|jj|	dd}
|jj|	}|jddd}tj|
| d}|jj|dd}|jj|}|jddd}tj|| d S )Nr   r  r   r  r   thirdcapitalordinal)r   rM  rN  rO  r]  )r   z([a-z])([0-9])T)r&   r   r.   )r  z!(?P<letter>[a-z])(?P<digit>[0-9])z(?P<group_name>[a-z])z([a-z]))r   r  )r   r  )r   r  )r  r  )	r   rv  r	   rt   r$   r'   r  r   r   )rx   r   r   r  r  Zhas_match_indexZno_match_indexr  r  r  r  r  r  r   r   r   -test_extractall_same_as_extract_subject_index'  s0    z?TestStringMethods.test_extractall_same_as_extract_subject_indexc             C   sB  t td }}t dd}t td}t td}tj||jj| d|jj ksRttj||jj  tj||jj	d tj||jj
d tj||jjd tj||jjd tj||jj  tj||jj  tj||jjdd tj||jjd tj||jjd tjtdgtd	|jjd
dd tjtddgtd	|jjddd tj||jjd
dd tjtddgtd	|jjddd tjttd|jj  tj||jjd tj||jj  tj||jjd tj||jjd tj||jjd tj||jjd tj||jjd tj||jjd tj||jjd tj||jjddd tj||jj ddd tj||jj!dd tj||jj!dd tj||jj"  tj||jj#  tj||jj$  tj||jj%d tj||jj&d tj||jj'd tj||jj(d tj||jj)  tj||jj*  tj||jj+  tj||jj,  tj||jj-  tj||jj.  tj||jj/  tj||jj0  tj||jj1  tj||jj2  tj||jj3  tj||jj4d tj5dd}tj||jj6| d S )N)rl   int64r,   r   rz   r6   z^ar   )rG  rl   z()T)r&   r>   z()()F*   )stop)stepasciir1   )7r	   ro   boolr   r   rt   r   rw   rZ   r   r   rA   r"   rT   r[   r7   r5   r.   r   r   r$   rI   r   rS   r)   r(   r9   r2   r   r@   rV   r3   r<   r=   rX   rU   rW   rE   r*   r   r!   rJ   rK   rM   rP   rN   rR   rQ   rO   rL   rH   rY   r0   	maketransrB   )rx   Z	empty_strrk   Z	empty_intZ
empty_boolZempty_bytestabler   r   r   test_empty_str_methodsG  sv    


 z(TestStringMethods.test_empty_str_methodsc             C   s<   t td}t }tj||jjd tj||jjd d S )N)rl   r   )r	   rt   r   r   r   r3   r<   )rx   rk   Zempty_dfr   r   r   test_empty_str_methods_to_frame  s    
z1TestStringMethods.test_empty_str_methods_to_framec          
   C   sl  ddddddddd	d
g
}t |}ddddddddddg
}ddddddddddg
}ddddddddddg
}ddddddddddg
}ddddddddddg
}ddddddddddg
}ddddddddddg
}	ddddddddddg
}
tj|jj t | tj|jj t | tj|jj t | tj|jj t | tj|jj t | tj|jj	 t |	 tj|jj
 t |
 |jj j dd |D kst|jj j dd |D kst|jj j dd |D kst|jj j dd |D kst|jj j dd |D ks$t|jj	 j dd |D ksFt|jj
 j dd |D kshtd S )Nr   rz   ZXyr  Z3Ar,   ZTTZ55r   z  TFc             S   s   g | ]}|j  qS r   )rJ   )r^   r  r   r   r   r     s    z4TestStringMethods.test_ismethods.<locals>.<listcomp>c             S   s   g | ]}|j  qS r   )rK   )r^   r  r   r   r   r     s    c             S   s   g | ]}|j  qS r   )rM   )r^   r  r   r   r   r     s    c             S   s   g | ]}|j  qS r   )rP   )r^   r  r   r   r   r     s    c             S   s   g | ]}|j  qS r   )rN   )r^   r  r   r   r   r     s    c             S   s   g | ]}|j  qS r   )rR   )r^   r  r   r   r   r     s    c             S   s   g | ]}|j  qS r   )rQ   )r^   r  r   r   r   r     s    )r	   r   r   rt   rJ   rK   rM   rP   rN   rR   rQ   r  rw   )rx   rq   Zstr_sZalnum_eZalpha_eZdigit_eZnum_eZspace_eZlower_eZupper_eZtitle_er   r   r   test_ismethods  sB    """"""z TestStringMethods.test_ismethodsc             C   s6  dddddddg}t |}dd	d	dd	d	dg}dd	dddd	dg}tj|jj t | tj|jj t | dddddddg}|jj j d
d |D kst|jj j dd |D kstdtj	ddtj	ddg}t |}dtj	d	dtj	d	dg}dtj	ddtj	d	dg}tj|jj t | tj|jj t | d S )Nr   r      ¼u   ★u   ፸u   ３ZfourFTc             S   s   g | ]}|j  qS r   )rO   )r^   r  r   r   r   r     s    z4TestStringMethods.test_isnumeric.<locals>.<listcomp>c             S   s   g | ]}|j  qS r   )rL   )r^   r  r   r   r   r     s    )
r	   r   r   rt   rO   rL   r  rw   rm   r   )rx   rq   r   Z	numeric_eZ	decimal_eZunicodesr   r   r   test_isnumeric  s      z TestStringMethods.test_isnumericc             C   s   t ddtjg}|jjd}tdddgdddgdddggtdd}tj|| t dd	d
g}|jjd}tdddgdddgdddggtdd}tj|| t	dddg}|jjd}t
jdddgdd}tj|| d S )Nza|bza|cr   r>   r   r*  )rG  za;br      ;Z7abzb|crz   rg   )r   )r>   r>   r   )r>   r   r>   )r   r>   r>   )r   rz   rg   )r	   rm   r   rt   rI   r   r   r   r   r   r   rv  r   )rx   r   r   r   rW  r   r   r   test_get_dummies  s    ((z"TestStringMethods.test_get_dummiesc             C   s   t dddg}|jjd}tdddgdddgdddggdddgd}tj|| td	d
dg}|jjd}tjdddgdd}tj	|| d S )Nr   zb,namerz   r   r>   r   r   )rG  za|bzname|czb|namer   rg   )r   )r>   r>   r   r   )r   r   r>   r>   )r   r>   r   r>   )r   rz   rg   r   )
r	   rt   rI   r   r   r   r   r   rv  r   )rx   r   r   r   rW  r   r   r    test_get_dummies_with_name_dummy  s    (z2TestStringMethods.test_get_dummies_with_name_dummyc          
   C   s   t ddtjdg}|jjdjjd}tj|| t dtjddtj	 dd d	d
g	}t |jjdjjd}t dtjdtjtjdtjtjtjg	}t
|t sttj|| d S )Na_b_cc_d_ef_g_hr]   a_basdf_cas_asdfTr   r>   g       @)r	   rm   r   rt   r@   r   r   r   r   r   r   rw   r  )rx   rq   r   r   r   r   r   r   r   	test_join  s4    
zTestStringMethods.test_joinc          
   C   s   t dddtjdg}|jj }|jdd }tj|| t dtjdd	tj	 dd d
dg	}t |jj }t dtjdtjtjdtjtjtjg	}t
|t sttj|| d S )Nr   ZfoooZfoooooZfoooooooc             S   s   t | rt| S tjS )N)r   rS   rm   r   )r   r   r   r   r   $  s    z,TestStringMethods.test_len.<locals>.<lambda>r  r  Tr>   g       @r6      )r	   rm   r   rt   rS   mapr   r   r   r   r   rw   r  )rx   rq   r   r   r   r   r   r   r   r   test_len   s$    
&zTestStringMethods.test_lenc          
   C   s   t dtjddg}|jjd}t ddgtjg dgg}tj|| t dtjddtj dd ddg	}t |jjd}t ddgtjg tjtjdgtjtjtjg	}t	|t st
tj|| d S )	Nr  r   r<  zBAD[_]*r;  Tr>   g       @)r	   rm   r   rt   r)   r   r  r   r   r   rw   )rx   rq   r   r   r   r   r   r   r   r   test_findall<  s6    
zTestStringMethods.test_findallc             C   sN  t dddddg}|jjd}tj|t ddd	d
dg tjdd |jD tjd}tj	|j| |jj
d}tj|t dddddg tjdd |jD tjd}tj	|j| |jjdd}tj|t dddddg tjdd |jD tjd}tj	|j| |jj
dd}tj|t dddddg tjdd |jD tjd}tj	|j| |jjddd}tj|t dddddg tjdd |jD tjd}tj	|j| |jj
ddd}tj|t dddddg tjdd |jD tjd}tj	|j| tjtdd |jjd
}W d Q R X tjtdd |jj
d
}W d Q R X d S ) NABCDEFGBCDEFEF	DEFGHIJEFEFGHEFXXXXEFr   r6   r>   r   c             S   s   g | ]}|j d qS )r  )r(   )r^   r  r   r   r   r   h  s    z/TestStringMethods.test_find.<locals>.<listcomp>)rl   r-  r  c             S   s   g | ]}|j d qS )r  )r9   )r^   r  r   r   r   r   m  s    c             S   s   g | ]}|j d dqS )r  r6   )r(   )r^   r  r   r   r   r   r  s    c             S   s   g | ]}|j d dqS )r  r6   )r9   )r^   r  r   r   r   r   w  s    r.  c             S   s   g | ]}|j d ddqS )r  r6   r.  )r(   )r^   r  r   r   r   r   |  s    c             S   s   g | ]}|j d ddqS )r  r6   r.  )r9   )r^   r  r   r   r   r     s    z!expected a string object, not int)r.   r  r  r  r  r  r  r  )r	   rt   r(   r   r   rm   rn   rq   r  r   r9   r{   r|   r   )rx   rq   r   r   r   r   r   	test_findd  s<    zTestStringMethods.test_findc             C   s"  t dtjdtjdg}|jjd}tj|t dtjdtjd
g |jjd}tj|t dtjdtjdg |jjdd}tj|t dtjdtjdg |jjdd}tj|t dtjdtjdg |jjddd	}tj|t dtjdtjdg |jjddd	}tj|t dtjdtjdg d S )Nr  r  r  r  r   r>   r  r6   r.  r  r  r  r  r  r  r  r  )r	   rm   r   rt   r(   r   r   r9   )rx   rq   r   r   r   r   test_find_nan  s    zTestStringMethods.test_find_nanc             C   s  dd }xFt tgD ]8}|ddddg}|jjd}|||dd	d
dg tjdd |jD tjd}tj	|j| |jj
d}|||ddddg tjdd |jD tjd}tj	|j| |jjdd	}|||dd	ddg tjdd |jD tjd}tj	|j| |jj
dd	}|||ddddg tjdd |jD tjd}tj	|j| |jjddd}|||ddddg tjdd |jD tjd}tj	|j| |jj
ddd}|||dd	d
dg tjdd |jD tjd}tj	|j| tjtdd |jjd}W d Q R X d}tjt|d |jjd}W d Q R X qW t dddtjg}|jjd}tj|t d
d
dtjg |jj
d}tj|t d	d
d tjg d S )!Nc             S   s(   t | trtj| | ntj| | d S )N)r   r	   r   r   r   )r   r   r   r   r   _check  s    
z,TestStringMethods.test_index.<locals>._checkr  r  r  r  r  r   r6   r>   r   c             S   s   g | ]}|j d qS )r  )r+   )r^   r  r   r   r   r     s    z0TestStringMethods.test_index.<locals>.<listcomp>)rl   r-  r  c             S   s   g | ]}|j d qS )r  )r:   )r^   r  r   r   r   r     s    c             S   s   g | ]}|j d dqS )r  r6   )r+   )r^   r  r   r   r   r     s    c             S   s   g | ]}|j d dqS )r  r6   )r:   )r^   r  r   r   r   r     s    r      c             S   s   g | ]}|j d ddqS )r   r   r  )r+   )r^   r  r   r   r   r     s    c             S   s   g | ]}|j d ddqS )r   r   r-  )r:   )r^   r  r   r   r   r     s    zsubstring not found)r.   ZDEz!expected a string object, not intZabcbr   Zbcberz   rF   )r	   r   rt   r+   rm   rn   rq   r  r   r   r:   r{   r|   r   r   r   r   )rx   r  r  r   r   r   r   r   r   r   
test_index  sJ    zTestStringMethods.test_indexc          
   C   s  t ddtjdtjdg}|jjddd}t dd	tjd
tjdg}tj|| |jjddd}t ddtjdtjdg}tj|| |jjddd}t ddtjdtjdg}tj|| t dtjddtj dd ddg	}t |jjddd}t dtjd	tjtjdtjtjtjg	}t	|t st
tj|| t dtjddtj dd ddg	}t |jjddd}t dtjdtjtjdtjtjtjg	}t	|t st
tj|| t dtjddtj dd ddg	}t |jjddd}t dtjdtjtjdtjtjtjg	}t	|t s
t
tj|| d S )Nr   rz   rg   eeeeeer-  r   )sidez    az    bz    cr   za    zb    zc    bothz  a  z  b  z  c  Teer>   g       @z   eezee   z  ee )r	   rm   r   rt   r2   r   r  r   r   r   rw   )rx   rq   r   r   r   r   r   r   r   r   test_pad  s8     $ $ $zTestStringMethods.test_padc             C   s  t ddtjdtjdg}|jjdddd}t d	d
tjdtjdg}tj|| |jjdddd}t ddtjdtjdg}tj|| |jjdddd}t ddtjdtjdg}tj|| d}tjt	|d |jjddd}W d Q R X d}tjt	|d |jjddd}W d Q R X d S )Nr   rz   rg   r  r-  r   X)r  fillcharXXXXaZXXXXbZXXXXcr   aXXXXZbXXXXZcXXXXr  XXaXXZXXbXXZXXcXXz%fillchar must be a character, not str)r.   XY)r  z%fillchar must be a character, not int)
r	   rm   r   rt   r2   r   r  r{   r|   r   )rx   rq   r   r   r   r   r   r   test_pad_fillchar	  s     z#TestStringMethods.test_pad_fillcharr_   r   r-   r;   rG   r2   c          
   C   sB   t ddddg}d}tjt|d t|j|d W d Q R X d S )Nr   22r   r   z#width must be of integer type, not*)r.   r_   )r	   r{   r|   r   r   rt   )rx   r_   r   r   r   r   r   test_pad_width	  s    z TestStringMethods.test_pad_widthc             C   s   dd }xRt tgD ]F}|ddddg}tjdd}|jj|}|d	d
ddg}||| qW t ddddg}t dddtjg}|jj|}tj|| d S )Nc             S   s(   t | trtj| | ntj| | d S )N)r   r	   r   r   r   )r   r   r   r   r   r  &	  s    
z0TestStringMethods.test_translate.<locals>._checkZabcdefgZabccZcdddfgZcdefgggr*  cdeZcdedefgZcdeeZedddfgZedefgggr   rz   rg   g333333?r   r   )	r	   r   rt   r  rB   rm   r   r   r   )rx   r  r  r   r  r   r   r   r   r   test_translate%	  s    z TestStringMethods.test_translatec             C   s  t ddtjdtjdg}|jjd}t ddtjdtjdg}tj|| |jjd}t d	d
tjdtjdg}tj|| |jjd}t ddtjdtjdg}tj|| t dtjddt	j
 ddd ddg
}t |jjd}t dtjdtjtjddtjtjtjg
}t|t sttj|| t |jjd}t d	tjd
tjtjddtjtjtjg
}t|t sfttj|| t |jjd}t dtjdtjtjddtjtjtjg
}t|t sttj|| d S )Nr   rz   rg   r  r-  z  a  z  b  z  c  za    zb    zc    z    az    bz    cTZeeer>   g       @z eee zeee  z  eee)r	   rm   r   rt   r   r   r  r-   r;   r   r   r   rw   )rx   rq   r   r   r   r   r   r   r   r   test_center_ljust_rjust9	  sl     


z)TestStringMethods.test_center_ljust_rjustc          .   C   sN  t dddddg}|jjddd}t d	d
dddg}tj|| tjdd |jD tjd}tj	|j| |jj
ddd}t dddddg}tj|| tjdd |jD tjd}tj	|j| |jjddd}t dddddg}tj|| tjdd |jD tjd}tj	|j| d}tjt|jddd |jjddd W d Q R X tjt|jddd |jj
ddd W d Q R X tjt|jddd |jjddd W d Q R X tjt|jddd |jjddd W d Q R X tjt|jddd |jj
ddd W d Q R X tjt|jddd |jjddd W d Q R X d S )Nr   r   r/  Zdddddr  r-  r  )r  r  ZXXbbXZXccccc             S   s   g | ]}|j d dqS )r-  r  )r   )r^   r  r   r   r   r   	  s    zFTestStringMethods.test_center_ljust_rjust_fillchar.<locals>.<listcomp>)rl   r  ZbbXXXZccccXc             S   s   g | ]}|j d dqS )r-  r  )r-   )r^   r  r   r   r   r   	  s    r  ZXXXbbc             S   s   g | ]}|j d dqS )r-  r  )r;   )r^   r  r   r   r   r   	  s    z)fillchar must be a character, not {dtype}rt   )r.   r  intr>   )r	   rt   r   r   r   rm   rn   rq   r   r   r-   r;   r{   r|   r   format)rx   rq   r   r   templater   r   r    test_center_ljust_rjust_fillchar	  s:    z2TestStringMethods.test_center_ljust_rjust_fillcharc             C   s  t dddddg}|jjd}t ddd	d
dg}tj|| tjdd |jD tjd}tj	|j| |jjd}t dddddg}tj|| tjdd |jD tjd}tj	|j| t dtj
dtj
dg}|jjd}t dtj
d	tj
dg}tj|| d S )Nr   r  r   Z333Z45678r-  Z00001Z00022Z00aaaZ00333c             S   s   g | ]}|j d qS )r-  )rG   )r^   r  r   r   r   r   	  s    z0TestStringMethods.test_zfill.<locals>.<listcomp>)rl   r6   Z001Z022c             S   s   g | ]}|j d qS )r6   )rG   )r^   r  r   r   r   r   	  s    )r	   rt   rG   r   r   rm   rn   rq   r   r   r   )rx   rq   r   r   r   r   r   
test_zfill	  s    zTestStringMethods.test_zfillc          	   C   s  t ddtjdg}|jjd}t dddgddd	gtjd
ddgg}tj|| t ddtjdg}|jjd}tj|| |jjddd}tj|| t dtjddtj d ddg}|jjd}t dddgtjdd	d
gtjtjtjtjtjg}t	|t st
tj|| |jjddd}t	|t s(t
tj|| t ddtjdg}|jjd}t dddgddd	gtjd
ddgg}tj|| d S )Nr  r  r  r]   r   rz   rg   r   r   r_   gr   a__b__cc__d__ef__g__h__F)r&   d_e_fTr>   g       @za,b_czc_d,ezf,g,hz[,_])r	   rm   r   rt   r@   r   r   r   r   r   rw   r  )rx   rq   r   r   r   r   r   r   
test_split	  s:    $
$zTestStringMethods.test_splitc          	   C   s  t ddtjdg}|jjd}t dddgddd	gtjd
ddgg}tj|| t ddtjdg}|jjd}tj|| |jjddd}tj|| t dtjddtj d ddg}|jjd}t dddgtjdd	d
gtjtjtjtjtjg}t	|t st
tj|| |jjddd}t	|t s(t
tj|| t ddtjdg}|jjd}t dgdgtjdgg}tj|| t ddtjdg}|jjddd}t ddgdd	gtjddgg}tj|| d S )Nr  r  r  r]   r   rz   rg   r   r   r_   r  r   r  r  r  r  F)r&   r  Tr>   g       @za,b_czc_d,ezf,g,hz[,_])r  r  c_df_g)r	   rm   r   rt   rV   r   r   r   r   r   rw   r  )rx   rq   r   r   r   r   r   r   test_rsplit	  sB    $
zTestStringMethods.test_rsplitc             C   s   t dgdd}|jjdd}tg g}tj|| t ddddgdd}|jjdd}td	d
dgd	d
tjgtjtjtjgtjtjtjgg}tj|| d S )Nr,   test)r   T)r&   za b cza br4   r   rz   rg   )r	   rt   r@   r   r   r   rm   r   )rx   rq   r   r   r   r   r   test_split_blank_string
  s    

z)TestStringMethods.test_split_blank_stringc             C   sL   t ddg}|jj }ddg}|d |ks.t|jj }|d |ksHtd S )NzWes McKinneyzTravis  OliphantZTravisZOliphantr>   )r	   rt   r@   rw   rV   )rx   r   r   r   r   r   r   test_split_noargs1
  s    

z#TestStringMethods.test_split_noargsc             C   s   t ddg}|jjdd}|jj }tj|| |jjdd}tj|| |jjd}|jjddd}tj|| |jjddd}tj|| d S )	Nzbd asdf jfgzkjasdflqw asdfnfkr>   )r  r   Zasdfr  r  )r	   rt   r@   r   r   )rx   r   r   r   r   r   r   test_split_maxsplit:
  s    
z%TestStringMethods.test_split_maxsplitc             C   sD   t ddg}|jjdd}t ddgddgd}tj||d	d
 d S )Nz
split oncezsplit once too!r>   )r  r@   oncez	once too!)r   r>   F)Zcheck_index_type)r	   rt   r@   r   r   )rx   r   r   r   r   r   r    test_split_no_pat_with_nonzero_nL
  s    z2TestStringMethods.test_split_no_pat_with_nonzero_nc             C   sX  t ddg}|jjddd}tdt ddgi}tj|| t ddg}|jjddd}td	d
gddgddgd}tj|| t ddg}|jjddd}td	dgddgddgtjdgtjdgtjdgd}tj|| t ddgddgd}|jjddd}td	d
gddgd ddgd}tj|| tj	t
d!d" |jjdd#d W d Q R X d S )$Nnosplitalsonosplitr]   T)r&   r   some_equal_splitswith_no_nanssomewithequalnosplitsnans)r   r>   rF   some_unequal_splitsone_of_these_things_is_notoneunequalofthesethingsisnot)r   r>   rF   r6   r   r-  some_splits
with_indexpreserveme)r+   r+   )r   r>   zexpand must be)r.   not_a_boolean)r	   rt   r@   r   r   r   rm   r   r{   r|   r   )rx   r   r   r   r   r   r   test_split_to_dataframeR
  s4    z)TestStringMethods.test_split_to_dataframec             C   sF  t ddtjg}|jjddd}|}tj|| |jdks>tt ddtjd g}|jjddd}t	j
ddtjtjtjgd d d gg}tj|| |jdkstt ddtjd g}|jjddd}t	j
d	ddtjtjtjfdtjtjtjtjtjtjfd g}tj|| |jdksttjtdd |jjddd W d Q R X d S )!Nr  r  r]   T)r&   r>   r  r  r  r  r  r  r  r  r6   r  r  r  r  r  r  r  r  r  r.  zexpand must be)r.   r  )r  r  r  )r  r  r  )r  r  r  r  r  r  )NNNNNN)r   rm   r   rt   r@   r   r   nlevelsrw   r   rv  r{   r|   r   )rx   rW  r   r   r   r   r   test_split_to_multiindex_expandw
  s2    z1TestStringMethods.test_split_to_multiindex_expandc             C   s@  t ddg}|jjddd}tdt ddgi}tj|| t ddg}|jjddd}td	d
gddgddgd}tj|| |jjdddd}td	d
gddgddgd}tj|| |jjdddd}tddgddgd}tj|| t ddgddgd}|jjddd}td	d
gddgdddgd}tj|| d S )Nr  r  r]   T)r&   r   r  r  r  r  r  r  r  r  )r   r>   rF   rF   )r&   r  r>   
some_equalwith_no)r   r>   r  r   r  r  )r+   r+   )r	   rt   rV   r   r   r   )rx   r   r   r   r   r   r   test_rsplit_to_dataframe_expand
  s*    z1TestStringMethods.test_rsplit_to_dataframe_expandc             C   s   t ddg}|jjddd}|}tj|| |jdks:tt ddg}|jjddd}tjddg}tj|| |jdks~tt ddg}|jjdddd}tjddg}tj|| |jdkstd S )Nr  r  r]   T)r&   r>   r  r  r  r  r  r  r  r  r6   )r&   r  r  r  rF   )r  r  r  )r  r  r  )r  r  )r  r  )	r   rt   rV   r   r   r  rw   r   rv  )rx   rW  r   r   r   r   r    test_rsplit_to_multiindex_expand
  s     
z2TestStringMethods.test_rsplit_to_multiindex_expandc             C   sh   t dtjg}|jjddd}tdddgtjtjtjgg}tj|| tdd	 |j	d
 D sdt
d S )Nzfoo,bar,bazr   T)r&   r   r	  bazc             s   s   | ]}t j|V  qd S )N)rm   isnan)r^   r   r   r   r   r  
  s    z:TestStringMethods.test_split_nan_expand.<locals>.<genexpr>r>   )r	   rm   r   rt   r@   r   r   r   allilocrw   )rx   r   r   r   r   r   r   test_split_nan_expand
  s
    z'TestStringMethods.test_split_nan_expandc             C   s   t ddgdd}|jjd}t ddgdd	ggdd}tj|| |jjdd
d}tddgdd	gg}tj|| tddgdd}|jjd}tddgdd	ggdd}|jdkst	tj
|| |jjdd
d}tjddg}|jdkst	tj
|| d S )Nza,bzc,dr  )r   r   r   rz   rg   r   T)r&   r>   rF   )r   rz   )rg   r   )r	   rt   r@   r   r   r   r   r   r  rw   r   r   rv  )rx   r   r5  r   rW  r   r   r   test_split_with_name
  s     z&TestStringMethods.test_split_with_namec             C   s  t ddtjdd g}|jjddd}t d1d2tjd3d g}tj|| |jjddd}t d4d5tjd6d g}tj|| t ddtjdd g}|jjddd}t d7d8tjd9d g}tj|| |jjddd}t d:d;tjd<d g}tj|| t ddtjdd g}|jjdd}t d=d>tjd?d g}tj|| |jjdd}t d@dAtjdBd g}tj|| t d&d'tjd(d g}|jjddd}t dCdDtjdEd g}tj|| |jjddd}t dFdGtjdHd g}tj|| t ddtjdg}|jjddd}t dIdJtjdKg}tj|| |jjddd}t dLdMtjdNg}tj|| t d*d+d,d-g}|jjdddj }|d.d/ |D ksvt	|jjdddj }|d0d/ |D kst	d S )ONr  r  r  r]   F)r&   r   b_crg   d_er_   g_hr  r  r   r  r   r  r  r  r  b__cd__eg__ha__bc__df__gza b czc d ezf g hr4   b cd eg ha bc df gr*  r  fghr,   ZA_B_CZB_C_DZE_F_Gr  c             S   s   g | ]}|j d qS )r]   )r3   )r^   r  r   r   r   r   E  s    z;TestStringMethods.test_partition_series.<locals>.<listcomp>c             S   s   g | ]}|j d qS )r]   )r<   )r^   r  r   r   r   r   G  s    )r   r]   r  )rg   r]   r  )r_   r]   r  )r  r]   rg   )r  r]   r   )r  r]   r   )r   r  r  )rg   r  r  )r_   r  r  )r  r  rg   )r  r  r   )r  r  r   )r   r4   r  )rg   r4   r  )r_   r4   r  )r  r4   rg   )r  r4   r   )r  r4   r   )r*  r,   r,   )r  r,   r,   )r   r,   r,   )r,   r,   r*  )r,   r,   r  )r,   r,   r   )r   r]   r  )rg   r]   r  )r_   r]   r  )r  r]   rg   )r  r]   r   )r  r]   r   )
r	   rm   r   rt   r3   r   r   r<   r  rw   )rx   rq   r   r   r   r   r   test_partition_series
  sl    z'TestStringMethods.test_partition_seriesc             C   sT  t dddtjd g}|jjddd}t tjdddtjd gtd}tj|| |j	dks\t
|jjddd}t tjdddtjd gtd}tj|| |j	dkst
|jjd}t dddtjtjtjfdg}tj|| t|t st
|j	dk st
|jjd}t dd d!tjtjtjfd"g}tj|| t|ts@t
|j	dksPt
d S )#Nr  r  r  r]   F)r&   r   r  rg   r  r_   r  )rl   r>   r  r  r   r  r   r6   )r   r]   r  )rg   r]   r  )r_   r]   r  )r  r]   rg   )r  r]   r   )r  r]   r   )r   r]   r  )rg   r]   r  )r_   r]   r  )NNN)r  r]   rg   )r  r]   r   )r  r]   r   )NNN)r   rm   r   rt   r3   rn   ro   r   r   r  rw   r<   r   r   )rx   rq   r   r   r   r   r   test_partition_indexI  sF    

z&TestStringMethods.test_partition_indexc             C   sd  t ddtjdd g}|jjd}tddtjdd gddtjdd gdd	tjd
d gd}tj|| |jjd}tddtjdd gddtjdd gddtjdd gd}tj|| t ddtjdd g}|jjddd}tddtjdd gddtjdd gdd	tjd
d gd}tj|| |jjddd}tddtjdd gddtjdd gddtjdd gd}tj|| d S )Nr  r  r  r]   r   rg   r_   r  r  r  )r   r>   rF   r  r  r  r   r   T)r&   )	r	   rm   r   rt   r3   r   r   r   r<   )rx   rq   r   r   r   r   r   test_partition_to_dataframe~  s4    z-TestStringMethods.test_partition_to_dataframec             C   s   t ddgdd}|jjd}tddgddgdd	gd
}tj|| |jjddd}t ddgdd}tj|| tddgdd}|jjd}tj	ddg}|j
dksttj|| |jjddd}ttjddgdd}|j
dk sttj|| d S )Nza,bzc,dr  )r   r   r   rg   rz   r   )r   r>   rF   F)r&   r6   r>   )r   r   rz   )rg   r   r   )r   r   rz   )rg   r   r   )r   r   rz   )rg   r   r   )r	   rt   r3   r   r   r   r   r   r   rv  r  rw   r   rm   rn   )rx   r   r5  r   rW  r   r   r   test_partition_with_name  s     z*TestStringMethods.test_partition_with_namec             C   sb   t ddtjdg}|jjdd}|jjd}tj|| |jjdd}|jjd}tj|| d S )Nr  r  r  r]   )r   )r	   rm   r   rt   r3   r   r   r<   )rx   rq   r   r   r   r   r   test_partition_sep_kwarg  s    z*TestStringMethods.test_partition_sep_kwargc             C   sZ   t dg}|jjd}t dddgg}tj|| |jjdd}t dg}tj|| d S )NzA|B|Cr   r   r   r   r4   zA B C)r	   rt   r@   r   r   r7   )rx   r   r   r   r   r   r   test_pipe_failures  s    

z$TestStringMethods.test_pipe_failureszstart, stop, step, expectedr-  r   r	  r  r   ZowtoofaaZowtrabaaZxuqzabaar   ZotoZatoZaqxZofaabac       
   	   C   s   t ddtjdg}|jj|||}tj|| t dtjddtj d ddg}t |jjdd}t d	tjd
tjtjtjtjtjg}	t	|t st
tj||	 t |jjddd}t dtjdtjtjtjtjtjg}	d S )NZaafootwoZaabartwoZaabazquxTr>   g       @rF   r-  r   r	  ZoofZrabr  )r	   rm   r   rt   r=   r   r   r   r   r   rw   r  )
rx   startr  r  r   rq   r   r   r   r   r   r   r   
test_slice  s    $zTestStringMethods.test_slicec             C   s  t ddddtjg}t ddddtjg}|jjdd	}tj|| t d
dddtjg}|jjdd	d}tj|| t ddddtjg}|jjddd}tj|| t ddddtjg}|jjddd}tj|| t ddddtjg}|jjdd d}tj|| t ddddtjg}|jjd d d}tj|| t ddddtjg}|jjddd}tj|| t ddddtjg}|jjd!d	d}tj|| d S )"Nshortza bit longerZevenlongerthanthatr,   Zshrtza it longerZevnlongerthanthatrF   r6   Zshzrtza zit longerZevznlongerthanthatr8   Zshzortza zbit longerZevzenlongerthanthatr>   Zshorzza bit longezZevenlongerthanthazZzrtZzerZzatZshortzza bit zngerZevenlozerthanthatr.  r  Zevenlongzerthanthatr   r  i)r	   rm   r   rt   r?   r   r   )rx   rq   r   r   r   r   r   test_slice_replace  s2    z$TestStringMethods.test_slice_replacec             C   s   t ddtjdg}|jj }t ddtjdg}tj|| |jj }t ddtjdg}tj|| |jj }t d	d
tjdg}tj|| d S )Nz  aa   z bb 
zcc  r   r   cczaa   zbb 
z  aaz bb)	r	   rm   r   rt   rX   r   r   rU   rW   )rx   rq   r   r   r   r   r   test_strip_lstrip_rstrip  s    


z*TestStringMethods.test_strip_lstrip_rstripc          	   C   s  t dtjddtj d ddg}t |jj }t dtjdtjtjtjtjtjg}t|t s^tt	j
|| t |jj }t dtjd	tjtjtjtjtjg}t|t stt	j
|| t |jj }t d
tjdtjtjtjtjtjg}t|t stt	j
|| d S )Nz  aa  z bb 	
Tr>   g       @r   r   zaa  zbb 	
z  aaz bb)r	   rm   r   r   r   rt   rX   r   rw   r   r  rU   rW   )rx   r   r   r   r   r   r   test_strip_lstrip_rstrip_mixed-  s    $$$z0TestStringMethods.test_strip_lstrip_rstrip_mixedc             C   s   t dddg}|jjd}t dddg}tj|| |jjd}t dddg}tj|| |jjd}t d	ddg}tj|| d S )
NZxxABCxxzxx BNSDzLDFJH xxr   ABCz BNSDzLDFJH ZABCxxZxxABC)r	   rt   rX   r   r   rU   rW   )rx   rq   r   r   r   r   r   test_strip_lstrip_rstrip_argsE  s    z/TestStringMethods.test_strip_lstrip_rstrip_argsc          
   C   s   t ddddddddd	g	}t ddd
ddddddg	}|jjddd}tj|| t dtjdg}t dtjdg}|jjd}tj|| d S )Nzhello worldzhello world!zhello world!!ZabcdefabcdeZabcdefabcdefZabcdefabcdefazab ab ab ab zab ab ab ab a	zhello
world!!zabcdefabcdef
azab ab ab abzab ab ab ab
ar,      T)break_long_wordsz  pre  u   ¬€耀 abadcafez  preu   ¬€耀 ab
adcafer.  )r	   rt   rE   r   r   rm   r   )rx   rq   r   r   r   r   r   	test_wrapT  s4    zTestStringMethods.test_wrapc          	   C   s*  t ddtjdg}|jjdjjd}t ddtjdg}tj|| t dtjdd	tj	 d dd
g}t |jjdjjd}t dtjdtjtjtjtjtjg}t
|t sttj|| t dddg}|jjdjjd}t ddtjg}tj|| |jjdjjd}t ddtjg}tj|| d S )Nr  r  r  r]   r>   rz   r   r  Tg       @Z	1_2_3_4_5Z
6_7_8_9_10Z11_12rF   r   8r6   )r	   rm   r   rt   r@   r*   r   r   r   r   r   rw   r  )rx   rq   r   r   r   r   r   r   r   r   test_get  s     $zTestStringMethods.test_getc             C   s~   t ddddgdddhddddg}|jjd}t ddtjdg}tj|| |jjd	}t ddtjtjg}tj|| d S )
Nr>   rF   r6   r   rz   rg   )r>   rF   r6   )r>   rF   r6   r  )r	   rt   r*   rm   r   r   r   )rx   rq   r   r   r   r   r   test_get_complex  s    $z"TestStringMethods.test_get_complexto_typec             C   sj   t ||ddggg}|jjd}t |ddgg}tj|| |jjd}t tjg}tj|| d S )Nr>   rF   r   )r	   rt   r*   r   r   rm   r   )rx   r:  rq   r   r   r   r   r   test_get_complex_nested  s    z)TestStringMethods.test_get_complex_nestedc             C   s8  t ddddddtjddd	g
}|jjd
}t ddddddtjdddg
}tj|| |jjd
dd}t ddddddtjdddg
}tj|| |jjd}t ddddddtjdddg
}tj|| |jjd}t ddddddtjdddg
}tj|| |jjddd}t ddddddtjdddg
}tj|| d S )Nr   r   r   AabaBacar,   CABAdogr   r   FT)r   ZAar)  )r	   rm   r   rt   r   r   r   )rx   r   r   r   r   r   r   test_contains_moar  s*    z$TestStringMethods.test_contains_moarc             C   s   t tjtjtjgtjd}|jjddd}t dddgtjd}tj|| |jjddd}t dddgtjd}tj|| |jjddd}t dddgtjd}tj|| |jjd}t tjtjtjgtjd}tj|| d S )N)rl   r   F)r#   T)	r	   rm   r   r   rt   r   r   r   r   )rx   r   r   r   r   r   r   test_contains_nan  s    z#TestStringMethods.test_contains_nanc             C   s   t ddddddtjddd	g
}|jjdd
}t d
dddddtjddd	g
}tj|| |jjdd
dd}t d
dddddtjdddg
}tj|| |jjdddd}t ddddddtjdddg
}tj|| d S )Nr   r   r   r<  r=  r,   r>  r?  r   YYYZYYYabaCYYYBYYYF)r   
YYYYYYbYYYBYYYcYYYcYYYtz^.a|dogzXX-XX zXX-XX bazXX-XX cazXX-XX BAzXX-XX t)r	   rm   r   rt   r7   r   r   )rx   r   r   r   r   r   r   test_replace_moar  s>    z#TestStringMethods.test_replace_moarc          
   C   s   t dddddtjdddg	}|jd	 }|jjd	}tj|| |jd d
 }|jjd
d}tj|| |jdd d }|jjddd}tj|| d S )NrB  r   r   rD  rE  rC  r?  rF  r   r6   )r  rF   r>   )r(  r  r  r  )r	   rm   r   rt   r*   r   r   r=   )rx   r   r   r   r   r   r   test_string_slice_get_syntax  s&    
z.TestStringMethods.test_string_slice_get_syntaxc             C   sl   t dddg}|jd }t dtjdg}tj|| t dddg}|jd }t d	tjd
g}tj|| d S )Nr>   rF   r6   r   r-  r   rz   r)  r   r   )r>   rF   )r>   )r6   r   r-  )r	   rt   rm   r   r   r   )rx   r   r   r   r   r   r   test_string_slice_out_of_bounds2  s    

z1TestStringMethods.test_string_slice_out_of_boundsc             C   s
  dddt jd}t|}d}|jj|tjdd}|jd j d	d
dgksLt	|jj
|tjd}|d sjt	|jj|tjd}|d st	|jj|tjd}|d d dkst	|jj|tjd}|d dkst	tjt |jj|tjd}W d Q R X |d st	d S )Nzdave@google.comzsteve@gmail.comzrob@gmail.com)rl  ZSteveZRobZWesz,([A-Z0-9._%+-]+)@([A-Z0-9.-]+)\.([A-Z]{2,4})T)r  r&   r   ra  r   rb  )r  r>   )ra  r   rb  )rm   r   r	   rt   r$   r  r'  r  r  rw   r.   r/   r)   r   r   r   UserWarningr   )rx   r   r   r   r   r   r   test_match_findall_flags?  s&    
z*TestStringMethods.test_match_findall_flagsc             C   sH   t dddg}|jjd}dd }|jjd}|j|}tj|| d S )Nr   rz   u   aäzutf-8c             S   s
   | j dS )Nzutf-8)r   )r   r   r   r   r   a  s    z6TestStringMethods.test_encode_decode.<locals>.<lambda>)r	   rt   r!   r   r  r   r   )rx   baseZseriesr_   r   r   r   r   r   test_encode_decode]  s    
z$TestStringMethods.test_encode_decodec             C   s   t dddg}d}tjt|d |jjd W d Q R X dd }|jjdd	}|j|}tj|| t d
ddg}d}tjt	|d |jj
d W d Q R X dd }|jj
dd	}|j|}tj|| d S )Nr   rz   u   az['charmap' codec can't encode character '\\x9d' in position 1: character maps to <undefined>)r.   cp1252c             S   s   | j ddS )NrN  ignore)r!   )r   r   r   r   r   q  s    z=TestStringMethods.test_encode_decode_errors.<locals>.<lambda>rO  ri      bs   azS'charmap' codec can't decode byte 0x9d in position 1: character maps to <undefined>c             S   s   | j ddS )NrN  rO  )r   )r   r   r   r   r     s    )r	   r{   r|   UnicodeEncodeErrorrt   r!   r  r   r   UnicodeDecodeErrorr   )rx   Z
encodeBaser   r_   r   r   Z
decodeBaser   r   r   test_encode_decode_errorsg  s     

z+TestStringMethods.test_encode_decode_errorsc             C   s   dddt jdg}t|ddddd	gd
}dddt jdg}t|ddddd	gd
}|jjd}tj|| tdddt jdgddddd	gd
}|jjd}tj|| tjt	dd |jjd W d Q R X t
dddg}t
dddg}|jjd}tj|| d S )Nr0  u	   ＡＢＣu	   １２３u	   ｱｲｴr   rz   rg   r   r   )r+   Z123u	   アイエNFKCr1   zinvalid normalization form)r.   r  )rm   r   r	   rt   r0   r   r   r{   r|   r   r   r   )rx   rq   r   Znormedr   r   r   r   r   test_normalize  s      z TestStringMethods.test_normalizec             C   s  ddl m} ddgdfdddgdfdddgd	fddddgdfd
tdddgd	fg}xJ|D ]B\}}t|}tt|j|s|tt|j|st|j|ksXtqXW xJ|D ]B\}}t|}tt|j|stt|j|st|j|kstqW dt	j
gdftdddgdftdgdfg}xr|D ]j\}}t|}d}tjt|d t|j W d Q R X tjt|d |j W d Q R X |j|kstqW tjddg}|jd	kstd}tjt|d |j W d Q R X d S )Nr   )rv   r   rz   rf   r>   zmixed-integerg?r   r   i  ZfloatingZ
datetime64Ztimedelta64z-Can only use .str accessor with string values)r.   z5Can only use .str accessor with Index, not MultiIndex)r   rz   )r   rz   )pandas.core.stringsrv   r   r   r   r	   rt   rw   Zinferred_typerm   r   r   r{   r|   r}   r   rv  )rx   rv   Zcasesrq   tprW  r   r   r   r   "test_index_str_accessor_visibility  s@    
z4TestStringMethods.test_index_str_accessor_visibilityc          	   C   s2   t td}tjtdd d|j_W d Q R X d S )NZaabbcdez You cannot add any new attribute)r.   r   )r	   r   r{   r|   r}   rt   Zxlabel)rx   r   r   r   r   #test_str_accessor_no_new_attributes  s    z5TestStringMethods.test_str_accessor_no_new_attributesc          	   C   s^   t tjtddjt}t tjtddjt}tjtdd |j	j
| W d Q R X d S )Nr*  ZS1defz$Cannot use .str.cat with values of.*)r.   )r	   rm   rn   r   r   ro   r{   r|   r   rt   r   )rx   lhsrhsr   r   r   test_method_on_bytes  s    z&TestStringMethods.test_method_on_bytesc             C   s>   t dtjddg}t dtjddg}|jj }tj|| d S )Nssr   Zssd   ßu   ßd)r	   rm   r   rt   r\   r   r   )rx   r   r   r   r   r   r   test_casefold  s    
zTestStringMethods.test_casefold)N)r~  )Nr  )r~  r  )N)r~  r  )Nr  )r~  r  r  r  r  )__name__
__module____qualname__ry   r   r{   r   parametrizero   r   r   r   r   r   r   r   r	   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rm   r   pdr   r  r  r  r  r  r  r  r   r%  r(  r+  r0  r1  r6  r8  r9  r:  r[  r\  r^  r_  r`  rz  r|  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r
  r  r  r!  r"  r#  r$  r%  r&  r)  r,  r.  r/  r1  r5  r8  r9  r  rn   r;  r@  rA  rG  rH  rI  rK  rM  rS  rU  rX  rY  r]  r`  r   r   r   r   rs      s  B
(
%e+D##	$$5' -/04	f' F*&((6. 	J,+0	%&U5-(#
,$",
+rs   c       
      C   s  | \}}}|dkrt jd ddtjdg}t|td}t|dd}t|j|||}t|j|||}t|tr4|j	dkrt
j|j jr|j	dkst|jt}n|j	dkrt
j|jd	d
r|j	dkst|jt}nX|j	dkr|j	dkst|jd}n4|j	dkrx|j j rx|j	dks(t|jd}nDt|trx|jddj}	t||	 jdksft||	 jt||	< tj|| d S )Nr   zdecode requires bytes.r   r   r,  )rl   rf   ro   T)Zskipnar7  r  floatInt64)include)r{   skiprm   r   r	   ro   r   rt   r   rl   r   Zis_string_arrayr   rq   rw   r   Zis_bool_arrayr   anyr   Zselect_dtypesrG  r  dtypesr   assert_equal)
re   r   r   r   r   r   rz   r   r   rG  r   r   r   test_string_array  s8    


rm  zmethod,expectedc             C   s<   t dd gdd}t|j| d}t |dd}tj|| d S )Nr'  rf   )rl   r   rg  )r	   r   rt   r   r   )r   r   r   r   r   r   r   'test_string_array_numeric_integer_array  s    
rn  c             C   s<   t dd dgdd}t|j|  }t |dd}tj|| d S )Nr   r   rf   )rl   r7  )r	   r   rt   r   r   )r   r   r   r   r   r   r   test_string_array_boolean_array  s    
ro  c              C   st   t dddgdd} t dddgdd}d}| jj|dd	}|jj|dd	}t|jdksZt|jt}tj	|| d S )
NZa1Zb2r-  rf   )rl   ro   z(\w)(\d)F)r&   )
r	   rt   r$   r  rk  rw   r   ro   r   rl  )r   rz   r   r   r   r   r   r   test_string_array_extract&  s    
rp  r  c             C   sF   t jdddg}|jj| dddg}t jddd	g}tj|| d S )
Nr   rz   rg   r   r$  r8   ZaxZbycz)re  r	   rt   r   r   r   )r  r   r   r   r   r   r   test_cat_different_classes5  s    rr  )r   )r   )r   )r    )r    )r   )r   )r   )r%   )r%   )r%   )r   )r   )r   )r,   )r   )r   )r   )r   )r1   )r   )r4   )r4   )r6   )r   r8   )r   )r,   )r   )r4   )r4   )r   r>   )r   r>   r8   )r4   )r4   )r   )r   )r   )rF   )r   )3r   r   r  numpyrm   Znumpy.randomr   r{   Zpandas._libsr   Zpandasre  r   r   r   r	   r
   r   r   Zpandas._testingZ_testingr   rV  coreru   r   r   zipZ_any_string_methodrb   r]   dirrv   r   Zmissing_methodsrw   Zfixturere   r   Z"_any_allowed_skipna_inferred_dtyperr   rs   rm  r   rd  rn  ro  rp  r  rn   rr  r   r   r   r   <module>   s  $


 '                          5(




