U
    -eAO                     @   sv  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
 ejddgddgedddd d d d d	d
d
d
ddg	ed d d d	d
d
d
ddg	eeedd d d d	d
d
d
ddg	ed	d	d	d	d	d
d
d
d
g	ed	d	d	d	d	d
d
d
d
g	edddddddddg	gg
ddd Zejddgddd Zejddddg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dddg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dddg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dddgd,d- Zd.d/ Z dS )0    N)Categorical	DataFrameGrouperSeries)get_groupby_method_argsab)keyc                 C   s   | d S )N    xr   r   a/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/pandas/tests/groupby/test_raises.py<lambda>       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   howmethodagg	transformc           	   #   C   s  t dddddddddg	dddddddddg	tdtdd}t||}|j|d}|rz|d	 }|d
krzt|d
rvt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tdftdfddtdftdfdddtdftdftdfdt	dfddtdft	dfdtdfd"| \}}|d krr| dkrDt
|||  n,| dkr`|j|f|  n|j|f|  n`tj||dL | dkrt
|||  n,| dkr|j|f|  n|j|f|  W 5 Q R X d S )Nr   r
   r   r   r   	xyzwtyuior   r   cd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 typez#'argmax' not allowed for this dtypez#'argmin' not allowed for this dtype.Could not convert xy?z?w?t?y?u?i?o? to numericz!could not convert string to floatz0can't multiply sequence by non-int of type 'str'z,cannot be performed against 'object' dtypes!"allanyZbfillr&   countZcumcountZcummaxZcumminZcumprodZcumsumdiffZffillZfillnafirstZidxmaxZidxminlastmaxmeanZmedianminZngroupZnuniqueZ
pct_changeprodZquantileZrankZsemshiftsizeZskewZstdsumvarr   r   match)r   rangelistr   groupbyhasattrAssertionError	TypeErrorNotImplementedError
ValueErrorgetattrr   r    pytestraises	r   r   r   groupby_funcdfargsgbklassmsgr   r   r   test_groupby_raises_string*   s    
/1




rN   c                 C   s   t dddddddddg	dddddddddg	tdtdd}|j|d}|rV|d	 }d
d }tjtdd t|| | W 5 Q R X d S )Nr   r
   r   r   r   r!   r"   r%   r$   c                 S   s   t dd S NTest error messagerA   r   r   r   r   func   s    z,test_groupby_raises_string_udf.<locals>.funcrP   r:   )r   r<   r=   r>   rE   rF   rA   rD   r   r   r   rI   rK   rR   r   r   r   test_groupby_raises_string_udf   s    rT   groupby_func_npc                 C   s   t dddddddddg	dddddddddg	tdtdd}|j|d}|rV|d	 }tjd
tjtdfi| \}}|d krt|| | n(t	j
||d t|| | W 5 Q R X d S )Nr   r
   r   r   r   r!   r"   r%   r$   r'   r*   r:   )r   r<   r=   r>   npr8   r3   rA   rD   rE   rF   r   r   r   rU   rI   rK   rL   rM   r   r   r   test_groupby_raises_string_np   s*      rX   c           	   #   C   s  t dddddddddg	dddddddddg	tdtdddddd	d
d}t||}|j|d}|r|d }|dkrt|drt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fdtdfdd"| \}}|d krH| dkrt|||  n,| dkr6|j	|f|  n|j
|f|  n`tj||dL | dkrrt|||  n,| dkr|j	|f|  n|j
|f|  W 5 Q R X d S )Nr   r
   r   r   r     
         `= r"   r%   r$   r&   r'   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 prodz1dtype datetime64\[ns\] does not support reduction/datetime64 type does not support sum operationsr+   r   r   r:   )r   r<   datetimer   r>   r?   r@   rA   rD   r   r    rE   rF   rG   r   r   r   test_groupby_raises_datetime   s~    
#%




r`   c                 C   s   t dddddddddg	dddddddddg	tdtdddddd	d
d}|j|d}|rd|d }dd }tjtdd t|| | W 5 Q R X d S )Nr   r
   r   r   r   rY   rZ   r[   r\   r]   r"   r%   r$   c                 S   s   t dd S rO   rQ   r   r   r   r   rR     s    z.test_groupby_raises_datetime_udf.<locals>.funcrP   r:   )r   r<   r_   r>   rE   rF   rA   rD   rS   r   r   r    test_groupby_raises_datetime_udf   s    	ra   c                 C   s   t dddddddddg	dddddddddg	tdtdddddd	d
d}|j|d}|rd|d }tjtdftjdi| \}}|d krt|| | n(t	j
||d t|| | W 5 Q R X d S )Nr   r
   r   r   r   rY   rZ   r[   r\   r]   r"   r%   r$   r^   r'   r:   )r   r<   r_   r>   rV   r8   rA   r3   rD   rE   rF   rW   r   r   r   test_groupby_raises_datetime_np  s*      rb   c           
   #   C   s  t dddddddddg	dddddddddg	tdtdddddddddg	dddd	gd
dd}t||}|j|d}|r|d	 }|dkrt|drt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ftdfdddtdftdftdfdt	dfddtdft	dftdftdfd "| \}}	|d kr| d!krlt
|||  n,| d"kr|j|f|  n|j|f|  n`tj||	d#L | d!krt
|||  n,| d"kr|j|f|  n|j|f|  W 5 Q R X d S )$Nr   r
   r   r   r   r   r   r#   r$   T
categoriesZorderedr"   r%   r&   r'   =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 firstC'Categorical' with dtype category does not support reduction 'mean'E'Categorical' with dtype category does not support reduction 'median'zDunsupported operand type\(s\) for /: 'Categorical' and 'Categorical'.category type does not support prod operationszNo matching signature found#Cannot cast object dtype to float64C'Categorical' with dtype category does not support reduction 'skew'-category type does not support sum operationsB'Categorical' with dtype category does not support reduction 'var'r+   r   r   r:   )r   r<   r   r   r>   r?   r@   rA   rB   rC   rD   r   r    rE   rF   )
r   r   r   rH   using_copy_on_writerI   rJ   rK   rL   rM   r   r   r   test_groupby_raises_category1  s    

RT




ro   c                 C   s   t dddddddddg	dddddddddg	tdtdddddddddg	dddd	gd
dd}|j|d}|rv|d	 }dd }tjtdd t|| | W 5 Q R X d S )Nr   r
   r   r   r   r   r   r#   r$   Trc   r"   r%   c                 S   s   t dd S rO   rQ   r   r   r   r   rR     s    z.test_groupby_raises_category_udf.<locals>.funcrP   r:   )r   r<   r   r>   rE   rF   rA   rD   rS   r   r   r    test_groupby_raises_category_udf  s"    
rp   c                 C   s   t dddddddddg	dddddddddg	tdtdddddddddg	dddd	gd
dd}|j|d}|rv|d	 }tjtdftjtdfi| \}}|d krt|| | n(t	j
||d t|| | W 5 Q R X d S )Nr   r
   r   r   r   r   r   r#   r$   Trc   r"   r%   rl   rg   r:   )r   r<   r   r>   rV   r8   rA   r3   rD   rE   rF   rW   r   r   r   test_groupby_raises_category_np  s6    
 rq   c              #   C   sH  t tdddddddddg	ddddgdddddddddddg	td	tdddddddddg	ddddgddd
}t||}|j||d}|r|d }|dkrt|drt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|st
dfndd|	r&tdfnd|	r6t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fddt
dftdft
dft
d fd!"| \}
}|
d kr| d"krt|||  n,| d#kr|j|f|  n|j|f|  n`tj|
|d$L | d"krt|||  n,| d#kr*|j|f|  n|j|f|  W 5 Q R X d S )%Nr   r   r#   r$   Trc   r   r   r   r"   )r   observedr&   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>r'   re   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)r)   rf   z*attempt to get argmax of an empty sequencez*attempt to get argmin of an empty sequencerg   rh   ri   r(   rj   rk   rl   rm   r+   r   r   r:   )r   r   r<   r   r>   r?   r@   r-   groupsvaluesrA   rB   rC   rD   r   r    rE   rF   )r   r   r   rH   rr   rn   rI   rJ   rK   Zempty_groupsrL   rM   r   r   r   (test_groupby_raises_category_on_category  s    


PR




ry   c               	   C   sJ   t dgdgdgd} | jddd}tjtdd |d	  W 5 Q R X d S )
Nr   r
   r   )r   r   r#   r   )Zaxisz'Cannot subset columns when using axis=1r:   r   )r   r>   rE   rF   rC   )rI   rK   r   r   r   %test_subsetting_columns_axis_1_raisest  s    rz   )!r_   numpyrV   rE   Zpandasr   r   r   r   Zpandas.tests.groupbyr   Zfixturearraydictzipr<   r   r   markZparametrizerN   rT   r8   r3   rX   r`   ra   rb   ro   rp   rq   ry   rz   r   r   r   r   <module>   sZ   "2


U

I


"
 