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   úFE:\soccer\ml_env\Lib\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©Ú
categoriesÚordered)r   r"   r   r$   r   r   r   Údf_with_cat_colS   s    ýüÿr3   Ú 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 )Nr4   ©ÚmatchÚmethodÚagg)ÚFutureWarningÚtmÚassert_produces_warningÚgetattrr8   Ú	transformÚpytestÚraises)ÚklassÚmsgÚhowÚgbÚgroupby_funcÚargsÚwarn_msgZ
warn_klassr   r   r   Ú_call_and_checkd   s    rG   rB   )r7   r8   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©Nr4   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bfillrI   Ú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]   rY   rZ   rS   rR   rc   r_   re   rb   r^   z(dtype 'str' does not support operation 'ú')r_   rc   rb   r\   ZpyarrowzBoperation 'truediv' not supported for dtype 'str' with dtype 'str'rT   z>operation 'sub' not supported for dtype 'str' with dtype 'str')rQ   rP   ÚobjectÚstrz1Cannot perform reduction 'mean' with string dtyperU   r   r   úGroupBy.fillna is deprecatedr4   )r   ÚgroupbyÚhasattrÚ	TypeErrorÚNotImplementedErrorÚreÚescapeÚ
ValueErrorZdtypeZstorageÚreplacerG   )rB   r   r   rD   r&   Úusing_infer_stringr%   rE   rC   r@   rA   ÚkindrF   r   r   r   Útest_groupby_raises_stringx   sž    
þþþþþþþþÉ;Å=




rt   r8   r=   c                 C   sd   |}|j |d�}|r|d }dd„ }tjtdd�� t|| ƒ|ƒ W d   ƒ n1 sV0    Y  d S )NrH   r!   c                 S   s   t dƒ‚d S ©NúTest error message©rl   r   r   r   r   Úfuncó   s    z,test_groupby_raises_string_udf.<locals>.funcrv   r5   ©rj   r>   r?   rl   r<   )rB   r   r   r&   r%   rC   rx   r   r   r   Útest_groupby_raises_string_udfë   s    rz   Ú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 )
NrH   r!   rJ   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   ©rF   )rj   Únprd   rY   rl   rG   )rB   r   r   r{   r&   rr   r%   rC   r@   rA   rF   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 )NrH   r!   rI   rJ   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 operationsrL   )rN   rM   rf   z&' with datetime64 dtypes is deprecatedrU   r   r   ri   r4   r~   )r   rj   rk   rl   ÚjoinrG   )rB   r   r   rD   r+   r%   rE   rC   r@   rA   rF   rs   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 )NrH   r!   c                 S   s   t dƒ‚d S ru   rw   r   r   r   r   rx   m  s    z.test_groupby_raises_datetime_udf.<locals>.funcrv   r5   ry   )rB   r   r   r+   r%   rC   rx   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 )	NrH   r!   r‚   rJ   r|   r}   r   r~   ©rj   r   rd   rl   rY   rG   )
rB   r   r   r{   r+   r%   rC   r@   rA   rF   r   r   r   Útest_groupby_raises_datetime_npt  s    
þýr‡   rx   )r]   rR   rb   re   c                 C   s&   |}|j dd�}ttdd|| g ƒ d S )Nr   rH   z/timedelta64 type does not support .* operationsr7   )rj   rG   rl   )rx   r.   r%   rC   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 )#NrH   r!   rI   rJ   ú=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'rL   rU   r   r   ri   r4   )r   rj   rk   rl   rm   rƒ   rG   )rB   r   r   rD   Úusing_copy_on_writer3   r%   rE   rC   r@   rA   rs   rF   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 )NrH   r!   c                 S   s   t dƒ‚d S ru   rw   r   r   r   r   rx   4  s    z.test_groupby_raises_category_udf.<locals>.funcrv   r5   ry   )rB   r   r   r3   r%   rC   rx   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 )	NrH   r!   r•   r‹   r|   r}   r   r~   r†   )
rB   r   r   r{   r3   r%   rC   r@   rA   rF   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!   rI   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   FrJ   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)rK   rŠ   z(empty group due to unobserved categoriesr‹   rŒ   r�   rŽ   r�   r�   r�   r’   r‘   r“   r”   r•   r–   r—   rL   rU   r   r   ri   r4   )r   r   rj   rk   rN   ÚgroupsÚvaluesÚ
isinstancer#   rh   rl   rm   rp   rƒ   rG   )rB   r   r   rD   rœ   r˜   r3   r%   rE   rC   Zempty_groupsr@   rA   rs   rF   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 deprecatedr5   r   )Zaxisz'Cannot subset columns when using axis=1r   )r   r:   r;   r9   rj   r>   r?   rp   )r%   rA   rC   r   r   r   Ú%test_subsetting_columns_axis_1_raisesî  s    ,r¥   )r4   )+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   rG   ÚmarkZparametrizert   rz   rd   rY   r€   r„   r…   r‡   rˆ   r™   rš   r›   r¤   r¥   r   r   r   r   Ú<module>   sv   
öÿ







r
#
E


 

 