U
    +if(                     @   s  d Z ddlmZ ddlZddlZddl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-eegd.d/ Zd0d1 Zd2d3 Zd4d5 Zejd6d7 Z ejd8eejd9dd:gejd;dd:gejd<d=d>gejd?d=d>gd@dA Z!dBdC Z"dDdE Z#dFdG Z$ejdHdIddJdKdLdMdNdddOdPdQdddRdSdTgdUdV Z%ej&dWdXdY Z'dZd[ Z(d\d] Z)dS )^zV
test methods relating to generic function evaluation
the so-called white/black lists
    )ascii_lowercaseN)	DataFrame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'   V/home/mars/bis/venv/lib/python3.8/site-packages/pandas/tests/groupby/test_allowlist.pydf_allowlist_fixture9   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_fixtureU   s    r-   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 )Nfoobaronetwothree   )ABCD)r   nprandomZrandnr'   r'   r'   r(   dfZ   s    

r:   c                  C   sR   t tt} d}| t jdd|}t|d tt j| t|d}|S )N
   r      )floatsletters)	r8   arraylistr   r   r9   randintr   r   )r>   NZrandom_lettersr:   r'   r'   r(   
df_lettersf   s    rC   	allowlistc                 C   s@   | }|t kr| }n| d }||j}t|t|jks<td S )Nr=   )df_allowlistgroupbyr>   setZ_apply_allowlistAssertionError)rC   rD   r:   objgbr'   r'   r(   test_groupby_allowlistt   s    rK   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"   )	rF   r>   getattrtype__name__AttributeErrorrH   __qualname__endswith)rI   r:   mrJ   fnr'   r'   r(   check_allowlist   s    

rU   c                 C   s   |}| }t |j|| d S r"   )rU   r>   )rC   r-   rR   r:   r'   r'   r(   test_groupby_series_allowlist   s    rV   c                 C   s   |}| }t ||| d S r"   )rU   )rC   r)   rR   r:   r'   r'   r(   test_groupby_frame_allowlist   s    rW   c                 C   s0   | }t j|jdddgf< t j|jdddgf< |S )N         r   )r8   naniloc)Z multiindex_dataframe_random_datar:   r'   r'   r(   	raw_frame   s    r]   oplevelrX   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   )r_   r`   rb   )ra   )r_   r`   ra   )r`   r_   )r_   r`   )	TAGG_FUNCTIONS_WITH_SKIPNArF   rL   tmZassert_produces_warningFutureWarningZ
sort_indexassert_frame_equal)
r]   r^   r_   r`   ra   rb   framegroupedresultexpectedr'   r'   r(   !test_regression_allowlist_methods   s$    
rl   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maskalignrF   ZclipZastypeatcombineZconsolidateZconvert_objectsc                 S   s   g | ]}| d r|qS )Z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)r=   dirextendrF   r>   reprrM   rN   pytestraisesrO   rL   )rC   r:   sZ	blocklistZ
to_methodsblrI   rJ   Zdefined_but_not_allowedZnot_definedmsgr'   r'   r(   test_groupby_blocklist   s8    
r   c              F   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@dAdBdCdDdEdFdGdHdIdJhF}||kstd S )KNsecondr_   c                 S   s   h | ]}| d s|qS _ru   )rw   vr'   r'   r(   	<setcomp>   s     
 z&test_tab_completion.<locals>.<setcomp>r4   r5   r6   ZaggZ	aggregateapplyZboxplotfilterfirstZ	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ewmZvalue_counts)rF   r}   rH   )mframegrpresultsrk   r'   r'   r(   test_tab_completion   s    Hr   c                 C   s2   | j dd}dD ]}t||}|j|kstqd S )Nr   r   )r	   r
   r   r   r   r   )rF   rL   rN   rH   )r   r   namerS   r'   r'   r(   test_groupby_function_renameG  s    
r   rx   r   r   r   r   r   r   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periodsr4   r6   )r   lenindexrF   rL   re   rg   )r:   rx   rnggg_expresexpr'   r'   r(   #test_groupby_selection_with_methodsN  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   r4   r6   zFreq was not set in the indexr{   )r   r   r   rF   r   r   
ValueErrorr   )r:   r   r   r'   r'   r(   $test_groupby_selection_tshift_raisest  s
    r   c                 C   s   t dt| d}d| j_|| _| 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   r.   r4   r6   r   c                 S   s   |   S r"   )r	   xr'   r'   r(   <lambda>      z6test_groupby_selection_other_methods.<locals>.<lambda>r7   c                 S   s   t | dkS )N   )r   r   r'   r'   r(   r     r   )r   r   columnsr   r   rF   re   rg   r   r   r   r   r   r   r   )r:   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   ru   )rw   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
)
rF   r\   r}   rG   r   r   r   r   rH   print)r   r   namesZ	new_namesr   Zall_categorizedr'   r'   r(   test_all_methods_categorized  s,    r   )*__doc__stringr   numpyr8   r   Zpandasr   r   r   Zpandas._testingZ_testingre   Zpandas.core.groupby.baser   r   r   ZAGG_FUNCTIONSrd   rE   Zfixturer)   Zs_allowlistr-   r:   rC   markZparametrizerK   rU   rV   rW   r]   rl   r   r   r   r   filterwarningsr   r   r   r'   r'   r'   r(   <module>   s   







,N


