o
    Û­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/CropPilot/venv/lib/python3.10/site-packages/pandas/tests/groupby/test_raises.pyÚ<lambda>   s    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   ó   | j S ©N©Úparam©Úrequestr   r   r   Úby   s   r   TFc                 C   r   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   Ú	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   ýüÿr4   Ú c              	   C   sH  |dkrd nt }tj||d��‹ | d u r8|dkr t||ƒ|Ž  nb|dkr.|j|g|¢R Ž  n\|j|g|¢R Ž  nBtj| |d��+ |dkrLt||ƒ|Ž  n|dkrZ|j|g|¢R Ž  n	|j|g|¢R Ž  W d   ƒ n(1 smw   Y  W d   ƒ d S W d   ƒ d S W d   ƒ d S W d   ƒ d S W d   ƒ d S 1 s�w   Y  d S )Nr5   ©ÚmatchÚmethodÚagg)ÚFutureWarningÚtmÚassert_produces_warningÚgetattrr9   Ú	transformÚpytestÚraises)ÚklassÚmsgÚhowÚgbÚgroupby_funcÚargsÚwarn_msgÚ
warn_klassr   r   r   Ú_call_and_checkd   s2   €ú÷ùýû	"÷rI   rC   )r8   r9   r>   c                 C   sH  |}t ||ƒ}|j|d�}|r |d }|dkr t|dƒrJ ‚d S i dd“dd“dd“dtdf“d	d“d
d“dttfdf“dttfdf“dttfdf“dttfdf“dtdf“dd“dd“dd“dd“dd“dd“i dd“dtt d¡f“dtt d¡f“d d“d!d“d"d“d#tdf“d$tt d%¡f“d&td'f“d(d“d)td*f“d+d“d,d“d-td*f“d.td*f“d/d“d0tt d1¡f“¥| \}	}
|�r|d2v rÔd3|› d4�}
|d5v rÓt}	n0|d#krã|d jj	d6krãd7}
n!|dkrò|d jj	d6kròd8}
n|d9v rý|
 
d:d;¡}
n|dk�rd<}
|dk�r|�rd=nd>}|› d?�}nd@}t|	|
| ||||ƒ d S )AN©r   r"   ÚcorrwithÚall©Nr5   ÚanyÚbfillzCould not convertÚcountÚcumcountÚcummaxzH(function|cummax) is not (implemented|supported) for (this|object) dtypeÚcumminzH(function|cummin) is not (implemented|supported) for (this|object) dtypeÚcumprodzI(function|cumprod) is not (implemented|supported) for (this|object) dtypeÚcumsumzH(function|cumsum) is not (implemented|supported) for (this|object) dtypeÚdiffúunsupported operand typeÚffillÚfillnaÚfirstÚidxmaxÚidxminÚlastÚmaxÚmeanz-agg function failed [how->mean,dtype->object]Úmedianz/agg function failed [how->median,dtype->object]ÚminÚngroupÚnuniqueÚ
pct_changeÚprodz-agg function failed [how->prod,dtype->object]Úquantilez4dtype 'object' does not support operation 'quantile'ÚrankÚsemz!could not convert string to floatÚshiftÚsizeÚskewÚstdÚsumÚvarz%agg function failed [how->var,dtype->)
re   r_   r`   rU   rT   rl   rh   rn   rk   rf   z(dtype 'str' does not support operation 'ú')rh   rl   rk   ÚpyarrowzBoperation 'truediv' not supported for dtype 'str' with dtype 'str'z>operation 'sub' not supported for dtype 'str' with dtype 'str')rS   rR   ÚobjectÚstrz1Cannot perform reduction 'mean' with string dtyper   r   úGroupBy.fillna is deprecatedr5   )r   ÚgroupbyÚhasattrÚ	TypeErrorÚNotImplementedErrorÚreÚescapeÚ
ValueErrorÚdtypeÚstorageÚreplacerI   )rC   r   r   rE   r'   Úusing_infer_stringr&   rF   rD   rA   rB   ÚkindrG   r   r   r   Útest_groupby_raises_stringx   sô   
ÿþýüûúþùþõþñþíéèçæåäãâþá#þÝ'Ù(Ø)×*Ö+þÕ/Ñ0Ð1Ï2Î3Í4Ì5Ë6Ê7þÉ;Å=€

r€   r9   r>   c                 C   óf   |}|j |d�}|r|d }dd„ }tjtdd�� t|| ƒ|ƒ W d   ƒ d S 1 s,w   Y  d S )NrJ   r"   c                 S   ó   t dƒ‚©NúTest error message©rv   r   r   r   r   Úfuncó   ó   z,test_groupby_raises_string_udf.<locals>.funcr„   r6   ©rt   r?   r@   rv   r=   )rC   r   r   r'   r&   rD   r†   r   r   r   Útest_groupby_raises_string_udfë   ó   "ÿr‰   Úgroupby_func_npc              	   C   sv   |}|j |d�}|r|d }tjdtjtdfi| \}}	|r'|tju r%t}d}	|r,d}
nd}
t||	| ||d|
d	� d S )
NrJ   r"   rM   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   ©rG   )rt   Únprm   r_   rv   rI   )rC   r   r   r‹   r'   r~   r&   rD   rA   rB   rG   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 i dd“dd“dd“dtdf“d	d“d
d“dd“dd“dtdf“dtdf“dd“dd“dd“dd“dd“dd“dd“i dd“dd“dd“dd“dd“dd“dtdf“d td!f“d"d“d#d“d$d“d%d“d&d“d'td( d)d*g¡f“d+d“d,td-f“d.td/f“¥| \}}	|d0v r®d1|› d2�}
n|dkr¾|r¶d3nd4}|› d5�}
nd6}
t||	| ||||
d7� d S )8NrJ   r"   rK   rL   rM   rN   rO   z+cannot perform __mul__ with this index typerP   rQ   rR   rS   rT   z3datetime64 type does not support cumprod operationsrU   z2datetime64 type does not support cumsum operationsrV   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   z/cannot perform __truediv__ with this index typere   z%datetime64 type does not support prodrf   rg   rh   ri   rj   rk   ú|z1dtype datetime64\[ns\] does not support reductionz0datetime64 type does not support skew operationsrl   rm   ú/datetime64 type does not support sum operationsrn   z/datetime64 type does not support var operations)rN   rL   ro   z&' with datetime64 dtypes is deprecatedr   r   rs   r5   rŽ   )r   rt   ru   rv   ÚjoinrI   )rC   r   r   rE   r,   r&   rF   rD   rA   rB   rG   r   r   r   r   Útest_groupby_raises_datetime  sº   
ÿþýüûúùø	÷
öõôóòñðïîíìëêéèçæåäãâþÿþá(Ø)×*Ö+Õ-r”   c                 C   r�   )NrJ   r"   c                 S   r‚   rƒ   r…   r   r   r   r   r†   m  r‡   z.test_groupby_raises_datetime_udf.<locals>.funcr„   r6   rˆ   )rC   r   r   r,   r&   rD   r†   r   r   r   Ú test_groupby_raises_datetime_udfe  rŠ   r•   c           
   	   C   s`   |}|j |d�}|r|d }tjtdftjdi| \}}|r!d}	nd}	t||| ||d|	d� d S )	NrJ   r"   r’   rM   rŒ   r�   r   rŽ   ©rt   r�   rm   rv   r_   rI   )
rC   r   r   r‹   r,   r&   rD   rA   rB   rG   r   r   r   Útest_groupby_raises_datetime_npt  s   
þýr—   r†   )re   rT   rk   rn   c                 C   s&   |}|j dd�}ttdd|| g ƒ d S )Nr   rJ   z/timedelta64 type does not support .* operationsr8   )rt   rI   rv   )r†   r/   r&   rD   r   r   r   Útest_groupby_raises_timedeltaŒ  s   úr˜   c                 C   sð  |}t ||ƒ}|j|d�}|r |d }|dkr t|dƒrJ ‚d S i dd“dd“dd“dtdf“d	d“d
d“dttfdf“dttfdf“dttfdf“dttfdf“dtdf“dd“d|s`tdfnd“dd“dd“dd“dd“i dd“dtd dd g¡f“d!td d"d#g¡f“d$d“d%d“d&d“d'td(f“d)td*f“d+td,f“d-d“d.td d/d0g¡f“d1d“d2d“d3td d4d5g¡f“d6td d7d8g¡f“d9td:f“d;td d<d=g¡f“¥| \}	}
|dkrê|râd>nd?}|› d@�}ndA}t|	|
| ||||ƒ d S )BNrJ   r"   rK   rL   rM   rN   rO   ú=unsupported operand type\(s\) for \*: 'Categorical' and 'int'rP   rQ   rR   zz(category type does not support cummax operations|category dtype not supported|cummax is not supported for category dtype)rS   zz(category type does not support cummin operations|category dtype not supported|cummin is not supported for category dtype)rT   z|(category type does not support cumprod operations|category dtype not supported|cumprod is not supported for category dtype)rU   zz(category type does not support cumsum operations|category dtype not supported|cumsum is not supported for category dtype)rV   zDunsupported operand type\(s\) for -: 'Categorical' and 'Categorical'rX   rY   úSCannot setitem on a Categorical with a new category \(0\), set the categories firstrZ   r[   r\   r]   r^   r_   r‘   z2'Categorical' .* does not support reduction 'mean'ú2category dtype does not support aggregation 'mean'r`   z4'Categorical' .* does not support reduction 'median'ú4category dtype does not support aggregation 'median'ra   rb   rc   rd   zDunsupported operand type\(s\) for /: 'Categorical' and 'Categorical're   ú.category type does not support prod operationsrf   úNo matching signature foundrg   rh   ú1'Categorical' .* does not support reduction 'sem'ú1category dtype does not support aggregation 'sem'ri   rj   rk   ú0dtype category does not support reduction 'skew'ú.category type does not support skew operationsrl   ú1'Categorical' .* does not support reduction 'std'ú1category dtype does not support aggregation 'std'rm   ú-category type does not support sum operationsrn   ú1'Categorical' .* does not support reduction 'var'ú1category dtype does not support aggregation 'var'r   r   rs   r5   )r   rt   ru   rv   rw   r“   rI   )rC   r   r   rE   Úusing_copy_on_writer4   r&   rF   rD   rA   rB   r   rG   r   r   r   Útest_groupby_raises_category›  s2  
ÿþýþüø	÷
þöþðþêþä"þÞ&Ú'ûþÓ.Ò/Ñ0Ð1Ï2Î3þÿþÍ<þÿþÄE»FºG¹Hþ¸L´M³N²Oþÿþ±X¨Y§Zþÿþ¦cþÿþ�l”mþÿþ“vŠxr©   c                 C   r�   )NrJ   r"   c                 S   r‚   rƒ   r…   r   r   r   r   r†   4  r‡   z.test_groupby_raises_category_udf.<locals>.funcr„   r6   rˆ   )rC   r   r   r4   r&   rD   r†   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| \}}|r#d}	nd}	t||| ||d|	d� d S )	NrJ   r"   r¥   r›   rŒ   r�   r   rŽ   r–   )
rC   r   r   r‹   r4   r&   rD   rA   rB   rG   r   r   r   Útest_groupby_raises_category_np;  s    
þþúr«   c                 C   sz  |}t g d¢g d¢dd�|d< t||ƒ}|j||d�}	|r.|	d }	|dkr.t|	dƒr,J ‚d S | o<td	d
„ |	j ¡ D ƒƒ}
|s[| dkr[t|tƒr[t|d t	ƒr[|ddgkr[|
rYJ ‚d}
| dkrad}
i dd“dd“dd“dt
df“dd“dd“dtt
fdf“dtt
fdf“dtt
fdf“dtt
fdf“dt
df“d d“d!|s¡t
d"fnd“d#d“d$|
r­td%fnd“d&|
r¶td%fnd“d'd“i d(d“d)t
d*f“d+t
d,f“d-d“d.d“d/d“d0t
df“d1t
d2f“d3t
d4f“d5d“d6t
d7 d8d9g¡f“d:d“d;d“d<t
d7 d=d>g¡f“d?t
d7 d@dAg¡f“dBt
dCf“dDt
d7 dEdFg¡f“¥| \}}|d!k�r/|�r'dGndH}|› dI�}ndJ}t||| |	|||ƒ d S )KNr0   r    Tr1   r   )r   Úobservedr"   rK   c                 s   s   � | ]}|j V  qd S r   )Úempty)Ú.0Úgroupr   r   r   Ú	<genexpr>q  s   € z;test_groupby_raises_category_on_category.<locals>.<genexpr>r>   r   r   FrL   rM   rN   rO   r™   rP   rQ   rR   zz(cummax is not supported for category dtype|category dtype not supported|category type does not support cummax operations)rS   zz(cummin is not supported for category dtype|category dtype not supported|category type does not support cummin operations)rT   z|(cumprod is not supported for category dtype|category dtype not supported|category type does not support cumprod operations)rU   zz(cumsum is not supported for category dtype|category dtype not supported|category type does not support cumsum operations)rV   rW   rX   rY   rš   rZ   r[   z(empty group due to unobserved categoriesr\   r]   r^   r_   r›   r`   rœ   ra   rb   rc   rd   re   r�   rf   rž   rg   rh   r‘   rŸ   r    ri   rj   rk   r¢   r¡   rl   r£   r¤   rm   r¥   rn   r¦   r§   r   r   rs   r5   )r   r   rt   ru   rN   ÚgroupsÚvaluesÚ
isinstancer$   rr   rv   rw   rz   r“   rI   )rC   r   r   rE   r¬   r¨   r4   r&   rF   rD   Úempty_groupsrA   rB   r   rG   r   r   r   Ú(test_groupby_raises_category_on_categoryV  s:  
ý
ÿÿþÿþýþüø	÷
þöþðþêþä"Þ#Ý$ûþÖ+Õ,
ÿÒ/
ÿÏ2Î3Í4Ì5Ë6Ê7É8È9Ç:Æ;Å<Ä=þÿþÃFºG¹Hþÿþ¸Qþÿþ¯Z¦[þÿþ¥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 s&w   Y  tjtd	d�� |d
  W d   ƒ d S 1 sBw   Y  d S )Nr   r
   r   )r   r   r!   z+DataFrame.groupby with axis=1 is deprecatedr6   r   )Úaxisz'Cannot subset columns when using axis=1r   )r   r;   r<   r:   rt   r?   r@   rz   )r&   rB   rD   r   r   r   Ú%test_subsetting_columns_axis_1_raisesî  s   ÿ
"ÿr·   )r5   )+r+   rx   Únumpyr�   r?   Úpandasr   r   r   r   Úpandas._testingÚ_testingr;   Úpandas.tests.groupbyr   ÚfixtureÚarrayÚdictÚzipr#   r   r   r'   r,   r/   r4   rI   ÚmarkÚparametrizer€   r‰   rm   r_   r�   r”   r•   r—   r˜   r©   rª   r«   rµ   r·   r   r   r   r   Ú<module>   sx   
öÿ







r
#
E


 

 