
    PiwZ                        d dl Z d dlZd dlZd dlZd dlm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 g d	 ej        g d	           e e ed
          g d	d                     eg d           eg d           eg d          gg
          d             Z ej        ddg          d             Zej        d             Zej        d             Zej        d             Z	 d+dZej                            dg d          d             Zej                            dddg          d             Zej                            dddg          ej                            dej         ej!        g          d                         Z"ej                            dg d          d              Z#ej                            dddg          d!             Z$ej                            dddg          ej                            dej         ej!        g          d"                         Z%ej                            d#g d$          d%             Z&ej                            dg d          d&             Z'ej                            dddg          d'             Z(ej                            dddg          ej                            dej         ej!        g          d(                         Z)ej        *                    d)          ej                            dg d          d*                         Z+dS ),    N)Pandas4Warning)Categorical	DataFrameGrouperSeries)get_groupby_method_argsab)keyc                     | dz  S )N    xs    t/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/pandas/tests/groupby/test_raises.py<lambda>r      s
    !a%     )	r   r   r      r   r   r      r   	   T)strict	r   r   r   r   r   r   r   r   r   	r   r      r   r   r   r   r   r   )paramsc                     | j         S Nparamrequests    r   byr"      s     =r   Fc                     | j         S r   r   r    s    r   groupby_seriesr$   )   s
    =r   c                  j    t          g dg dt          d          t          d          d          } | S )Nr   r   r   	xyzwtyuior	   r
   cd)r   rangelistdfs    r   df_with_string_colr.   .   sH    	,,,,,,qk""		
 	

 
B Ir   c                      t          g dg dt          d          t          j        ddddddd	          d
          } | S )Nr   r   r   i  r   
         i`= r'   )r   r*   datetimer,   s    r   df_with_datetime_colr4   ;   sW    	,,,,,,q"4Ar2r6BB		
 	

 
B Ir   c            
      x    t          g dg dt          d          t          g dg dd          d          } | S )Nr   r   r   	r	   r	   r	   r	   r
   r
   r
   r
   r(   r'   T
categoriesordered)r   r*   r   r,   s    r   df_with_cat_colr:   H   sd    	,,,,,,q===///  			
 		

 
B Ir    c                    t          j        ||d          5  | >|dk    r t          ||          |  n|dk    r |j        |g|R   nz |j        |g|R   nkt          j        | |          5  |dk    r t          ||          |  n#|dk    r |j        |g|R   n |j        |g|R   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NF)matchcheck_stacklevelmethodaggr=   )tmassert_produces_warninggetattrr@   	transformpytestraises)klassmsghowgbgroupby_funcargswarn_categorywarn_msgs           r   _call_and_checkrP   Y   s    
	#X
 
 
 6 6 =h)L))4000|+d+++++\1D11111uC000 6 6(??-GB--t444E\\BF</$///// BL555556 6 6 6 6 6 6 6 6 6 6 6 6 6 66 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6s6   AC/>B9-C9B=	=C B=	CCCrJ   )r?   r@   rE   c           
      r   |}t          ||          }|                    |          }|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t          t          j        d          fdt          t          j        d          fddd dd!dd"t          dfd#t          t          j        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.t          d)fd/dd0t          t          j        d1          f|         \  }	}
|rw|d2v rd3| d4}
|d5v rt          }	na|d"k    r|d         j        j	        d6k    rd7}
nB|dk    r|d         j        j	        d6k    rd8}
n#|d9v r|

                    d:d;          }
n|dk    rd<}
|dk    r
t          }d=}nd }d>}t          |	|
| |||||           d S )?Nr"   r)   corrwithallNr;   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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kurtstdsumvarz%agg function failed [how->var,dtype->)rl   rf   rg   r]   r\   rt   ro   rv   rr   rs   rm   z(dtype 'str' does not support operation '')ro   rt   rr   rs   pyarrowzBoperation 'truediv' not supported for dtype 'str' with dtype 'str'z>operation 'sub' not supported for dtype 'str' with dtype 'str')r[   rZ   objectstrz1Cannot perform reduction 'mean' with string dtype'DataFrameGroupBy.corrwith is deprecatedr;   )r   groupbyhasattr	TypeErrorNotImplementedErrorreescape
ValueErrordtypestoragereplacer   rP   )rJ   r"   r$   rL   r.   using_infer_stringr-   rM   rK   rH   rI   rN   rO   s                r   test_groupby_raises_stringr   p   s    
B"<44D	r		B W:%%r:.....F;z;z; 	; 	Y 34	;
 	; 	J; 	 ),V
; 	 ),V
; 	 ),W
;& 	 ),V
';. 	67/;0 	1;2 	3;4 	*5;6 	*7;8 	
9;: 	z;; ;< 	IEFF
=;D 	IGHH
E;L 	zM;N 	*O;P 	:Q;R 	y"<=S;T 	IEFF
U;\ 	Y VW];^ 	
_;` 	
?@a;b 	c;d 	
e;f 	@Ag;h 	@Ai;j 	
?@k;l 	zm;n 	I=>>
o; ;v w;JE3z  F 
 
 
 M\LLLC===!\))bgm.Cy.P.P WCCV##3(=(J(J SCC111++h..CCZ''ECz!!&<E3Rt]HUUUUUr   r@   rE   c                     |}|                     |          }|r|d         }d }t          j        t          d          5   t	          ||           |           d d d            d S # 1 swxY w Y   d S )NrR   r)   c                      t          d          NTest error messager~   r   s    r   funcz,test_groupby_raises_string_udf.<locals>.func       ,---r   r   rA   r|   rF   rG   r~   rD   )rJ   r"   r$   r.   r-   rK   r   s          r   test_groupby_raises_string_udfr      s    	B	r		B W. . . 
y(<	=	=	=  C                    A((A,/A,groupby_func_npc                 
   |}|                     |          }|r|d         }t          j        dt          j        t          dfi|         \  }}	|r |t          j        u rt          }d|j         d}	t          ||	| ||d           d S )NrR   r)   rU   zXCould not convert string .* to numeric|Cannot perform reduction 'mean' with string dtypezCannot perform reduction 'z' with string dtyper   )r|   npru   rf   r~   __name__rP   )
rJ   r"   r$   r   r.   r   r-   rK   rH   rI   s
             r   test_groupby_raises_string_npr      s     
B	r		B W 	

@
 JE3  Ybg%%EX?+CXXXE3R"=====r   c           
         |}t          ||          }|                    |          }|r"|d         }|dk    rt          |d          rJ d S i dt          dfdt          df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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,t          d)                    d*d-g          fd.d	d/t          d0fd1t          d2f|         \  }}	|dk    r
t
          }
d3}nd }
d4}t          ||	| ||||
|           d S )5NrR   r)   rS   rT   z3'all' with datetime64 dtypes is no longer supportedrV   z3'any' with datetime64 dtypes is no longer supportedrW   rU   z+cannot perform __mul__ with this index typerX   rY   rZ   r[   r\   z4datetime64 type does not support operation 'cumprod'r]   z3datetime64 type does not support operation 'cumsum'r^   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   z/cannot perform __truediv__ with this index typerl   z1datetime64 type does not support operation 'prod'rm   rn   ro   rp   rq   rr   |z1dtype datetime64\[ns\] does not support operationz1datetime64 type does not support operation 'skew'rs   z1datetime64 type does not support operation 'kurt'rt   ru   z/datetime64 type does not support operation 'sumrv   z0datetime64 type does not support operation 'var'r{   r;   )r   r|   r}   r~   joinr   rP   )rJ   r"   r$   rL   r4   r-   rM   rK   rH   rI   rN   rO   s               r   test_groupby_raises_datetimer     s    
B"<44D	r		B W:%%r:.....F3	PQ3	PQ3 	3 	Y MN	3
 	3 	J3 	*3 	*3 	IUV3 	9ST3 	
3 	3 	3 	*3 	*3  	
!3" 	z#3 3$ 	
%3& 	*'3( 	z)3* 	*+3, 	:-3. 	y"ST/30 	OP132 	J334 	
536 	z738 	93: 	
;3< 	HHHG 
=3N 	HHHG 
O3` 	za3b 		LMc3d 		MNe3 3f g3JE3j z!!&<E3Rt]HUUUUUr   c                     |}|                     |          }|r|d         }d }t          j        t          d          5   t	          ||           |           d d d            d S # 1 swxY w Y   d S )NrR   r)   c                      t          d          r   r   r   s    r   r   z.test_groupby_raises_datetime_udf.<locals>.funck  r   r   r   rA   r   )rJ   r"   r$   r4   r-   rK   r   s          r    test_groupby_raises_datetime_udfr   c  s    	B	r		B W. . . 
y(<	=	=	=  C                 r   c                     |}|                     |          }|r|d         }t          j        t          t	          j        d          ft          j        di|         \  }}t          ||| ||d           d S )NrR   r)   z/datetime64[us] does not support operation 'sum'rU   r   )r|   r   ru   r~   r   r   rf   rP   )	rJ   r"   r$   r   r4   r-   rK   rH   rI   s	            r   test_groupby_raises_datetime_npr   r  s     
B	r		B W 	IGHH
 	 JE3 E3R"=====r   r   )rl   r\   rr   rs   rv   c                     t          g dg dt          d          t          j        d          d          }|                    d          }t          t          d	d
|| g            d S )Nr   r   r   r   )daysr'   r	   rR   z/timedelta64 type does not support .* operationsr?   )r   r*   r3   	timedeltar|   rP   r~   )r   r-   rK   s      r   test_groupby_raises_timedeltar     s    	,,,,,,q#+++		
 	

 
B 
s		B9

    r   c           
      $   |}t          ||          }|                    |          }|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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-d.g          fd/dd0dd1t          d                    d2d3g          fd4t          d                    d5d6g          fd7t          d                    d8d9g          fd:t          d;fd<t          d                    d=d>g          f|         \  }}	|dk    r
t          }
d?}nd }
d@}t          ||	| ||||
|           d S )ANrR   r)   rS   rT   rU   rV   rW   =unsupported operand type\(s\) for \*: 'Categorical' and 'int'rX   rY   rZ   zz(category type does not support cummax operations|category dtype not supported|cummax is not supported for category dtype)r[   zz(category type does not support cummin operations|category dtype not supported|cummin is not supported for category dtype)r\   z|(category type does not support cumprod operations|category dtype not supported|cumprod is not supported for category dtype)r]   zz(category type does not support cumsum operations|category dtype not supported|cumsum is not supported for category dtype)r^   zDunsupported operand type\(s\) for -: 'Categorical' and 'Categorical'r`   ra   rb   rc   rd   re   rf   r   z2'Categorical' .* does not support operation 'mean'2category dtype does not support aggregation 'mean'rg   z4'Categorical' .* does not support operation 'median'4category dtype does not support aggregation 'median'rh   ri   rj   rk   zDunsupported operand type\(s\) for /: 'Categorical' and 'Categorical'rl   .category type does not support prod operationsrm   No matching signature foundrn   ro   1'Categorical' .* does not support operation 'sem'1category dtype does not support aggregation 'sem'rp   rq   rr   0dtype category does not support operation 'skew'.category type does not support skew operationsrs   0dtype category does not support operation 'kurt'.category type does not support kurt operationsrt   1'Categorical' .* does not support operation 'std'1category dtype does not support aggregation 'std'ru   -category type does not support sum operationsrv   1'Categorical' .* does not support operation 'var'1category dtype does not support aggregation 'var'r{   r;   )r   r|   r}   r~   r   r   r   rP   )rJ   r"   r$   rL   r:   r-   rM   rK   rH   rI   rN   rO   s               r   test_groupby_raises_categoryr     s   
 
B"<44D	r		B W:%%r:.....Fxzxzx 	x 	L
	x 	x 	Jx 	 ),:
x  	 ),:
!x, 	 ),;
-x8 	 ),:
9xD 	S
ExL 	MxN 	OxP 	*QxR 	*SxT 	
UxV 	zWx xX 	HHHH 
Yxj 	HHJJ 
kx| 	z}x~ 	*x@ 	:AxB 	S
CxJ 	LMKxL 	Y =>MxN 	
OxP 	HHGG 
Qxb 	cxd 	
exf 	HHFD 
gxx 	HHFD 
yxJ 	HHGG 
Kx\ 		JK]x^ 	HHGG 
_x xp qxJE3t z!!&<E3Rt]HUUUUUr   c                     |}|                     |          }|r|d         }d }t          j        t          d          5   t	          ||           |           d d d            d S # 1 swxY w Y   d S )NrR   r)   c                      t          d          r   r   r   s    r   r   z.test_groupby_raises_category_udf.<locals>.func:  r   r   r   rA   r   )rJ   r"   r$   r:   r-   rK   r   s          r    test_groupby_raises_category_udfr   1  s     
B	r		B W. . . 
y(<	=	=	=  C                 r   c                     |}|                     |          }|r|d         }t          j        t          dft          j        t          dfi|         \  }}t          ||| ||d           d S )NrR   r)   z/dtype category does not support operation 'sum'z0dtype category does not support operation 'mean'r   )r|   r   ru   r~   rf   rP   )	rJ   r"   r$   r   r:   r-   rK   rH   rI   s	            r   test_groupby_raises_category_npr   A  s     
B	r		B W 	MN
>
 JE3 E3R"=====r   z$ignore:In a future version, the keysc           
         |}t          g dg dd          |d<   t          ||          }|                    ||          }|r"|d         }|dk    rt          |d          rJ d S | o/t	          d	 |j                                        D                       }	| d
k    rd}	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|	r	t          d fndd!|	r	t          d fndd"dd#di d$t          d%fd&t          d'fd(dd)dd*dd+t          dfd,t          d-fd.t          d/fd0dd1t          d2
                    d3d4g          fd5dd6dd7t          d2
                    d8d9g          fd:t          d2
                    d;d<g          fd=t          d2
                    d>d?g          fd@t          dAfdBt          d2
                    dCdDg          f|         \  }
}|dk    r
t          }dE}nd }dF}t          |
|| |||||           d S )GNr6   r'   Tr7   r	   )r"   observedr)   rS   c              3   $   K   | ]}|j         V  d S r   )empty).0groups     r   	<genexpr>z;test_groupby_raises_category_on_category.<locals>.<genexpr>r  s$      'T'T'T'T'T'T'T'Tr   rE   FrT   rU   rV   rW   r   rX   rY   rZ   zz(cummax is not supported for category dtype|category dtype not supported|category type does not support cummax operations)r[   zz(cummin is not supported for category dtype|category dtype not supported|category type does not support cummin operations)r\   z|(cumprod is not supported for category dtype|category dtype not supported|category type does not support cumprod operations)r]   zz(cumsum is not supported for category dtype|category dtype not supported|category type does not support cumsum operations)r^   r_   r`   ra   rb   z(empty group due to unobserved categoriesrc   rd   re   rf   r   rg   r   rh   ri   rj   rk   rl   r   rm   r   rn   ro   r   r   r   rp   rq   rr   r   r   rs   r   r   rt   r   r   ru   r   rv   r   r   r{   r;   )r   r   r|   r}   rV   groupsvaluesr~   r   r   r   r   rP   )rJ   r"   r$   rL   r   r:   r-   rM   rK   empty_groupsrH   rI   rN   rO   s                 r   (test_groupby_raises_category_on_categoryr   W  sn    
B555'''  BsG
 #<44D	rH	-	-B W:%%r:.....F<TC'T'TAQAQASAS'T'T'T$T$TL
kfzfzf 	f 	L
	f 	f 	Jf 	 ),@
f  	 ),@
!f, 	 ),A
-f8 	 ),@
9fD 	67EfF 	GfH 	IfJ 	:IJJOfP 	:IJJUfV 	
WfX 	zYf fZ 	PQ[f\ 	9TU]f^ 	z_f` 	*afb 	:cfd 	y"<=eff 	LMgfh 	Y =>ifj 	
kfl 	HHGG 
mf~ 	f@ 	
AfB 	HHDF 
CfT 	HHDF 
Uff 	HHGG 
gfx 		JKyfz 	HHGG 
{f fL MfJE3P z!!&<E3Rt]HUUUUUr   rU   ),r3   r   numpyr   rF   pandas.errorsr   pandasr   r   r   r   pandas._testing_testingrB   pandas.tests.groupbyr   fixturearraydictzipr*   r"   r$   r.   r4   r:   rP   markparametrizer   r   ru   rf   r   r   r   r   r   r   r   r   filterwarningsr   r   r   r   <module>r      s#  
  				      ( ( ( ( ( (                  8 8 8 8 8 8 		c
C###,,,--SSq666tDDDEE***++	+++	,	,ff5P5P5P.Q.QR     e}%%%  &% 	 	 	 	 	 	   " KM6 6 6 6.  > > >??qV qV @?qVh  455  65  455*RVRW,=>>> > ?> 65>@  > > >??IV IV @?IVX  455  65  455*RVRW,=>>> > ?> 65>( !K!K!KLL  ML*  > > >??OV OV @?OVd  455  65  455*RVRW,=>>> > ?> 65>( BCC > > >??LV LV @? DCLV LV LVr   