o
    $j\                     @   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   a/var/www/html/Deteccion_Ine/venv/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
categoriesordered)r   r"   r   r$   r   r   r   df_with_cat_colS   s   r3    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 )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   s2   	"rG   rB   )r7   r8   r=   c                 C   sH  |}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| \}	}
|r|d2v rd3| d4}
|d5v rt}	n0|d#kr|d jj	d6krd7}
n!|dkr|d jj	d6krd8}
n|d9v r|

d:d;}
n|dkrd<}
|dkr|rd=nd>}| d?}nd@}t|	|
| |||| d S )ANr   r!   corrwithallNr4   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meanz-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]quantilez4dtype 'object' does not support operation 'quantile'ranksemz!could not convert string to floatshiftsizeskewstdsumvarz%agg function failed [how->var,dtype->)
rc   r]   r^   rS   rR   rj   rf   rl   ri   rd   z(dtype 'str' does not support operation '')rf   rj   ri   ZpyarrowzBoperation 'truediv' not supported for dtype 'str' with dtype 'str'z>operation 'sub' not supported for dtype 'str' with dtype 'str')rQ   rP   objectstrz1Cannot perform reduction 'mean' with string dtyper   r   GroupBy.fillna is deprecatedr4   )r   groupbyhasattr	TypeErrorNotImplementedErrorreescape
ValueErrorZdtypeZstoragereplacerG   )rB   r   r   rD   r&   using_infer_stringr%   rE   rC   r@   rA   kindrF   r   r   r   test_groupby_raises_stringx   s   
#'()*+/01234567;=

r{   r8   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 )NrH   r!   c                 S      t dNTest error messagers   r   r   r   r   func      z,test_groupby_raises_string_udf.<locals>.funcr   r5   rq   r>   r?   rs   r<   )rB   r   r   r&   r%   rC   r   r   r   r   test_groupby_raises_string_udf      "r   groupby_func_npc              	   C   sv   |}|j |d}|r|d }tjdtjtdfi| \}}	|r'|tju r%t}d}	|r,d}
nd}
t||	| ||d|
d	 d S )
NrH   r!   rK   zEagg function failed|Cannot perform reduction 'mean' with string dtypez-dtype 'str' does not support operation 'mean'using SeriesGroupBy.[sum|mean]!using DataFrameGroupBy.[sum|mean]r   rF   )rq   nprk   r]   rs   rG   )rB   r   r   r   r&   ry   r%   rC   r@   rA   rF   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 )8NrH   r!   rI   rJ   rK   rL   rM   z+cannot perform __mul__ with this index typerN   rO   rP   rQ   rR   z3datetime64 type does not support cumprod operationsrS   z2datetime64 type does not support cumsum operationsrT   rV   rW   rX   rY   rZ   r[   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)rL   rJ   rm   z&' with datetime64 dtypes is deprecatedr   r   rp   r4   r   )r   rq   rr   rs   joinrG   )rB   r   r   rD   r+   r%   rE   rC   r@   rA   rF   rz   r   r   r   test_groupby_raises_datetime  s   
	
()*+-r   c                 C   r|   )NrH   r!   c                 S   r}   r~   r   r   r   r   r   r   m  r   z.test_groupby_raises_datetime_udf.<locals>.funcr   r5   r   )rB   r   r   r+   r%   rC   r   r   r   r    test_groupby_raises_datetime_udfe  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 )	NrH   r!   r   rK   r   r   r   r   rq   r   rk   rs   r]   rG   )
rB   r   r   r   r+   r%   rC   r@   rA   rF   r   r   r   test_groupby_raises_datetime_npt  s   
r   r   )rc   rR   ri   rl   c                 C   s&   |}|j dd}ttdd|| g  d S )Nr   rH   z/timedelta64 type does not support .* operationsr7   )rq   rG   rs   )r   r.   r%   rC   r   r   r   test_groupby_raises_timedelta  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 )BNrH   r!   rI   rJ   rK   rL   rM   =unsupported operand type\(s\) for \*: 'Categorical' and 'int'rN   rO   rP   zz(category type does not support cummax operations|category dtype not supported|cummax is not supported for category dtype)rQ   zz(category type does not support cummin operations|category dtype not supported|cummin is not supported for category dtype)rR   z|(category type does not support cumprod operations|category dtype not supported|cumprod is not supported for category dtype)rS   zz(category type does not support cumsum operations|category dtype not supported|cumsum is not supported for category dtype)rT   zDunsupported operand type\(s\) for -: 'Categorical' and 'Categorical'rV   rW   SCannot setitem on a Categorical with a new category \(0\), set the categories firstrX   rY   rZ   r[   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   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   rp   r4   )r   rq   rr   rs   rt   r   rG   )rB   r   r   rD   using_copy_on_writer3   r%   rE   rC   r@   rA   rz   rF   r   r   r   test_groupby_raises_category  s2  
	
"&'./0123<EFGHLMNOXYZclmvxr   c                 C   r|   )NrH   r!   c                 S   r}   r~   r   r   r   r   r   r   4  r   z.test_groupby_raises_category_udf.<locals>.funcr   r5   r   )rB   r   r   r3   r%   rC   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 )	NrH   r!   r   r   r   r   r   r   r   )
rB   r   r   r   r3   r%   rC   r@   rA   rF   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dJ}t||| |	||| d S )KNr/   r   Tr0   r   )r   observedr!   rI   c                 s   s    | ]}|j V  qd S r   )empty).0groupr   r   r   	<genexpr>q  s    z;test_groupby_raises_category_on_category.<locals>.<genexpr>r=   r   r   FrJ   rK   rL   rM   r   rN   rO   rP   zz(cummax is not supported for category dtype|category dtype not supported|category type does not support cummax operations)rQ   zz(cummin is not supported for category dtype|category dtype not supported|category type does not support cummin operations)rR   z|(cumprod is not supported for category dtype|category dtype not supported|category type does not support cumprod operations)rS   zz(cumsum is not supported for category dtype|category dtype not supported|category type does not support cumsum operations)rT   rU   rV   rW   r   rX   rY   z(empty group due to unobserved categoriesrZ   r[   r\   r]   r   r^   r   r_   r`   ra   rb   rc   r   rd   r   re   rf   r   r   r   rg   rh   ri   r   r   rj   r   r   rk   r   rl   r   r   r   r   rp   r4   )r   r   rq   rr   rL   groupsvalues
isinstancer#   ro   rs   rt   rw   r   rG   )rB   r   r   rD   r   r   r3   r%   rE   rC   Zempty_groupsr@   rA   rz   rF   r   r   r   (test_groupby_raises_category_on_categoryV  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 deprecatedr5   r   )Zaxisz'Cannot subset columns when using axis=1r   )r   r:   r;   r9   rq   r>   r?   rw   )r%   rA   rC   r   r   r   %test_subsetting_columns_axis_1_raises  s   
"r   )r4   )+r*   ru   numpyr   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parametrizer{   r   rk   r]   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sx   








r
#
E


 

 