a
    deR                     @   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   i/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/pandas/tests/groupby/test_raises.py<lambda>       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   s   | j S Nparamrequestr   r   r   by   s    r   TFc                 C   s   | j S 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   s   | d u rP|dkr t |||  q|dkr<|j|g|R   q|j|g|R   nttj| |dV |dkrxt |||  n.|dkr|j|g|R   n|j|g|R   W d    n1 s0    Y  d S )Nmethodaggmatch)getattrr4   	transformpytestraises)klassmsghowgbgroupby_funcargsr   r   r   _call_and_checkd   s    rA   r=   )r3   r4   r8   c           
   %   C   s  |}t ||}|j|d}|r@|d }|dkr@t|dr<J d S dddtdfddttfdfttfdfttfdfttfd	ftd
fdddddddttdfttdfdddtd
fttdftdfdtdfddtdftdfdttdfd"| \}}	t||	| ||| d S )Nr   r!   corrwithN zCould not convertzH(function|cummax) is not (implemented|supported) for (this|object) dtypezH(function|cummin) is not (implemented|supported) for (this|object) dtypezI(function|cumprod) is not (implemented|supported) for (this|object) dtypezH(function|cumsum) is not (implemented|supported) for (this|object) dtypeunsupported operand type-agg function failed [how->mean,dtype->object]z/agg function failed [how->median,dtype->object]z-agg function failed [how->prod,dtype->object]z,cannot be performed against 'object' dtypes!z!could not convert string to floatz,agg function failed [how->var,dtype->object]"allanyZbfillrC   countZcumcountZcummaxZcummincumprodZcumsumdiffZffillZfillnafirstZidxmaxZidxminlastmaxmeanZmedianminZngroupZnuniqueZ
pct_changeprodZquantileZrankZsemshiftsizeskewZstdsumvar)	r   groupbyhasattr	TypeErrorNotImplementedErrorreescape
ValueErrorrA   )
r=   r   r   r?   r&   r%   r@   r>   r;   r<   r   r   r   test_groupby_raises_stringv   s|    
;=r`   r4   r8   c                 C   sd   |}|j |d}|r|d }dd }tjtdd t|| | W d    n1 sV0    Y  d S )NrB   r!   c                 S   s   t dd S NTest error messager[   r   r   r   r   func   s    z,test_groupby_raises_string_udf.<locals>.funcrb   r5   rY   r9   r:   r[   r7   )r=   r   r   r&   r%   r>   rd   r   r   r   test_groupby_raises_string_udf   s    rf   groupby_func_npc           
      C   s   |}|j |d}|r|d }tjdtjttdfi| \}}|rHd}	nd}	tjt	|	d" t
||| ||d W d    n1 s0    Y  d S )	NrB   r!   rD   rG   using SeriesGroupBy.[sum|mean]!using DataFrameGroupBy.[sum|mean]r5   r   )rY   nprW   rQ   r[   r]   r^   tmassert_produces_warningFutureWarningrA   )
r=   r   r   rg   r&   r%   r>   r;   r<   warn_msgr   r   r   test_groupby_raises_string_np   s"    ro   c              #   C   s  |}t ||}|j|d}|r@|d }|dkr@t|dr<J d S dddtdfddddtdftdfdddddddddddddtdftd	fdddddtd
ddgfdtdftdfd"| \}}	d }
d| d}|dv rt}
tj|
|d" t||	| ||| W d    n1 s0    Y  d S )NrB   r!   rC   rD   z+cannot perform __mul__ with this index typez3datetime64 type does not support cumprod operationsz2datetime64 type does not support cumsum operationsz/cannot perform __truediv__ with this index typez%datetime64 type does not support prod|z1dtype datetime64\[ns\] does not support reductionz0datetime64 type does not support skew operations/datetime64 type does not support sum operationsz/datetime64 type does not support var operationsrH   'z&' with datetime64 dtypes is deprecated)rJ   rI   r5   )	r   rY   rZ   r[   joinrm   rk   rl   rA   )r=   r   r   r?   r+   r%   r@   r>   r;   r<   warnrn   r   r   r   test_groupby_raises_datetime   sr    
	+-ru   c                 C   sd   |}|j |d}|r|d }dd }tjtdd t|| | W d    n1 sV0    Y  d S )NrB   r!   c                 S   s   t dd S ra   rc   r   r   r   r   rd   =  s    z.test_groupby_raises_datetime_udf.<locals>.funcrb   r5   re   )r=   r   r   r+   r%   r>   rd   r   r   r    test_groupby_raises_datetime_udf5  s    rv   c           
      C   s   |}|j |d}|r|d }tjtdftjdi| \}}|rBd}	nd}	tjt|	d" t||| ||d W d    n1 s|0    Y  d S )	NrB   r!   rq   rD   rh   ri   r5   r   	rY   rj   rW   r[   rQ   rk   rl   rm   rA   )
r=   r   r   rg   r+   r%   r>   r;   r<   rn   r   r   r   test_groupby_raises_datetime_npD  s    
rx   rd   )rS   rL   rV   rX   c                 C   s&   |}|j dd}ttdd|| g  d S )Nr   rB   z/timedelta64 type does not support .* operationsr3   )rY   rA   r[   )rd   r.   r%   r>   r   r   r   test_groupby_raises_timedelta]  s    ry   c              &   C   s@  |}t ||}|j|d}|r@|d }|dkr@t|dr<J d S dddtdfddttfdfttfdfttfdfttfd	ftd
fd|stdfnddddddtdddgftdddgfdddtdftdftdfdtdddgfddtdddgftdddgftdftdddgfd"| \}	}
t|	|
| ||| d S )NrB   r!   rC   rD   =unsupported operand type\(s\) for \*: 'Categorical' and 'int'zz(category type does not support cummax operations|category dtype not supported|cummax is not supported for category dtype)zz(category type does not support cummin operations|category dtype not supported|cummin is not supported for category dtype)z|(category type does not support cumprod operations|category dtype not supported|cumprod is not supported for category dtype)zz(category type does not support cumsum operations|category dtype not supported|cumsum is not supported for category dtype)zDunsupported operand type\(s\) for -: 'Categorical' and 'Categorical'SCannot setitem on a Categorical with a new category \(0\), set the categories firstrp   z2'Categorical' .* does not support reduction 'mean'2category dtype does not support aggregation 'mean'z4'Categorical' .* does not support reduction 'median'4category dtype does not support aggregation 'median'zDunsupported operand type\(s\) for /: 'Categorical' and 'Categorical'.category type does not support prod operationszNo matching signature found1'Categorical' .* does not support reduction 'sem'1category dtype does not support aggregation 'sem'0dtype category does not support reduction 'skew'.category type does not support skew operations1'Categorical' .* does not support reduction 'std'1category dtype does not support aggregation 'std'-category type does not support sum operations1'Categorical' .* does not support reduction 'var'1category dtype does not support aggregation 'var'rH   )r   rY   rZ   r[   r\   rs   rA   )r=   r   r   r?   using_copy_on_writer2   r%   r@   r>   r;   r<   r   r   r   test_groupby_raises_categoryl  s    

		
	vxr   c                 C   sd   |}|j |d}|r|d }dd }tjtdd t|| | W d    n1 sV0    Y  d S )NrB   r!   c                 S   s   t dd S ra   rc   r   r   r   r   rd      s    z.test_groupby_raises_category_udf.<locals>.funcrb   r5   re   )r=   r   r   r2   r%   r>   rd   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| \}}|rFd}	nd}	tjt|	d" t||| ||d W d    n1 s0    Y  d S )	NrB   r!   r   r|   rh   ri   r5   r   rw   )
r=   r   r   rg   r2   r%   r>   r;   r<   rn   r   r   r   test_groupby_raises_category_np  s"    
r   c              &   C   sx  |}t g dg ddd|d< t||}|j||d}	|r\|	d }	|dkr\t|	drXJ d S td	d
 |	j D }
dddtdfddttfdfttfdfttfdfttfdftdfd|stdfndd|
rt	dfnd|
rt	dfndddtdftdfdddtdftdftdfdtd
ddgfddtd
ddgftd
ddgftd ftd
d!d"gfd#"| \}}t||| |	|| d S )$Nr/   r   Tr0   r   )r   observedr!   rC   c                 s   s   | ]}|j V  qd S r   )empty).0groupr   r   r   	<genexpr>>  r   z;test_groupby_raises_category_on_category.<locals>.<genexpr>rD   rz   zz(cummax is not supported for category dtype|category dtype not supported|category type does not support cummax operations)zz(cummin is not supported for category dtype|category dtype not supported|category type does not support cummin operations)z|(cumprod is not supported for category dtype|category dtype not supported|category type does not support cumprod operations)zz(cumsum is not supported for category dtype|category dtype not supported|category type does not support cumsum operations)rF   r{   z*attempt to get argmax of an empty sequencez*attempt to get argmin of an empty sequencer|   r}   r~   rE   rp   r   r   r   r   r   r   r   r   r   rH   )r   r   rY   rZ   rJ   groupsvaluesr[   r\   r_   rs   rA   )r=   r   r   r?   r   r   r2   r%   r@   r>   Zempty_groupsr;   r<   r   r   r   (test_groupby_raises_category_on_category#  s    



	
	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 sL0    Y  tjtd	d |d
  W d    n1 s0    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   rk   rl   rm   rY   r9   r:   r_   )r%   r<   r>   r   r   r   %test_subsetting_columns_axis_1_raises  s    ,r   )+r*   r]   numpyrj   r9   Zpandasr   r   r   r   Zpandas._testingZ_testingrk   Zpandas.tests.groupbyr   Zfixturearraydictzipr"   r   r   r&   r+   r.   r2   rA   markZparametrizer`   rf   rW   rQ   ro   ru   rv   rx   ry   r   r   r   r   r   r   r   r   r   <module>   sv   







N

D


 

 