U
    NZf                      @   sL  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g
ZdgZejdd Zejdd Zejdd Zejdeejdddgejdddgejdddgdd Zdd  Zd!d" Zd#d$ Zejd%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6gd7d8 Zd9d: 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stdvarsemc                
   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randn r   r   G/tmp/pip-unpacked-wheel-nbcvw55c/pandas/tests/groupby/test_allowlist.pydf&   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)	r   arraylistr   taker   randintr   r   )r"   NZrandom_lettersr   r   r   r   
df_letters2   s    r(   c                   C   s
   t dgS )Nr   )r   r   r   r   r   	raw_frame@   s    r)   opaxis   skipnaTFsortc           	         s    dkr| }n| j }tkrx|jd |d}t|d}|jdd fdd}|rj|j d}t|| nT|jd |d}t| }|jdd fdd}|r|j d}t|| d S )	Nr   )levelr+   r.   )r-   r/   c                    s   t |  dS )N)r+   r-   getattrhr+   r*   r-   r   r   <lambda>V       z3test_regression_allowlist_methods.<locals>.<lambda>r+   c                    s   t |  dS )Nr8   r1   r3   )r+   r*   r   r   r6   ^   r7   )TAGG_FUNCTIONS_WITH_SKIPNAgroupbyr2   applyZ
sort_indextmassert_frame_equal)	r)   r*   r+   r-   r.   frameZgroupedresultexpectedr   r5   r   !test_regression_allowlist_methodsE   s$    rB   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alignr;   ZclipZastypeatcombineZconsolidateZconvert_objectsc                 S   s   g | ]}| d r|qS )to_
startswith).0methodr   r   r   
<listcomp>w   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extendr;   r"   reprtype__name__pytestZraisesAttributeErrorr2   )r(   r   sZ	blocklistZ
to_methodsblobjgbZdefined_but_not_allowedZnot_definedmsgr   r   r   test_groupby_blocklistd   s8    
r^   c              B   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@dAdBdCdDdEdFhB}||kstd S )GNsecondr0   c                 S   s   h | ]}| d s|qS _rK   )rM   vr   r   r   	<setcomp>   s     
 z&test_tab_completion.<locals>.<setcomp>r   r   r   ZaggZ	aggregater<   ZboxplotfilterfirstZ	get_groupgroupshistindiceslastr   r   r   r   ZngroupsZnthohlcZplotr
   sizer   r	   Z	transformr   r   countZnuniqueheaddescribecummaxquantilerankcumprodtailresamplecumminfillnaZcumsumZcumcountZngroupallshiftr   r%   
pct_changeanycorrZcorrwithZcovdtypesndimdiffidxmaxidxminffillbfillZrollingZ	expandingpipesampleZewmZvalue_counts)r;   rR   AssertionError)mframegrpresultsrA   r   r   r   test_tab_completion   s    Dr   c                 C   s2   | j dd}dD ]}t||}|j|kstqd S )Nr_   r0   )r	   r
   r   r   re   ri   )r;   r2   rV   r   )r   r   namefr   r   r   test_groupby_function_rename   s    
r   rN   rl   r{   ro   ru   rr   rn   rq   rp   r~   rx   rw   rz   r   r   r   r   ry   c                 C   sd   t dt| d}|| _| dgdg }| dg | d }t|| }t|| }t|| d S )N2014Zperiodsr   r   )r   lenindexr;   r2   r=   r>   )r   rN   rnggg_expresexpr   r   r   #test_groupby_selection_with_methods   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   r   r   r   c                 S   s   |   S )N)r	   xr   r   r   r6     r7   z6test_groupby_selection_other_methods.<locals>.<lambda>r   c                 S   s   t | dkS )N   )r   r   r   r   r   r6     r7   )r   r   columnsr   r   r;   r=   r>   rv   r|   r<   rt   r   rj   rd   )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 }||krd||  d}t|d S )Nr   c                 S   s   h | ]}| d s|qS r`   rK   )rM   ra   r   r   r   rc     s     
 z/test_all_methods_categorized.<locals>.<setcomp>z?
There are uncategorized 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
)	r;   ZilocrR   setr   r   r   r   r   )r   r   namesZ	new_namesr]   Zall_categorizedr   r   r   test_all_methods_categorized  s(    r   ) __doc__stringr   Znumpyr   rW   Zpandasr   r   r   Zpandas._testingZ_testingr=   Zpandas.core.groupby.baser   r   r   ZAGG_FUNCTIONSr:   Zfixturer   r(   r)   markZparametrizerB   r^   r   r   r   r   r   r   r   r   r   <module>   sp   


,J
