a
    é´«jÔ\  ã                   @   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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 d0g d1¢¡d2d3„ ƒZ%ej dg d ¢¡d4d5„ ƒZ&ej dd#d$g¡d6d7„ ƒZ'ej dd#d$g¡ej d'ejej g¡d8d9„ ƒƒZ(ej dg d ¢¡d:d;„ ƒ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/laksyashrimp/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krd nt }tj||d��Ô | d u rp|dkr@t||ƒ|Ž  qä|dkr\|j|g|¢R Ž  qä|j|g|¢R Ž  nttj| |d��V |dkr˜t||ƒ|Ž  n.|dkr´|j|g|¢R Ž  n|j|g|¢R Ž  W d   ƒ n1 sÚ0    Y  W d   ƒ n1 sø0    Y  d S )Nr3   ©ÚmatchÚmethodÚagg)ÚFutureWarningÚtmÚassert_produces_warningÚgetattrr7   Ú	transformÚpytestÚraises)ÚklassÚmsgÚhowÚgbÚgroupby_funcÚargsÚwarn_msgZ
warn_klassr   r   r   Ú_call_and_checkd   s    rF   rA   )r6   r7   r<   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œ"| \}	}
|�rŒ|dv �r"d|› d�}
|dv �rŒt}	nj|dk�rD|d jj	dk�rDd}
nH|dk�rf|d jj	dk�rfd}
n&|dv �r~|
 
dd¡}
n|dk�rŒd}
|dk�r°|�r d nd!}|› d"�}nd#}t|	|
| ||||ƒ d S )$N©r   r!   Úcorrwith©Nr3   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-agg function failed [how->mean,dtype->object]z/agg function failed [how->median,dtype->object]z-agg function failed [how->prod,dtype->object]z4dtype 'object' does not support operation 'quantile'z!could not convert string to floatz%agg function failed [how->var,dtype->©"ÚallÚanyZbfillrH   ÚcountZcumcountÚcummaxÚcumminÚcumprodÚcumsumÚdiffZffillÚfillnaÚfirstZidxmaxZidxminÚlastÚmaxÚmeanÚmedianÚminZngroupZnuniqueÚ
pct_changeÚprodÚquantileZrankÚsemÚshiftÚsizeÚskewÚstdÚsumÚvar)
r\   rX   rY   rR   rQ   rb   r^   rd   ra   r]   z(dtype 'str' does not support operation 'ú')r^   rb   ra   r[   ZpyarrowzBoperation 'truediv' not supported for dtype 'str' with dtype 'str'rS   z>operation 'sub' not supported for dtype 'str' with dtype 'str')rP   rO   ÚobjectÚstrz1Cannot perform reduction 'mean' with string dtyperT   r   r   úGroupBy.fillna is deprecatedr3   )r   ÚgroupbyÚhasattrÚ	TypeErrorÚNotImplementedErrorÚreÚescapeÚ
ValueErrorZdtypeZstorageÚreplacerF   )rA   r   r   rC   r&   Úusing_infer_stringr%   rD   rB   r?   r@   ÚkindrE   r   r   r   Útest_groupby_raises_stringx   sž    
þþþþþþþþÉ;Å=




rs   r7   r<   c                 C   sd   |}|j |d�}|r|d }dd„ }tjtdd�� t|| ƒ|ƒ W d   ƒ n1 sV0    Y  d S )NrG   r!   c                 S   s   t dƒ‚d S ©NúTest error message©rk   r   r   r   r   Úfuncó   s    z,test_groupby_raises_string_udf.<locals>.funcru   r4   ©ri   r=   r>   rk   r;   )rA   r   r   r&   r%   rB   rw   r   r   r   Útest_groupby_raises_string_udfë   s    ry   Úgroupby_func_npc              	   C   sv   |}|j |d�}|r|d }tjdtjtdfi| \}}	|rN|tju rJt}d}	|rXd}
nd}
t||	| ||d|
d	� d S )
NrG   r!   rI   zEagg function failed|Cannot perform reduction 'mean' with string dtypez-dtype 'str' does not support operation 'mean'úusing SeriesGroupBy.[sum|mean]ú!using DataFrameGroupBy.[sum|mean]r   ©rE   )ri   Únprc   rX   rk   rF   )rA   r   r   rz   r&   rq   r%   rB   r?   r@   rE   r   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 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v rÒd|› d�}
n$|dkrò|râdnd}|› d�}
nd}
t||	| ||||
d� d S )NrG   r!   rH   rI   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 operationsrK   )rM   rL   re   z&' with datetime64 dtypes is deprecatedrT   r   r   rh   r3   r}   )r   ri   rj   rk   ÚjoinrF   )rA   r   r   rC   r+   r%   rD   rB   r?   r@   rE   rr   r   r   r   Útest_groupby_raises_datetime  st    
þÿþ	Ö+Õ-rƒ   c                 C   sd   |}|j |d�}|r|d }dd„ }tjtdd�� t|| ƒ|ƒ W d   ƒ n1 sV0    Y  d S )NrG   r!   c                 S   s   t dƒ‚d S rt   rv   r   r   r   r   rw   m  s    z.test_groupby_raises_datetime_udf.<locals>.funcru   r4   rx   )rA   r   r   r+   r%   rB   rw   r   r   r   Ú test_groupby_raises_datetime_udfe  s    r„   c           
   	   C   s`   |}|j |d�}|r|d }tjtdftjdi| \}}|rBd}	nd}	t||| ||d|	d� d S )	NrG   r!   r�   rI   r{   r|   r   r}   ©ri   r~   rc   rk   rX   rF   )
rA   r   r   rz   r+   r%   rB   r?   r@   rE   r   r   r   Útest_groupby_raises_datetime_npt  s    
þýr†   rw   )r\   rQ   ra   rd   c                 C   s&   |}|j dd�}ttdd|| g ƒ d S )Nr   rG   z/timedelta64 type does not support .* operationsr6   )ri   rF   rk   )rw   r.   r%   rB   r   r   r   Útest_groupby_raises_timedeltaŒ  s    úr‡   c              &   C   sj  |}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|sŒt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œ"| \}	}
|dk�rN|�r>dnd }|› d!�}nd"}t|	|
| ||||ƒ d S )#NrG   r!   rH   rI   ú=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 firstr€   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 operationsúNo matching signature foundú1'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 operationsú1'Categorical' .* does not support reduction 'std'ú1category dtype does not support aggregation 'std'ú-category type does not support sum operationsú1'Categorical' .* does not support reduction 'var'ú1category dtype does not support aggregation 'var'rK   rT   r   r   rh   r3   )r   ri   rj   rk   rl   r‚   rF   )rA   r   r   rC   Úusing_copy_on_writer2   r%   rD   rB   r?   r@   rr   rE   r   r   r   Útest_groupby_raises_category›  sÒ    
þþþþþþûþþÿþ
þÿþ	þþÿþ	þÿþ
þÿþ	þÿþ“vŠx
r˜   c                 C   sd   |}|j |d�}|r|d }dd„ }tjtdd�� t|| ƒ|ƒ W d   ƒ n1 sV0    Y  d S )NrG   r!   c                 S   s   t dƒ‚d S rt   rv   r   r   r   r   rw   4  s    z.test_groupby_raises_category_udf.<locals>.funcru   r4   rx   )rA   r   r   r2   r%   rB   rw   r   r   r   Ú test_groupby_raises_category_udf+  s    r™   c           
   	   C   sd   |}|j |d�}|r|d }tjtdftjtdfi| \}}|rFd}	nd}	t||| ||d|	d� d S )	NrG   r!   r”   rŠ   r{   r|   r   r}   r…   )
rA   r   r   rz   r2   r%   rB   r?   r@   rE   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ƒrXJ ‚d S | oxtd	d
„ |	j ¡ D ƒƒ}
|s¶| dkr¶t|tƒr¶t|d t	ƒr¶|ddgkr¶|
r²J ‚d}
| dkrÂ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|
�r2t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&œ"| \}}|d'k�rÚ|�rÊd(nd)}|› d*�}nd+}t||| |	|||ƒ d S ),Nr/   r   Tr0   r   )r   Úobservedr!   rH   c                 s   s   | ]}|j V  qd S r   )Úempty)Ú.0Úgroupr   r   r   Ú	<genexpr>q  r   z;test_groupby_raises_category_on_category.<locals>.<genexpr>r<   r   r   FrI   rˆ   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)rJ   r‰   z(empty group due to unobserved categoriesrŠ   r‹   rŒ   r�   r€   rŽ   r�   r‘   r�   r’   r“   r”   r•   r–   rK   rT   r   r   rh   r3   )r   r   ri   rj   rM   ÚgroupsÚvaluesÚ
isinstancer#   rg   rk   rl   ro   r‚   rF   )rA   r   r   rC   r›   r—   r2   r%   rD   rB   Zempty_groupsr?   r@   rr   rE   r   r   r   Ú(test_groupby_raises_category_on_categoryV  sâ    ý

ÿþýü
ûþþþþþûþÿÿþÿþ	þÿþ
þÿþ	þÿþ¥dœf
r£   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 s‚0    Y  d S )Nr   r
   r   )r   r   r    z+DataFrame.groupby with axis=1 is deprecatedr4   r   )Zaxisz'Cannot subset columns when using axis=1r   )r   r9   r:   r8   ri   r=   r>   ro   )r%   r@   rB   r   r   r   Ú%test_subsetting_columns_axis_1_raisesî  s    ,r¤   )r3   )+r*   rm   Únumpyr~   r=   Zpandasr   r   r   r   Zpandas._testingZ_testingr9   Zpandas.tests.groupbyr   ZfixtureÚarrayÚdictÚzipr"   r   r   r&   r+   r.   r2   rF   ÚmarkZparametrizers   ry   rc   rX   r   rƒ   r„   r†   r‡   r˜   r™   rš   r£   r¤   r   r   r   r   Ú<module>   sv   
öÿ







r
#
E


 

 