o
    TieR                     @   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   `/var/www/html/evchargy.com/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   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)getattrr5   	transformpytestraises)klassmsghowgbgroupby_funcargsr   r   r   _call_and_checkd   s"   "rB   r>   )r4   r5   r9   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
ValueErrorrB   )
r>   r   r   r@   r&   r%   rA   r?   r<   r=   r   r   r   test_groupby_raises_stringv   s   
#'()*+/01234567;=rq   r5   r9   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 )NrC   r!   c                 S      t dNTest error messagerl   r   r   r   r   func      z,test_groupby_raises_string_udf.<locals>.funcru   r6   rj   r:   r;   rl   r8   )r>   r   r   r&   r%   r?   rw   r   r   r   test_groupby_raises_string_udf      "rz   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 )	NrC   r!   rF   rZ   using SeriesGroupBy.[sum|mean]!using DataFrameGroupBy.[sum|mean]r6   r   )rj   nprh   rY   rl   rn   ro   tmassert_produces_warningFutureWarningrB   )
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 )4NrC   r!   rD   rE   rF   rH   rI   z+cannot perform __mul__ with this index typerJ   rK   rL   rM   rN   z3datetime64 type does not support cumprod operationsrO   z2datetime64 type does not support cumsum operationsrP   rR   rS   rT   rU   rV   rW   rX   rY   r[   r\   r]   r^   r_   z/cannot perform __truediv__ with this index typer`   z%datetime64 type does not support prodra   rb   rc   rd   re   rf   |z1dtype datetime64\[ns\] does not support reductionz0datetime64 type does not support skew operationsrg   rh   /datetime64 type does not support sum operationsri   z/datetime64 type does not support var operations'z&' with datetime64 dtypes is deprecated)rH   rE   r6   )	r   rj   rk   rl   joinr   r   r   rB   )r>   r   r   r@   r+   r%   rA   r?   r<   r=   warnr   r   r   r   test_groupby_raises_datetime   s   
	
()*+-"r   c                 C   rr   )NrC   r!   c                 S   rs   rt   rv   r   r   r   r   rw   =  rx   z.test_groupby_raises_datetime_udf.<locals>.funcru   r6   ry   )r>   r   r   r+   r%   r?   rw   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 )	NrC   r!   r   rF   r}   r~   r6   r   	rj   r   rh   rl   rY   r   r   r   rB   )
r>   r   r   r|   r+   r%   r?   r<   r=   r   r   r   r   test_groupby_raises_datetime_npD  s   
"r   rw   )r`   rN   rf   ri   c                 C   s&   |}|j dd}ttdd|| g  d S )Nr   rC   z/timedelta64 type does not support .* operationsr4   )rj   rB   rl   )rw   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 )>NrC   r!   rD   rE   rF   rH   rI   =unsupported operand type\(s\) for \*: 'Categorical' and 'int'rJ   rK   rL   zz(category type does not support cummax operations|category dtype not supported|cummax is not supported for category dtype)rM   zz(category type does not support cummin operations|category dtype not supported|cummin is not supported for category dtype)rN   z|(category type does not support cumprod operations|category dtype not supported|cumprod is not supported for category dtype)rO   zz(category type does not support cumsum operations|category dtype not supported|cumsum is not supported for category dtype)rP   zDunsupported operand type\(s\) for -: 'Categorical' and 'Categorical'rR   rS   SCannot setitem on a Categorical with a new category \(0\), set the categories firstrT   rU   rV   rW   rX   rY   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'r`   .category type does not support prod operationsra   zNo matching signature foundrb   rc   1'Categorical' .* does not support reduction 'sem'1category dtype does not support aggregation 'sem'rd   re   rf   0dtype category does not support reduction 'skew'.category type does not support skew operationsrg   1'Categorical' .* does not support reduction 'std'1category dtype does not support aggregation 'std'rh   -category type does not support sum operationsri   1'Categorical' .* does not support reduction 'var'1category dtype does not support aggregation 'var')r   rj   rk   rl   rm   r   rB   )r>   r   r   r@   using_copy_on_writer3   r%   rA   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   rr   )NrC   r!   c                 S   rs   rt   rv   r   r   r   r   rw      rx   z.test_groupby_raises_category_udf.<locals>.funcru   r6   ry   )r>   r   r   r3   r%   r?   rw   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 )	NrC   r!   r   r   r}   r~   r6   r   r   )
r>   r   r   r|   r3   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 )DNr/   r   Tr0   r   )r   observedr!   rD   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>rE   rF   rH   rI   r   rJ   rK   rL   zz(cummax is not supported for category dtype|category dtype not supported|category type does not support cummax operations)rM   zz(cummin is not supported for category dtype|category dtype not supported|category type does not support cummin operations)rN   z|(cumprod is not supported for category dtype|category dtype not supported|category type does not support cumprod operations)rO   zz(cumsum is not supported for category dtype|category dtype not supported|category type does not support cumsum operations)rP   rQ   rR   rS   r   rT   rU   z*attempt to get argmax of an empty sequencerV   z*attempt to get argmin of an empty sequencerW   rX   rY   r   r[   r   r\   r]   r^   r_   r`   r   ra   rG   rb   rc   r   r   r   rd   re   rf   r   r   rg   r   r   rh   r   ri   r   r   )r   r   rj   rk   rH   groupsvaluesrl   rm   rp   r   rB   )r>   r   r   r@   r   r   r3   r%   rA   r?   Z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 deprecatedr6   r   )Zaxisz'Cannot subset columns when using axis=1r   )r   r   r   r   rj   r:   r;   rp   )r%   r=   r?   r   r   r   %test_subsetting_columns_axis_1_raises  s   
"r   )+r*   rn   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   rB   markZparametrizerq   rz   rh   rY   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sx   







N

D


 

 