o
    _~#gV                     @   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   /var/www/static.ux5.de/https/Moving-Object-Detection-with-OpenCV/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   	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   r4    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 )Nr5   matchmethodagg)FutureWarningtmassert_produces_warninggetattrr9   	transformpytestraises)klassmsghowgbgroupby_funcargswarn_msg
warn_klassr   r   r   _call_and_checkd   s2   	"rI   rC   )r8   r9   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Nr5   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 deprecatedr5   )	r   groupbyhasattr	TypeErrorNotImplementedErrorreescape
ValueErrorrI   )rC   r   r   rE   r'   r&   rF   rD   rA   rB   kindrG   r   r   r   test_groupby_raises_stringx   s   
#'()*+/01234567;=ry   r9   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 )NrJ   r"   c                 S      t dNTest error messagers   r   r   r   r   func      z,test_groupby_raises_string_udf.<locals>.funcr}   r6   rq   r?   r@   rs   r=   )rC   r   r   r'   r&   rD   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 )	NrJ   r"   rM   r`   using SeriesGroupBy.[sum|mean]!using DataFrameGroupBy.[sum|mean]r   rG   )rq   nprn   r_   rs   ru   rv   rI   )
rC   r   r   r   r'   r&   rD   rA   rB   rG   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 )8NrJ   r"   rK   rL   rM   rN   rO   z+cannot perform __mul__ with this index typerP   rQ   rR   rS   rT   z3datetime64 type does not support cumprod operationsrU   z2datetime64 type does not support cumsum operationsrV   rX   rY   rZ   r[   r\   r]   r^   r_   ra   rb   rc   rd   re   z/cannot perform __truediv__ with this index typerf   z%datetime64 type does not support prodrg   rh   ri   rj   rk   rl   |z1dtype datetime64\[ns\] does not support reductionz0datetime64 type does not support skew operationsrm   rn   /datetime64 type does not support sum operationsro   z/datetime64 type does not support var operations)rN   rL   'z&' with datetime64 dtypes is deprecatedr   r   rp   r5   r   )r   rq   rr   rs   joinrI   )rC   r   r   rE   r,   r&   rF   rD   rA   rB   rG   rx   r   r   r   test_groupby_raises_datetime   s   
	
()*+-r   c                 C   rz   )NrJ   r"   c                 S   r{   r|   r~   r   r   r   r   r   D  r   z.test_groupby_raises_datetime_udf.<locals>.funcr}   r6   r   )rC   r   r   r,   r&   rD   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 )	NrJ   r"   r   rM   r   r   r   r   rq   r   rn   rs   r_   rI   )
rC   r   r   r   r,   r&   rD   rA   rB   rG   r   r   r   test_groupby_raises_datetime_npK  s   
r   r   )rf   rT   rl   ro   c                 C   s&   |}|j dd}ttdd|| g  d S )Nr   rJ   z/timedelta64 type does not support .* operationsr8   )rq   rI   rs   )r   r/   r&   rD   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 )BNrJ   r"   rK   rL   rM   rN   rO   =unsupported operand type\(s\) for \*: 'Categorical' and 'int'rP   rQ   rR   zz(category type does not support cummax operations|category dtype not supported|cummax is not supported for category dtype)rS   zz(category type does not support cummin operations|category dtype not supported|cummin is not supported for category dtype)rT   z|(category type does not support cumprod operations|category dtype not supported|cumprod is not supported for category dtype)rU   zz(category type does not support cumsum operations|category dtype not supported|cumsum is not supported for category dtype)rV   zDunsupported operand type\(s\) for -: 'Categorical' and 'Categorical'rX   rY   SCannot setitem on a Categorical with a new category \(0\), set the categories firstrZ   r[   r\   r]   r^   r_   r   z2'Categorical' .* does not support reduction 'mean'2category dtype does not support aggregation 'mean'ra   z4'Categorical' .* does not support reduction 'median'4category dtype does not support aggregation 'median'rb   rc   rd   re   zDunsupported operand type\(s\) for /: 'Categorical' and 'Categorical'rf   .category type does not support prod operationsrg   zNo matching signature foundrh   ri   1'Categorical' .* does not support reduction 'sem'1category dtype does not support aggregation 'sem'rj   rk   rl   0dtype category does not support reduction 'skew'.category type does not support skew operationsrm   1'Categorical' .* does not support reduction 'std'1category dtype does not support aggregation 'std'rn   -category type does not support sum operationsro   1'Categorical' .* does not support reduction 'var'1category dtype does not support aggregation 'var'r   r   rp   r5   )r   rq   rr   rs   rt   r   rI   )rC   r   r   rE   using_copy_on_writer4   r&   rF   rD   rA   rB   rx   rG   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   rz   )NrJ   r"   c                 S   r{   r|   r~   r   r   r   r   r     r   z.test_groupby_raises_category_udf.<locals>.funcr}   r6   r   )rC   r   r   r4   r&   rD   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 )	NrJ   r"   r   r   r   r   r   r   r   )
rC   r   r   r   r4   r&   rD   rA   rB   rG   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 )JNr0   r    Tr1   r   )r   observedr"   rK   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   FrL   rM   rN   rO   r   rP   rQ   rR   zz(cummax is not supported for category dtype|category dtype not supported|category type does not support cummax operations)rS   zz(cummin is not supported for category dtype|category dtype not supported|category type does not support cummin operations)rT   z|(cumprod is not supported for category dtype|category dtype not supported|category type does not support cumprod operations)rU   zz(cumsum is not supported for category dtype|category dtype not supported|category type does not support cumsum operations)rV   rW   rX   rY   r   rZ   r[   z(empty group due to unobserved categoriesr\   r]   r^   r_   r   ra   r   rb   rc   rd   re   rf   r   rg   r5   rh   ri   r   r   r   rj   rk   rl   r   r   rm   r   r   rn   r   ro   r   r   r   r   rp   )r   r   rq   rr   rN   groupsvalues
isinstancer$   strrs   rt   rw   r   rI   )rC   r   r   rE   r   r   r4   r&   rF   rD   empty_groupsrA   rB   rx   rG   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 deprecatedr6   r   )axisz'Cannot subset columns when using axis=1r   )r   r;   r<   r:   rq   r?   r@   rw   )r&   rB   rD   r   r   r   %test_subsetting_columns_axis_1_raises  s   
"r   )r5   )+r+   ru   numpyr   r?   pandasr   r   r   r   pandas._testing_testingr;   pandas.tests.groupbyr   fixturearraydictzipr#   r   r   r'   r,   r/   r4   rI   markparametrizery   r   rn   r_   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sx   








S

E


 

 