U
    f/e+                     @   sP  d Z ddlmZ ddlZddlZddlm  mZ	 ddl
mZmZmZmZmZ ddlmZ ddlmZmZmZ dddd	d
ddddddgZddgZdddddddddddddddgZejeddd  Zddddddddddd!dddd"d#d$d%d&gZejedd'd( Zejd)d* Zejd+d, Zejd-d. Z ej!"d/eegd0d1 Z#d2d3 Z$d4d5 Z%d6d7 Z&ejd8d9 Z'ej!"d:eej!"d;dd<gej!"d=dd<gej!"d>d?d@gej!"dAd?d@gdBdC Z(dDdE Z)dFdG Z*dHdI Z+ej!"dJdKddLdMdNej,dOe	j-dPdQdddRdSdTdddUdVdWgdXdY Z.ej!/dZd[d\ Z0d]d^ Z1d_d` Z2dS )azV
test methods relating to generic function evaluation
the so-called white/black lists
    )ascii_lowercaseN)	DataFrameIndex
MultiIndexSeries
date_range)groupby_other_methodsreduction_kernelstransformation_kernelssumprodminmaxmedianmeanskewmadstdvarsemquantilefillnatakeidxmaxidxmintshiftplothistdtypescorrwithcorrcovdiff)paramsc                 C   s   | j S Nparamrequest r)   G/tmp/pip-unpacked-wheel-tiezk1ph/pandas/tests/groupby/test_allowlist.pydf_allowlist_fixture=   s    r+   Zdtypeuniquenlargest	nsmallestZis_monotonic_increasingZis_monotonic_decreasingc                 C   s   | j S r$   r%   r'   r)   r)   r*   s_allowlist_fixtureY   s    r/   c                  C   sn   t ddddgdddggdddd	d	d
d
dddg
dd	d
dd	d	d
dd	d
g
gddgd} ttjdd| dddgdS )Nfoobarbazquxonetwothreer            firstsecondlevelscodesnames
   ABCindexcolumns)r   r   nprandomrandn)rE   r)   r)   r*   mframe^   s    .rJ   c                
   C   sB   t ddddddddgddddddddgtjdtjddS )Nr0   r1   r4   r5   r6      )rA   rB   rC   D)r   rG   rH   rI   r)   r)   r)   r*   dfh   s    

rM   c                  C   sR   t tt} d}| t jdd|}t|d tt j| t|d}|S )Nr@   r      )floatsletters)	rG   arraylistr   r   rH   randintr   r   )rP   NZrandom_lettersrM   r)   r)   r*   
df_letterst   s    rU   	allowlistc                 C   s@   | }|t kr| }n| d }||j}t|t|jks<td S )NrO   )df_allowlistgroupbyrP   setZ_apply_allowlistAssertionError)rU   rV   rM   objgbr)   r)   r*   test_groupby_allowlist   s    r]   c                 C   s|   |  |j}tt||}z
|j}W n tk
r:   Y d S X ||ksHtz
|j}W n tk
rh   Y d S X ||sxtd S r$   )	rX   rP   getattrtype__name__AttributeErrorrZ   __qualname__endswith)r[   rM   mr\   fnr)   r)   r*   check_allowlist   s    

rg   c                 C   s   |}| }t |j|| d S r$   )rg   rP   )rU   r/   rd   rM   r)   r)   r*   test_groupby_series_allowlist   s    rh   c                 C   s   |}| }t ||| d S r$   )rg   )rU   r+   rd   rM   r)   r)   r*   test_groupby_frame_allowlist   s    ri   c                  C   s   t ddddgdddggdddd	d	d
d
dddg
dd	d
dd	d	d
dd	d
g
gddgd} ttjdd| tdddgddd}tj|jd	d	d
gf< tj|jddd	gf< |S )Nr0   r1   r2   r3   r4   r5   r6   r   r7   r8   r9   r:   r;   r<   r@   rA   rB   rC   exp)namerD      )r   r   rG   rH   rI   r   naniloc)rE   	raw_framer)   r)   r*   ro      s    .  ro   oplevelr7   axisskipnaTFsortc           
   	   C   s   |dkr| }n| j }|tkr|j|||d}t|||d}tt t|||||d}	W 5 Q R X |rx|	j||d}	t||	 nb|j|||d}t|| }tt t||||d}	W 5 Q R X |r|	j||d}	t||	 d S )Nr   )rq   rr   rt   )rs   )rq   rr   rs   )rr   rq   )rq   rr   )	TAGG_FUNCTIONS_WITH_SKIPNArX   r^   tmZassert_produces_warningFutureWarningZ
sort_indexassert_frame_equal)
ro   rp   rq   rr   rs   rt   frameZgroupedresultexpectedr)   r)   r*   !test_regression_allowlist_methods   s$    
r}   c                 C   s   | }| j }ddddddddd	d
dddg}dd t|D }|| |D ]}||fD ]z}||j}dt| dt|j d}dt|j dt| d}	| d|	 }
tj	t
|
d t|| W 5 Q R X qTqHd S )NevalqueryabswheremaskZalignrX   ZclipZastypeatcombineZconsolidateZconvert_objectsc                 S   s   g | ]}| d r|qS )to_
startswith).0methodr)   r)   r*   
<listcomp>   s     
 z*test_groupby_blocklist.<locals>.<listcomp>z(?:^Cannot.+z.+'z!'.+try using the 'apply' method$)z(?:^'z' object has no attribute z$)|match)rO   dirextendrX   rP   reprr_   r`   pytestraisesra   r^   )rU   rM   sZ	blocklistZ
to_methodsblr[   r\   Zdefined_but_not_allowedZnot_definedmsgr)   r)   r*   test_groupby_blocklist   s8    
r   c              E   C   s   | j dd}dd t|D }ddddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIhE}||kstd S )JNr;   rq   c                 S   s   h | ]}| d s|qS _r   )r   vr)   r)   r*   	<setcomp>  s     
 z&test_tab_completion.<locals>.<setcomp>rA   rB   rC   ZaggZ	aggregateapplyZboxplotfilterr:   Z	get_groupgroupsr   indiceslastr   r   r   r   ZngroupsZnthohlcr   r   sizer   r   Z	transformr   r   countZnuniqueheaddescribecummaxr   rankcumprodtailresamplecumminr   ZcumsumZcumcountZngroupallshiftr   r   r   
pct_changeanyr   r    r   r!   r   ndimr"   r   r   ffillbfillpadZbackfillZrollingZ	expandingpipesampleZewm)rX   r   rZ   )rJ   grpresultsr|   r)   r)   r*   test_tab_completion  s    Gr   c                 C   s2   | j dd}dD ]}t||}|j|kstqd S )Nr;   r   )r   r   r   r   r:   r   )rX   r^   r`   rZ   )rJ   r   rk   re   r)   r)   r*   test_groupby_function_rename[  s    
r   r   r   r   r   r   r   )Zmarksr   r   r   r   r   r   r   c                 C   sd   t dt| d}|| _| dgdg }| dg | d }t|| }t|| }t|| d S )N2014ZperiodsrA   rC   )r   lenrE   rX   r^   rw   ry   )rM   r   rnggg_expresrj   r)   r)   r*   #test_groupby_selection_with_methodsb  s    r   z)ignore:tshift is deprecated:FutureWarningc              	   C   sN   t dt| d}|| _| dgdg }tjtdd |  W 5 Q R X d S )Nr   r   rA   rC   zFreq was not set in the indexr   )r   r   rE   rX   r   r   
ValueErrorr   )rM   r   r   r)   r)   r*   $test_groupby_selection_tshift_raises  s
    r   c                 C   s   t dt| d}|| _| dgdg }| dg | d }t|d|d t|j|j t|dd |dd  t|	d
 |	d
  t|	d |	d  t|d	d |d	d  d S )
Nr   r   rA   rC   r   c                 S   s   |   S r$   )r   xr)   r)   r*   <lambda>      z6test_groupby_selection_other_methods.<locals>.<lambda>rL   c                 S   s   t | dkS )Nr9   )r   r   r)   r)   r*   r     r   )r   r   rE   rX   rw   ry   r   r   r   r   r   r   r   )rM   r   r   r   r)   r)   r*   $test_groupby_selection_other_methods  s        r   c                 C   s   |  | jd d df }dd t|D t| j }t|}|t8 }|t8 }|t8 }tt@ r`ttt@ rlttt@ rxt|rd| d}t|ttB tB }t	| t	| ||ksd||  d}t|d S )Nr   c                 S   s   h | ]}| d s|qS r   r   )r   r   r)   r)   r*   r     s     
 z/test_all_methods_categorized.<locals>.<setcomp>z?
There are uncatgeorized methods defined on the Grouper class:
aG  .

Was a new method recently added?

Every public method On Grouper must appear in exactly one the
following three lists defined in pandas.core.groupby.base:
- `reduction_kernels`
- `transformation_kernels`
- `groupby_other_methods`
see the comments in pandas/core/groupby/base.py for guidance on
how to fix this test.
        zI
Some methods which are supposed to be on the Grouper class
are missing:
z.

They're still defined in one of the lists that live in pandas/core/groupby/base.py.
If you removed a method, you should update them
)
rX   rn   r   rY   rF   r	   r
   r   rZ   print)rJ   r   r?   Z	new_namesr   Zall_categorizedr)   r)   r*   test_all_methods_categorized  s,    r   )3__doc__stringr   ZnumpyrG   r   Zpandas.util._test_decoratorsutilZ_test_decoratorstdZpandasr   r   r   r   r   Zpandas._testingZ_testingrw   Zpandas.core.groupby.baser   r	   r
   ZAGG_FUNCTIONSrv   rW   Zfixturer+   Zs_allowlistr/   rJ   rM   rU   markZparametrizer]   rg   rh   ri   ro   r}   r   r   r   r&   Z&skip_array_manager_not_yet_implementedr   filterwarningsr   r   r   r)   r)   r)   r*   <module>   s   




	



,M


