U
    ¾mœdAO  ã                   @   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   úY/home/sam/Atlas/atlas_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�rœt
||ƒ|Ž  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rŠt|| ƒ|ƒ 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rˆt|dƒr„t‚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r˜t|| ƒ|ƒ 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ršt|dƒr–t‚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|sæt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�rÄt
||ƒ|Ž  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 firstúC'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 float64úC'Categorical' with dtype category does not support reduction 'skew'ú-category type does not support sum operationsúB'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r®t|| ƒ|ƒ 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r®t|dƒrªt‚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�r¶t||ƒ|Ž  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


"
 