o
    ҷheR                     @   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 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d/g d0d1d2 Z%ejdg dd3d4 Z&ejdd"d#gd5d6 Z'ejdd"d#gejd&ejej gd7d8 Z(ejdg dd9d: 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   S/var/www/html/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   	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   s   | d u r+|dkrt |||  d S |dkr |j|g|R   d S |j|g|R   d S tj| |d< |dkr?t |||  n|dkrM|j|g|R   n|j|g|R   W d    d S W d    d S W d    d S 1 sqw   Y  d S )Nmethodaggmatch)getattrr6   	transformpytestraises)klassmsghowgbgroupby_funcargsr   r   r   _call_and_checkd   s"   "rC   r?   )r5   r6   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| \}}	t||	| ||| d S )2Nr   r"   corrwithallN 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->object])	r   groupbyhasattr	TypeErrorNotImplementedErrorreescape
ValueErrorrC   )
r?   r   r   rA   r'   r&   rB   r@   r=   r>   r   r   r   test_groupby_raises_stringv   s   
#'()*+/01234567;=rr   r6   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 )NrD   r"   c                 S      t dNTest error messagerm   r   r   r   r   func      z,test_groupby_raises_string_udf.<locals>.funcrv   r7   rk   r;   r<   rm   r9   )r?   r   r   r'   r&   r@   rx   r   r   r   test_groupby_raises_string_udf      "r{   groupby_func_npc           
      C   s   |}|j |d}|r|d }tjdtjttdfi| \}}|r$d}	nd}	tjt	|	d t
||| ||d W d    d S 1 sBw   Y  d S )	NrD   r"   rG   r[   using SeriesGroupBy.[sum|mean]!using DataFrameGroupBy.[sum|mean]r7   r   )rk   npri   rZ   rm   ro   rp   tmassert_produces_warningFutureWarningrC   )
r?   r   r   r}   r'   r&   r@   r=   r>   warn_msgr   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| \}}	d }
d0| d1}|d2v rt}
tj|
|d3 t||	| ||| W d    d S 1 sw   Y  d S )4NrD   r"   rE   rF   rG   rI   rJ   z+cannot perform __mul__ with this index typerK   rL   rM   rN   rO   z3datetime64 type does not support cumprod operationsrP   z2datetime64 type does not support cumsum operationsrQ   rS   rT   rU   rV   rW   rX   rY   rZ   r\   r]   r^   r_   r`   z/cannot perform __truediv__ with this index typera   z%datetime64 type does not support prodrb   rc   rd   re   rf   rg   |z1dtype datetime64\[ns\] does not support reductionz0datetime64 type does not support skew operationsrh   ri   /datetime64 type does not support sum operationsrj   z/datetime64 type does not support var operations'z&' with datetime64 dtypes is deprecated)rI   rF   r7   )	r   rk   rl   rm   joinr   r   r   rC   )r?   r   r   rA   r,   r&   rB   r@   r=   r>   warnr   r   r   r   test_groupby_raises_datetime   s   
	
()*+-"r   c                 C   rs   )NrD   r"   c                 S   rt   ru   rw   r   r   r   r   rx   =  ry   z.test_groupby_raises_datetime_udf.<locals>.funcrv   r7   rz   )r?   r   r   r,   r&   r@   rx   r   r   r    test_groupby_raises_datetime_udf5  r|   r   c           
      C   s   |}|j |d}|r|d }tjtdftjdi| \}}|r!d}	nd}	tjt|	d t||| ||d W d    d S 1 s?w   Y  d S )	NrD   r"   r   rG   r~   r   r7   r   	rk   r   ri   rm   rZ   r   r   r   rC   )
r?   r   r   r}   r,   r&   r@   r=   r>   r   r   r   r   test_groupby_raises_datetime_npD  s   
"r   rx   )ra   rO   rg   rj   c                 C   s&   |}|j dd}ttdd|| g  d S )Nr   rD   z/timedelta64 type does not support .* operationsr5   )rk   rC   rm   )rx   r/   r&   r@   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| \}	}
t|	|
| ||| d S )>NrD   r"   rE   rF   rG   rI   rJ   =unsupported operand type\(s\) for \*: 'Categorical' and 'int'rK   rL   rM   zz(category type does not support cummax operations|category dtype not supported|cummax is not supported for category dtype)rN   zz(category type does not support cummin operations|category dtype not supported|cummin is not supported for category dtype)rO   z|(category type does not support cumprod operations|category dtype not supported|cumprod is not supported for category dtype)rP   zz(category type does not support cumsum operations|category dtype not supported|cumsum is not supported for category dtype)rQ   zDunsupported operand type\(s\) for -: 'Categorical' and 'Categorical'rS   rT   SCannot setitem on a Categorical with a new category \(0\), set the categories firstrU   rV   rW   rX   rY   rZ   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^   r_   r`   zDunsupported operand type\(s\) for /: 'Categorical' and 'Categorical'ra   .category type does not support prod operationsrb   zNo matching signature foundrc   rd   1'Categorical' .* does not support reduction 'sem'1category dtype does not support aggregation 'sem're   rf   rg   0dtype category does not support reduction 'skew'.category type does not support skew operationsrh   1'Categorical' .* does not support reduction 'std'1category dtype does not support aggregation 'std'ri   -category type does not support sum operationsrj   1'Categorical' .* does not support reduction 'var'1category dtype does not support aggregation 'var')r   rk   rl   rm   rn   r   rC   )r?   r   r   rA   using_copy_on_writer4   r&   rB   r@   r=   r>   r   r   r   test_groupby_raises_categoryl  s*  
	
"&'./0123<EFGHLMNOXYZclmvxr   c                 C   rs   )NrD   r"   c                 S   rt   ru   rw   r   r   r   r   rx      ry   z.test_groupby_raises_category_udf.<locals>.funcrv   r7   rz   )r?   r   r   r4   r&   r@   rx   r   r   r    test_groupby_raises_category_udf  s   "r   c           
      C   s   |}|j |d}|r|d }tjtdftjtdfi| \}}|r#d}	nd}	tjt|	d t||| ||d W d    d S 1 sAw   Y  d S )	NrD   r"   r   r   r~   r   r7   r   r   )
r?   r   r   r}   r4   r&   r@   r=   r>   r   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r,J d S td	d
 |	j D }
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|szt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d-tdfd.td/fd0td1fd2dd3td4
d5d6gfd7dd8dd9td4
d:d;gfd<td4
d=d>gfd?td@fdAtd4
dBdCgf| \}}t||| |	|| d S )DNr0   r    Tr1   r   )r   observedr"   rE   c                 s   s    | ]}|j V  qd S r   )empty).0groupr   r   r   	<genexpr>>  s    z;test_groupby_raises_category_on_category.<locals>.<genexpr>rF   rG   rI   rJ   r   rK   rL   rM   zz(cummax is not supported for category dtype|category dtype not supported|category type does not support cummax operations)rN   zz(cummin is not supported for category dtype|category dtype not supported|category type does not support cummin operations)rO   z|(cumprod is not supported for category dtype|category dtype not supported|category type does not support cumprod operations)rP   zz(cumsum is not supported for category dtype|category dtype not supported|category type does not support cumsum operations)rQ   rR   rS   rT   r   rU   rV   z*attempt to get argmax of an empty sequencerW   z*attempt to get argmin of an empty sequencerX   rY   rZ   r   r\   r   r]   r^   r_   r`   ra   r   rb   rH   rc   rd   r   r   r   re   rf   rg   r   r   rh   r   r   ri   r   rj   r   r   )r   r   rk   rl   rI   groupsvaluesrm   rn   rq   r   rC   )r?   r   r   rA   r   r   r4   r&   rB   r@   empty_groupsr=   r>   r   r   r   (test_groupby_raises_category_on_category#  s  

	
"#$+,
/
23456789:;<=FGHQZ[dfr   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 deprecatedr7   r   )axisz'Cannot subset columns when using axis=1r   )r   r   r   r   rk   r;   r<   rq   )r&   r>   r@   r   r   r   %test_subsetting_columns_axis_1_raises  s   
"r   )+r+   ro   numpyr   r;   pandasr   r   r   r   pandas._testing_testingr   pandas.tests.groupbyr   fixturearraydictzipr#   r   r   r'   r,   r/   r4   rC   markparametrizerr   r{   ri   rZ   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sx   







N

D


 

 