a
    PfV                     @   s  d dl Z d dlZd dlZd dlZd dlmZmZmZm	Z	 d dl
mZ d dlmZ ejddgddgedddd g d	eg d	eeed
g d	e	g de	g de	g dgg
ddd Zejddgddd Zejdd Zejdd Zejdd Zejdd Zd>ddZejdg d d!d" Zejdd#d$gd%d& Zejdd#d$gejd'ejej gd(d) Z!ejdg d d*d+ Z"ejdd#d$gd,d- Z#ejdd#d$gejd'ejej gd.d/ Z$ejd0g d1d2d3 Z%ejdg d d4d5 Z&ejdd#d$gd6d7 Z'ejdd#d$gejd'ejej gd8d9 Z(ejdg d d:d; Z)d<d= Z*dS )?    N)Categorical	DataFrameGrouperSeries)get_groupby_method_argsab)keyc                 C   s   | d S )N    xr   r   Y/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/tests/groupby/test_raises.py<lambda>       r   )	r   r   r      r
   r
   r
      r   	   	r   r   r   r   r   r
   r
   r
   r
   	r   r      r   r   r   r   r   r   )paramsc                 C   s   | j S Nparamrequestr   r   r   by   s    r   TFc                 C   s   | j S r   r   r   r   r   r   groupby_series'   s    r   c                  C   s&   t g dg dtdtdd} | S )Nr   r   r   Z	xyzwtyuior   r   cd)r   rangelistdfr   r   r   df_with_string_col,   s    r&   c                  C   s4   t g dg dtdtddddddd	d
} | S )Nr   r   r   i  r   
         i`= r   )r   r"   datetimer$   r   r   r   df_with_datetime_col9   s    r+   c                  C   s*   t g dg dtdtjddd} | S )Nr   r   r   r   )daysr   )r   r"   r*   	timedeltar$   r   r   r   df_with_timedelta_colF   s    
r.   c               	   C   s4   t g dg dtdtg dg dddd} | S )Nr   r   r   	r   r   r   r   r   r   r   r   r    r   T
categoriesordered)r   r"   r   r$   r   r   r   df_with_cat_colS   s    r3    c              	   C   s  |dkrd nt }tj||d | d u rp|dkr@t|||  q|dkr\|j|g|R   q|j|g|R   nttj| |dV |dkrt|||  n.|dkr|j|g|R   n|j|g|R   W d    n1 s0    Y  W d    n1 s0    Y  d S )Nr4   matchmethodagg)FutureWarningtmassert_produces_warninggetattrr8   	transformpytestraises)klassmsghowgbgroupby_funcargswarn_msgZ
warn_klassr   r   r   _call_and_checkd   s    rG   rB   )r7   r8   r=   c              %   C   s6  |}t ||}|j|d}|r@|d }|dkr@t|dr<J d S dddtdfddttfdfttfdfttfdfttfd	ftd
fdddddddttdfttdfdddtd
fttdftdfdtdfddtdftdfdttdfd"| \}}	|dkr|r
dnd}
|
 d}nd}t||	| |||| d S )Nr   r!   corrwithNr4   zCould not convertzH(function|cummax) is not (implemented|supported) for (this|object) dtypezH(function|cummin) is not (implemented|supported) for (this|object) dtypezI(function|cumprod) is not (implemented|supported) for (this|object) dtypezH(function|cumsum) is not (implemented|supported) for (this|object) dtypeunsupported operand type-agg function failed [how->mean,dtype->object]z/agg function failed [how->median,dtype->object]z-agg function failed [how->prod,dtype->object]z,cannot be performed against 'object' dtypes!z!could not convert string to floatz%agg function failed [how->var,dtype->"allanyZbfillrI   countZcumcountZcummaxZcummincumprodZcumsumdiffZffillfillnafirstZidxmaxZidxminlastmaxmeanZmedianminZngroupZnuniqueZ
pct_changeprodZquantileZrankZsemshiftsizeskewZstdsumvarrS   r   r   GroupBy.fillna is deprecatedr4   )	r   groupbyhasattr	TypeErrorNotImplementedErrorreescape
ValueErrorrG   )rB   r   r   rD   r&   r%   rE   rC   r@   rA   kindrF   r   r   r   test_groupby_raises_stringx   s    
;=
rh   r8   r=   c                 C   sd   |}|j |d}|r|d }dd }tjtdd t|| | W d    n1 sV0    Y  d S )NrH   r!   c                 S   s   t dd S NTest error messagerb   r   r   r   r   func   s    z,test_groupby_raises_string_udf.<locals>.funcrj   r5   r`   r>   r?   rb   r<   )rB   r   r   r&   r%   rC   rl   r   r   r   test_groupby_raises_string_udf   s    rn   groupby_func_npc           
   	   C   sf   |}|j |d}|r|d }tjdtjttdfi| \}}|rHd}	nd}	t||| ||d|	d d S )	NrH   r!   rJ   rL   using SeriesGroupBy.[sum|mean]!using DataFrameGroupBy.[sum|mean]r   rF   )r`   npr]   rW   rb   rd   re   rG   )
rB   r   r   ro   r&   r%   rC   r@   rA   rF   r   r   r   test_groupby_raises_string_np   s     rt   c              #   C   s  |}t ||}|j|d}|r@|d }|dkr@t|dr<J d S dddtdfddddtdftdfdddddddddddddtdftd	fdddddtd
ddgfdtdftdfd"| \}}	|dv rd| d}
n$|dkr|rdnd}| d}
nd}
t||	| ||||
d d S )NrH   r!   rI   rJ   z+cannot perform __mul__ with this index typez3datetime64 type does not support cumprod operationsz2datetime64 type does not support cumsum operationsz/cannot perform __truediv__ with this index typez%datetime64 type does not support prod|z1dtype datetime64\[ns\] does not support reductionz0datetime64 type does not support skew operations/datetime64 type does not support sum operationsz/datetime64 type does not support var operationsrM   )rO   rN   'z&' with datetime64 dtypes is deprecatedrS   r   r   r_   r4   rr   )r   r`   ra   rb   joinrG   )rB   r   r   rD   r+   r%   rE   rC   r@   rA   rF   rg   r   r   r   test_groupby_raises_datetime   st    
	+-ry   c                 C   sd   |}|j |d}|r|d }dd }tjtdd t|| | W d    n1 sV0    Y  d S )NrH   r!   c                 S   s   t dd S ri   rk   r   r   r   r   rl   D  s    z.test_groupby_raises_datetime_udf.<locals>.funcrj   r5   rm   )rB   r   r   r+   r%   rC   rl   r   r   r    test_groupby_raises_datetime_udf<  s    rz   c           
   	   C   s`   |}|j |d}|r|d }tjtdftjdi| \}}|rBd}	nd}	t||| ||d|	d d S )	NrH   r!   rv   rJ   rp   rq   r   rr   r`   rs   r]   rb   rW   rG   )
rB   r   r   ro   r+   r%   rC   r@   rA   rF   r   r   r   test_groupby_raises_datetime_npK  s    
r|   rl   )rY   rQ   r\   r^   c                 C   s&   |}|j dd}ttdd|| g  d S )Nr   rH   z/timedelta64 type does not support .* operationsr7   )r`   rG   rb   )rl   r.   r%   rC   r   r   r   test_groupby_raises_timedeltac  s    r}   c              &   C   sj  |}t ||}|j|d}|r@|d }|dkr@t|dr<J d S dddtdfddttfdfttfdfttfdfttfd	ftd
fd|stdfnddddddtdddgftdddgfdddtdftdftdfdtdddgfddtdddgftdddgftdftdddgfd"| \}	}
|dkrN|r>dnd }| d!}nd"}t|	|
| |||| d S )#NrH   r!   rI   rJ   =unsupported operand type\(s\) for \*: 'Categorical' and 'int'zz(category type does not support cummax operations|category dtype not supported|cummax is not supported for category dtype)zz(category type does not support cummin operations|category dtype not supported|cummin is not supported for category dtype)z|(category type does not support cumprod operations|category dtype not supported|cumprod is not supported for category dtype)zz(category type does not support cumsum operations|category dtype not supported|cumsum is not supported for category dtype)zDunsupported operand type\(s\) for -: 'Categorical' and 'Categorical'SCannot setitem on a Categorical with a new category \(0\), set the categories firstru   z2'Categorical' .* does not support reduction 'mean'2category dtype does not support aggregation 'mean'z4'Categorical' .* does not support reduction 'median'4category dtype does not support aggregation 'median'zDunsupported operand type\(s\) for /: 'Categorical' and 'Categorical'.category type does not support prod operationszNo matching signature found1'Categorical' .* does not support reduction 'sem'1category dtype does not support aggregation 'sem'0dtype category does not support reduction 'skew'.category type does not support skew operations1'Categorical' .* does not support reduction 'std'1category dtype does not support aggregation 'std'-category type does not support sum operations1'Categorical' .* does not support reduction 'var'1category dtype does not support aggregation 'var'rM   rS   r   r   r_   r4   )r   r`   ra   rb   rc   rx   rG   )rB   r   r   rD   using_copy_on_writer3   r%   rE   rC   r@   rA   rg   rF   r   r   r   test_groupby_raises_categoryr  s    

		
	vx
r   c                 C   sd   |}|j |d}|r|d }dd }tjtdd t|| | W d    n1 sV0    Y  d S )NrH   r!   c                 S   s   t dd S ri   rk   r   r   r   r   rl     s    z.test_groupby_raises_category_udf.<locals>.funcrj   r5   rm   )rB   r   r   r3   r%   rC   rl   r   r   r    test_groupby_raises_category_udf  s    r   c           
   	   C   sd   |}|j |d}|r|d }tjtdftjtdfi| \}}|rFd}	nd}	t||| ||d|	d d S )	NrH   r!   r   r   rp   rq   r   rr   r{   )
rB   r   r   ro   r3   r%   rC   r@   rA   rF   r   r   r   test_groupby_raises_category_np  s     
r   c              &   C   s  |}t g dg ddd|d< t||}|j||d}	|r\|	d }	|dkr\t|	drXJ d S | oxtd	d
 |	j D }
|s| dkrt|trt|d t	r|ddgkr|
rJ d}
| dkrd}
dddt
dfddtt
fdftt
fdftt
fdftt
fdft
dfd|st
dfndd|
r"tdfnd|
r2tdfndddt
dft
dfdddt
dft
dft
dfdt
dddgfddt
ddd gft
dd!d"gft
d#ft
dd$d%gfd&"| \}}|d'kr|rd(nd)}| d*}nd}t||| |	||| d S )+Nr/   r   Tr0   r   )r   observedr!   rI   c                 s   s   | ]}|j V  qd S r   )empty).0groupr   r   r   	<genexpr>H  r   z;test_groupby_raises_category_on_category.<locals>.<genexpr>r=   r   r   FrJ   r~   zz(cummax is not supported for category dtype|category dtype not supported|category type does not support cummax operations)zz(cummin is not supported for category dtype|category dtype not supported|category type does not support cummin operations)z|(cumprod is not supported for category dtype|category dtype not supported|category type does not support cumprod operations)zz(cumsum is not supported for category dtype|category dtype not supported|category type does not support cumsum operations)rK   r   z(empty group due to unobserved categoriesr   r   r   r4   ru   r   r   r   r   r   r   r   r   r   rM   rS   r   r   r_   )r   r   r`   ra   rO   groupsvalues
isinstancer#   strrb   rc   rf   rx   rG   )rB   r   r   rD   r   r   r3   r%   rE   rC   Zempty_groupsr@   rA   rg   rF   r   r   r   (test_groupby_raises_category_on_category-  s    


	
	df
r   c                  C   s   t dgdgdgd} d}tjt|d | jddd}W d    n1 sL0    Y  tjtd	d |d
  W d    n1 s0    Y  d S )Nr   r
   r   )r   r   r    z+DataFrame.groupby with axis=1 is deprecatedr5   r   )Zaxisz'Cannot subset columns when using axis=1r   )r   r:   r;   r9   r`   r>   r?   rf   )r%   rA   rC   r   r   r   %test_subsetting_columns_axis_1_raises  s    ,r   )r4   )+r*   rd   numpyrs   r>   Zpandasr   r   r   r   Zpandas._testingZ_testingr:   Zpandas.tests.groupbyr   Zfixturearraydictzipr"   r   r   r&   r+   r.   r3   rG   markZparametrizerh   rn   r]   rW   rt   ry   rz   r|   r}   r   r   r   r   r   r   r   r   r   <module>   sv   








S

E


 

 