o
    թZhV                     @   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   W/var/www/html/lang_env/lib/python3.10/site-packages/pandas/tests/groupby/test_raises.py<lambda>   s    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      | j S Nparamrequestr   r   r   by   s   r   TFc                 C   r   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
categoriesZordered)r   r"   r   r$   r   r   r   df_with_cat_colS   s   r2    c              	   C   sH  |dkrd nt }tj||d | d u r8|dkr t|||  nb|dkr.|j|g|R   n\|j|g|R   nBtj| |d+ |dkrLt|||  n|dkrZ|j|g|R   n	|j|g|R   W d    n(1 smw   Y  W d    d S W d    d S W d    d S W d    d S W d    d S 1 sw   Y  d S )Nr3   matchmethodagg)FutureWarningtmassert_produces_warninggetattrr7   	transformpytestraises)klassmsghowgbgroupby_funcargswarn_msgZ
warn_klassr   r   r   _call_and_checkd   s2   	"rF   rA   )r6   r7   r<   c                 C   s  |}t ||}|j|d}|r |d }|dkr t|drJ d S i dddddddtdfd	dd
ddttfdfdttfdfdttfdfdttfdfdtdfddddddddddddi dddttdfdttdfd dd!dd"dd#tdfd$ttd%fd&td'fd(dd)td*fd+dd,dd-td*fd.td*fd/dd0ttd1f| \}}	|dkr|rd2nd3}
|
 d4}nd5}t||	| |||| d S )6Nr   r!   corrwithallNr3   anybfillzCould not convertcountcumcountcummaxzH(function|cummax) is not (implemented|supported) for (this|object) dtypecumminzH(function|cummin) is not (implemented|supported) for (this|object) dtypecumprodzI(function|cumprod) is not (implemented|supported) for (this|object) dtypecumsumzH(function|cumsum) is not (implemented|supported) for (this|object) dtypediffunsupported operand typeffillfillnafirstidxmaxidxminlastmaxmean-agg function failed [how->mean,dtype->object]medianz/agg function failed [how->median,dtype->object]minngroupnunique
pct_changeprodz-agg function failed [how->prod,dtype->object]quantilez,cannot be performed against 'object' dtypes!ranksemz!could not convert string to floatshiftsizeskewstdsumvarz%agg function failed [how->var,dtype->r   r   GroupBy.fillna is deprecatedr3   )	r   groupbyhasattr	TypeErrorNotImplementedErrorreescape
ValueErrorrF   )rA   r   r   rC   r&   r%   rD   rB   r?   r@   kindrE   r   r   r   test_groupby_raises_stringx   s   
#'()*+/01234567;=rv   r7   r<   c                 C   f   |}|j |d}|r|d }dd }tjtdd t|| | W d    d S 1 s,w   Y  d S )NrG   r!   c                 S      t dNTest error messagerp   r   r   r   r   func      z,test_groupby_raises_string_udf.<locals>.funcrz   r4   rn   r=   r>   rp   r;   )rA   r   r   r&   r%   rB   r|   r   r   r   test_groupby_raises_string_udf      "r   groupby_func_npc           
   	   C   sf   |}|j |d}|r|d }tjdtjttdfi| \}}|r$d}	nd}	t||| ||d|	d d S )	NrG   r!   rJ   r]   using SeriesGroupBy.[sum|mean]!using DataFrameGroupBy.[sum|mean]r   rE   )rn   nprk   r\   rp   rr   rs   rF   )
rA   r   r   r   r&   r%   rB   r?   r@   rE   r   r   r   test_groupby_raises_string_np   s    r   c              	   C   s  |}t ||}|j|d}|r |d }|dkr t|drJ d S i dddddddtdfd	dd
ddddddtdfdtdfddddddddddddddi dddddddddddddtdfd td!fd"dd#dd$dd%dd&dd'td(d)d*gfd+dd,td-fd.td/f| \}}	|d0v rd1| d2}
n|dkr|rd3nd4}| d5}
nd6}
t||	| ||||
d7 d S )8NrG   r!   rH   rI   rJ   rK   rL   z+cannot perform __mul__ with this index typerM   rN   rO   rP   rQ   z3datetime64 type does not support cumprod operationsrR   z2datetime64 type does not support cumsum operationsrS   rU   rV   rW   rX   rY   rZ   r[   r\   r^   r_   r`   ra   rb   z/cannot perform __truediv__ with this index typerc   z%datetime64 type does not support prodrd   re   rf   rg   rh   ri   |z1dtype datetime64\[ns\] does not support reductionz0datetime64 type does not support skew operationsrj   rk   /datetime64 type does not support sum operationsrl   z/datetime64 type does not support var operations)rK   rI   'z&' with datetime64 dtypes is deprecatedr   r   rm   r3   r   )r   rn   ro   rp   joinrF   )rA   r   r   rC   r+   r%   rD   rB   r?   r@   rE   ru   r   r   r   test_groupby_raises_datetime   s   
	
()*+-r   c                 C   rw   )NrG   r!   c                 S   rx   ry   r{   r   r   r   r   r|   D  r}   z.test_groupby_raises_datetime_udf.<locals>.funcrz   r4   r~   )rA   r   r   r+   r%   rB   r|   r   r   r    test_groupby_raises_datetime_udf<  r   r   c           
   	   C   s`   |}|j |d}|r|d }tjtdftjdi| \}}|r!d}	nd}	t||| ||d|	d d S )	NrG   r!   r   rJ   r   r   r   r   rn   r   rk   rp   r\   rF   )
rA   r   r   r   r+   r%   rB   r?   r@   rE   r   r   r   test_groupby_raises_datetime_npK  s   
r   r|   )rc   rQ   ri   rl   c                 C   s&   |}|j dd}ttdd|| g  d S )Nr   rG   z/timedelta64 type does not support .* operationsr6   )rn   rF   rp   )r|   r.   r%   rB   r   r   r   test_groupby_raises_timedeltac  s   r   c                 C   s  |}t ||}|j|d}|r |d }|dkr t|drJ d S i dddddddtdfd	dd
ddttfdfdttfdfdttfdfdttfdfdtdfddd|s`tdfndddddddddi dddtddd gfd!tdd"d#gfd$dd%dd&dd'td(fd)td*fd+td,fd-dd.tdd/d0gfd1dd2dd3tdd4d5gfd6tdd7d8gfd9td:fd;tdd<d=gf| \}	}
|dkr|rd>nd?}| d@}ndA}t|	|
| |||| d S )BNrG   r!   rH   rI   rJ   rK   rL   =unsupported operand type\(s\) for \*: 'Categorical' and 'int'rM   rN   rO   zz(category type does not support cummax operations|category dtype not supported|cummax is not supported for category dtype)rP   zz(category type does not support cummin operations|category dtype not supported|cummin is not supported for category dtype)rQ   z|(category type does not support cumprod operations|category dtype not supported|cumprod is not supported for category dtype)rR   zz(category type does not support cumsum operations|category dtype not supported|cumsum is not supported for category dtype)rS   zDunsupported operand type\(s\) for -: 'Categorical' and 'Categorical'rU   rV   SCannot setitem on a Categorical with a new category \(0\), set the categories firstrW   rX   rY   rZ   r[   r\   r   z2'Categorical' .* does not support reduction 'mean'2category dtype does not support aggregation 'mean'r^   z4'Categorical' .* does not support reduction 'median'4category dtype does not support aggregation 'median'r_   r`   ra   rb   zDunsupported operand type\(s\) for /: 'Categorical' and 'Categorical'rc   .category type does not support prod operationsrd   zNo matching signature foundre   rf   1'Categorical' .* does not support reduction 'sem'1category dtype does not support aggregation 'sem'rg   rh   ri   0dtype category does not support reduction 'skew'.category type does not support skew operationsrj   1'Categorical' .* does not support reduction 'std'1category dtype does not support aggregation 'std'rk   -category type does not support sum operationsrl   1'Categorical' .* does not support reduction 'var'1category dtype does not support aggregation 'var'r   r   rm   r3   )r   rn   ro   rp   rq   r   rF   )rA   r   r   rC   using_copy_on_writer2   r%   rD   rB   r?   r@   ru   rE   r   r   r   test_groupby_raises_categoryr  s2  
	
"&'./0123<EFGHLMNOXYZclmvxr   c                 C   rw   )NrG   r!   c                 S   rx   ry   r{   r   r   r   r   r|     r}   z.test_groupby_raises_category_udf.<locals>.funcrz   r4   r~   )rA   r   r   r2   r%   rB   r|   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| \}}|r#d}	nd}	t||| ||d|	d d S )	NrG   r!   r   r   r   r   r   r   r   )
rA   r   r   r   r2   r%   rB   r?   r@   rE   r   r   r   test_groupby_raises_category_np  s    
r   c                 C   sz  |}t g dg ddd|d< t||}|j||d}	|r.|	d }	|dkr.t|	dr,J d S | o<td	d
 |	j D }
|s[| dkr[t|tr[t|d t	r[|ddgkr[|
rYJ d}
| dkrad}
i dddddddt
dfdddddtt
fdfdtt
fdfdtt
fdfdtt
fdfdt
dfd dd!|st
d"fndd#dd$|
rtd%fndd&|
rtd%fndd'di d(dd)t
d*fd+t
d,fd-dd.dd/dd0t
dfd1t
d2fd3t
d4fd5dd6t
d7d8d9gfd:dd;dd<t
d7d=d>gfd?t
d7d@dAgfdBt
dCfdDt
d7dEdFgf| \}}|d!kr/|r'dGndH}| dI}nd4}t||| |	||| d S )JNr/   r   Tr0   r   )r   observedr!   rH   c                 s   s    | ]}|j V  qd S r   )empty).0groupr   r   r   	<genexpr>H  s    z;test_groupby_raises_category_on_category.<locals>.<genexpr>r<   r   r   FrI   rJ   rK   rL   r   rM   rN   rO   zz(cummax is not supported for category dtype|category dtype not supported|category type does not support cummax operations)rP   zz(cummin is not supported for category dtype|category dtype not supported|category type does not support cummin operations)rQ   z|(cumprod is not supported for category dtype|category dtype not supported|category type does not support cumprod operations)rR   zz(cumsum is not supported for category dtype|category dtype not supported|category type does not support cumsum operations)rS   rT   rU   rV   r   rW   rX   z(empty group due to unobserved categoriesrY   rZ   r[   r\   r   r^   r   r_   r`   ra   rb   rc   r   rd   r3   re   rf   r   r   r   rg   rh   ri   r   r   rj   r   r   rk   r   rl   r   r   r   r   rm   )r   r   rn   ro   rK   groupsvalues
isinstancer#   strrp   rq   rt   r   rF   )rA   r   r   rC   r   r   r2   r%   rD   rB   Zempty_groupsr?   r@   ru   rE   r   r   r   (test_groupby_raises_category_on_category-  s:  

	
"#$+,
/
23456789:;<=FGHQZ[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 s&w   Y  tjtd	d |d
  W d    d S 1 sBw   Y  d S )Nr   r
   r   )r   r   r    z+DataFrame.groupby with axis=1 is deprecatedr4   r   )Zaxisz'Cannot subset columns when using axis=1r   )r   r9   r:   r8   rn   r=   r>   rt   )r%   r@   rB   r   r   r   %test_subsetting_columns_axis_1_raises  s   
"r   )r3   )+r*   rr   numpyr   r=   Zpandasr   r   r   r   Zpandas._testingZ_testingr9   Zpandas.tests.groupbyr   Zfixturearraydictzipr"   r   r   r&   r+   r.   r2   rF   markZparametrizerv   r   rk   r\   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sx   








S

E


 

 