o
    i)                  	   @   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 g dZddgZg d	Zejed
dd Zg d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dd Zdd Z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ejd&d$d%gd'd( Z!d)d* Z"d+d, Z#d-d. Z$ejd/g d0d1d2 Z%ej&d3d4d5 Z'd6d7 Z(d8d9 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semr   r   )quantilefillnar   takeidxmaxidxmintshiftr   plothistdtypescorrwithcorrcovdiff)paramsc                 C      | j S Nparamrequest r(   ^/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/pandas/tests/groupby/test_allowlist.pydf_allowlist_fixture9      r*   )r   r   r   r   r   r   r   r   r   r   dtyper   r   r    uniquenlargest	nsmallestis_monotonic_increasingis_monotonic_decreasingc                 C   r"   r#   r$   r&   r(   r(   r)   s_allowlist_fixtureU   r+   r2   c                   C   s*   t g dg dtjdtjddS )N)foobarr3   r4   r3   r4   r3   r3   )oner5   twothreer6   r6   r5   r7      )ABCD)r   nprandom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)	r=   arraylistr   r   r>   randintr   r   )rD   Nrandom_lettersr@   r(   r(   r)   
df_lettersf   s   rJ   	allowlistc                 C   s@   | }|t kr	| }n| d }||j}t|t|jksJ d S )NrC   )df_allowlistgroupbyrD   set_apply_allowlist)rJ   rK   r@   objgbr(   r(   r)   test_groupby_allowlistt   s   rR   c                 C   sx   |  |j}tt||}z|j}W n
 ty   Y d S w ||ks#J z|j}W n
 ty2   Y d S w ||s:J d S r#   )rM   rD   getattrtype__name__AttributeError__qualname__endswith)rP   r@   mrQ   fnr(   r(   r)   check_allowlist   s   

r\   c                 C   s   |}| }t |j|| d S r#   )r\   rD   )rJ   r2   rY   r@   r(   r(   r)   test_groupby_series_allowlist   s   r]   c                 C   s   |}| }t ||| d S r#   )r\   )rJ   r*   rY   r@   r(   r(   r)   test_groupby_frame_allowlist   s   r^   c                 C   s0   | }t j|jdddgf< t j|jdddgf< |S )N         r   )r=   naniloc) multiindex_dataframe_random_datar@   r(   r(   r)   	raw_frame   s   re   oplevelr_   axisskipnaTFsortc                 C   sV  |dkrt nd }|dkr| }n| j}|tv rn|j|||d}tj|ddd t|||d}	W d    n1 s9w   Y  tt  t|||||d}
W d    n1 sXw   Y  |rf|
j||d	}
t|	|
 d S |j|||d}tt  t|| }	t||||d
}
W d    n1 sw   Y  |r|
j||d	}
t|	|
 d S )Nr   r   )rg   rh   rj   zThe 'mad' method is deprecatedF)matchraise_on_extra_warnings)ri   )rg   rh   ri   )rh   rg   )rg   rh   )	FutureWarningTAGG_FUNCTIONS_WITH_SKIPNArM   tmassert_produces_warningrS   
sort_indexassert_frame_equal)re   rf   rg   rh   ri   rj   warnframegroupedresultexpectedr(   r(   r)   !test_regression_allowlist_methods   s2   	ry   c              
   C   s   | }| j }g d}dd t|D }|| |D ]N}||fD ]G}||j}dt| dt|j d}dt|j dt| d	}	| d
|	 }
tj	t
|
d t|| W d    n1 saw   Y  qqd S )N)evalqueryabswheremaskalignrM   clipastypeatcombineconsolidateconvert_objectsc                 S   s   g | ]	}| d r|qS )to_
startswith).0methodr(   r(   r)   
<listcomp>       z*test_groupby_blocklist.<locals>.<listcomp>z(?:^Cannot.+z.+'z!'.+try using the 'apply' method$)z(?:^'z' object has no attribute z$)|rk   )rC   dirextendrM   rD   reprrT   rU   pytestraisesrV   rS   )rJ   r@   s	blocklist
to_methodsblrP   rQ   defined_but_not_allowednot_definedmsgr(   r(   r)   test_groupby_blocklist   s&   
r   c                 C   s6   | j dd}dd t|D }h d}||ksJ d S )Nsecondrg   c                 S      h | ]	}| d s|qS _r   )r   vr(   r(   r)   	<setcomp>   r   z&test_tab_completion.<locals>.<setcomp>>F   r9   r:   r;   aggallanyr   ewmr   r   r   nthpadr   r   r	   r   r   r    headr   lastr   ndimohlcpiper   r
   ranksizer   tailr   applybfillcountffillfirstshiftcummaxcummincumsumr   r   filtergroupsr   r   r   ngroupsampler   boxplotcumprodindicesngroupsnuniquerollingbackfillr   cumcountdescriber   resample	aggregate	expanding	get_group	transform
pct_changevalue_counts)rM   r   )mframegrpresultsrx   r(   r(   r)   test_tab_completion   s   Hr   c                 C   s2   | j dd}dD ]}t||}|j|ksJ qd S )Nr   r   )r	   r
   r   r   r   r   )rM   rS   rU   )r   r   namerZ   r(   r(   r)   test_groupby_function_renameK  s
   
r   r   )r   r   r   r   r   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periodsr9   r;   )r   lenindexrM   rS   rp   rs   )r@   r   rnggg_expresexpr(   r(   r)   #test_groupby_selection_with_methodsR  s   r   z)ignore:tshift is deprecated:FutureWarningc                 C   sd   t dt| d}|| _| dgdg }tjtdd |  W d    d S 1 s+w   Y  d S )Nr   r   r9   r;   zFreq was not set in the indexr   )r   r   r   rM   r   r   
ValueErrorr   )r@   r   r   r(   r(   r)   $test_groupby_selection_tshift_raisesx  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   r3   r9   r;   r   c                 S   s   |   S r#   )r	   xr(   r(   r)   <lambda>  s    z6test_groupby_selection_other_methods.<locals>.<lambda>r<   c                 S   s   t | dkS )N   )r   r   r(   r(   r)   r     s    )r   r   columnsr   r   rM   rp   rs   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@ r0J tt@ r6J tt@ r<J |rHd| d}t|ttB tB }t	| t	| ||ksfd||  d}t|d S )Nr   c                 S   r   r   r   )r   r   r(   r(   r)   r     r   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
)
rM   rc   r   rN   r   r   r   r   AssertionErrorprint)r   r   names	new_namesr   all_categorizedr(   r(   r)   test_all_methods_categorized  s.   r   )*__doc__stringr   numpyr=   r   pandasr   r   r   pandas._testing_testingrp   pandas.core.groupby.baser   r   r   AGG_FUNCTIONSro   rL   fixturer*   s_allowlistr2   r@   rJ   markparametrizerR   r\   r]   r^   re   ry   r   r   r   r   filterwarningsr   r   r   r(   r(   r(   r)   <module>   sX    







 ,N


