U
    b(                     @   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'   G/tmp/pip-unpacked-wheel-ck39h295/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barZoneZtwoZthree   )ABCD)r   nprandomZrandnr'   r'   r'   r(   dfZ   s    

r7   c                  C   sR   t tt} d}| t jdd|}t|d tt j| t|d}|S )N
   r      )floatsletters)	r5   arraylistr   r   r6   randintr   r   )r;   NZrandom_lettersr7   r'   r'   r(   
df_lettersf   s    r@   	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)r@   rA   r7   objgbr'   r'   r(   test_groupby_allowlistt   s    rH   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"   )	rC   r;   getattrtype__name__AttributeErrorrE   __qualname__endswith)rF   r7   mrG   fnr'   r'   r(   check_allowlist   s    

rR   c                 C   s   |}| }t |j|| d S r"   )rR   r;   )r@   r-   rO   r7   r'   r'   r(   test_groupby_series_allowlist   s    rS   c                 C   s   |}| }t ||| d S r"   )rR   )r@   r)   rO   r7   r'   r'   r(   test_groupby_frame_allowlist   s    rT   c                 C   s0   | }t j|jdddgf< t j|jdddgf< |S )N         r   )r5   naniloc)Z multiindex_dataframe_random_datar7   r'   r'   r(   	raw_frame   s    rZ   oplevelrU   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]   r_   )r^   )r\   r]   r^   )r]   r\   )r\   r]   )	TAGG_FUNCTIONS_WITH_SKIPNArC   rI   tmZassert_produces_warningFutureWarningZ
sort_indexassert_frame_equal)
rZ   r[   r\   r]   r^   r_   frameZgroupedresultexpectedr'   r'   r(   !test_regression_allowlist_methods   s$    
rh   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alignrC   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)r:   dirextendrC   r;   reprrJ   rK   pytestraisesrL   rI   )r@   r7   sZ	blocklistZ
to_methodsblrF   rG   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 _rq   )rs   vr'   r'   r(   	<setcomp>   s     
 z&test_tab_completion.<locals>.<setcomp>r1   r2   r3   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)rC   ry   rE   )mframegrpresultsrg   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   )rC   rI   rK   rE   )r   r   namerP   r'   r'   r(   test_groupby_function_renameG  s    
r   rt   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periodsr1   r3   )r   lenindexrC   rI   rb   rd   )r7   rt   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   r1   r3   zFreq was not set in the indexrw   )r   r   r   rC   r|   r}   
ValueErrorr   )r7   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.   r1   r3   r   c                 S   s   |   S r"   )r	   xr'   r'   r(   <lambda>      z6test_groupby_selection_other_methods.<locals>.<lambda>r4   c                 S   s   t | dkS )N   )r   r   r'   r'   r(   r     r   )r   r   columnsr   r   rC   rb   rd   r   r   r   r   r   r   r   )r7   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   rq   )rs   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
)
rC   rY   ry   rD   r   r   r   r   rE   print)r   r   namesZ	new_namesr   Zall_categorizedr'   r'   r(   test_all_methods_categorized  s,    r   )*__doc__stringr   Znumpyr5   r|   Zpandasr   r   r   Zpandas._testingZ_testingrb   Zpandas.core.groupby.baser   r   r   ZAGG_FUNCTIONSra   rB   Zfixturer)   Zs_allowlistr-   r7   r@   markZparametrizerH   rR   rS   rT   rZ   rh   r   r   r   r   filterwarningsr   r   r   r'   r'   r'   r(   <module>   s   







,N


