
    bMh\                     x   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 g d ej        g d           e e ed	          g 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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g d          d(             Z)d) Z*dS )+    N)Categorical	DataFrameGrouperSeries)get_groupby_method_argsab)keyc                     | dz  S )N    xs    `/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pandas/tests/groupby/test_raises.py<lambda>r      s
    !a%     )	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                     | j         S Nparamrequests    r   byr       s     =r   TFc                     | 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_colr2   9   sW    	,,,,,,q"4Ar2r6BB		
 	

 
B Ir   c                  v    t          g dg dt          d          t          j        d          d          } | S )Nr   r   r   r   )daysr%   )r   r(   r1   	timedeltar*   s    r   df_with_timedelta_colr6   F   sN    	,,,,,,q#+++		
 	

 
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<   S   sd    	,,,,,,q===///  			
 		

 
B Ir    c                    |dk    rd nt           }t          j        ||          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 )Nr=   matchmethodagg)FutureWarningtmassert_produces_warninggetattrrB   	transformpytestraises)klassmsghowgbgroupby_funcargswarn_msg
warn_klasss           r   _call_and_checkrR   d   s   !R]J		#Jh	?	?	? 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=>C;CC	CC	CC#&C#rL   )rA   rB   rG   c           	      b   |}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d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/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|rd=nd>}| d?}nd@}t          |	|
| ||||           d S )AN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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->)
ro   ri   rj   r_   r^   rv   rr   rx   ru   rp   z(dtype 'str' does not support operation '')rr   rv   ru   pyarrowzBoperation 'truediv' not supported for dtype 'str' with dtype 'str'z>operation 'sub' not supported for dtype 'str' with dtype 'str')r]   r\   objectstrz1Cannot perform reduction 'mean' with string dtyper   r   GroupBy.fillna is deprecatedr=   )r   groupbyhasattr	TypeErrorNotImplementedErrorreescape
ValueErrordtypestoragereplacerR   )rL   r    r"   rN   r,   using_infer_stringr+   rO   rM   rJ   rK   kindrP   s                r   test_groupby_raises_stringr   x   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
?;F 	IGHH
G;N 	zO;P 	*Q;R 	:S;T 	y"<=U;V 	IEFF
W;^ 	Y VW_;` 	
a;b 	
?@c;d 	e;f 	
g;h 	@Ai;j 	
?@k;l 	zm;n 	I=>>
o; ;v w;JE3z  F 
 
 
 M\LLLC555!\))bgm.Cy.P.P WCCV##3(=(J(J SCC111++h..CCZ''ECx):xx{888E3RtXFFFFFr   rB   rG   c                     |}|                     |          }|r|d         }d }t          j        t          d          5   t	          ||           |           d d d            d S # 1 swxY w Y   d S )NrT   r'   c                      t          d          NTest error messager   r   s    r   funcz,test_groupby_raises_string_udf.<locals>.func       ,---r   r   r?   r~   rH   rI   r   rF   )rL   r    r"   r,   r+   rM   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}	|rd}
nd}
t          ||	| ||d|
	           d S )
NrT   r'   rW   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   rP   )r~   nprw   ri   r   rR   )rL   r    r"   r   r,   r   r+   rM   rJ   rK   rP   s              r   test_groupby_raises_string_npr      s     
B	r		B W 	

S
 JE3  >bg%%E= 736E3R"xPPPPPPr   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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          ||	| ||||
7           d S )8NrT   r'   rU   rV   rW   rX   rY   z+cannot perform __mul__ with this index typerZ   r[   r\   r]   r^   z3datetime64 type does not support cumprod operationsr_   z2datetime64 type does not support cumsum operationsr`   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   z/cannot perform __truediv__ with this index typero   z%datetime64 type does not support prodrp   rq   rr   rs   rt   ru   |z1dtype datetime64\[ns\] does not support reductionz0datetime64 type does not support skew operationsrv   rw   /datetime64 type does not support sum operationsrx   z/datetime64 type does not support var operations)rX   rV   ry   z&' with datetime64 dtypes is deprecatedr   r   r}   r=   r   )r   r~   r   r   joinrR   )rL   r    r"   rN   r2   r+   rO   rM   rJ   rK   rP   r   s               r   test_groupby_raises_datetimer     s    
B"<44D	r		B W:%%r:.....F+z+z+ 	+ 	Y MN	+
 	+ 	J+ 	*+ 	*+ 	ITU+ 	9RS+ 	
+ 	+ 	*+ 	+ 	*+  	*!+" 	
#+ +$ 	z%+& 	
'+( 	*)+* 	z++, 	*-+. 	:/+0 	y"ST1+2 	CD3+4 	J5+6 	
7+8 	z9+: 	;+< 	
=+> 	HHHF 
?+P 	zQ+R 		LMS+T 		LMU+ +V W+JE3Z ~%%K|KKK		!	!):xx{888E3RthOOOOOOr   c                     |}|                     |          }|r|d         }d }t          j        t          d          5   t	          ||           |           d d d            d S # 1 swxY w Y   d S )NrT   r'   c                      t          d          r   r   r   s    r   r   z.test_groupby_raises_datetime_udf.<locals>.funcm  r   r   r   r?   r   )rL   r    r"   r2   r+   rM   r   s          r    test_groupby_raises_datetime_udfr   e  s    	B	r		B W. . . 
y(<	=	=	=  C                 r   c           	          |}|                     |          }|r|d         }t          j        t          dft          j        di|         \  }}|rd}	nd}	t          ||| ||d|	           d S )	NrT   r'   r   rW   r   r   r   r   r~   r   rw   r   ri   rR   )
rL   r    r"   r   r2   r+   rM   rJ   rK   rP   s
             r   test_groupby_raises_datetime_npr   t  s     
B	r		B W 	MN
 JE3
  736E3R"xPPPPPPr   r   )ro   r^   ru   rx   c                 h    |}|                     d          }t          t          dd|| g            d S )Nr   rT   z/timedelta64 type does not support .* operationsrA   )r~   rR   r   )r   r6   r+   rM   s       r   test_groupby_raises_timedeltar     sH    	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|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 )BNrT   r'   rU   rV   rW   rX   rY   =unsupported operand type\(s\) for \*: 'Categorical' and 'int'rZ   r[   r\   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'rb   rc   SCannot setitem on a Categorical with a new category \(0\), set the categories firstrd   re   rf   rg   rh   ri   r   z2'Categorical' .* does not support reduction 'mean'2category dtype does not support aggregation 'mean'rj   z4'Categorical' .* does not support reduction 'median'4category dtype does not support aggregation 'median'rk   rl   rm   rn   zDunsupported operand type\(s\) for /: 'Categorical' and 'Categorical'ro   .category type does not support prod operationsrp   No matching signature foundrq   rr   1'Categorical' .* does not support reduction 'sem'1category dtype does not support aggregation 'sem'rs   rt   ru   0dtype category does not support reduction 'skew'.category type does not support skew operationsrv   1'Categorical' .* does not support reduction 'std'1category dtype does not support aggregation 'std'rw   -category type does not support sum operationsrx   1'Categorical' .* does not support reduction 'var'1category dtype does not support aggregation 'var'r   r   r}   r=   )r   r~   r   r   r   r   rR   )rL   r    r"   rN   using_copy_on_writer<   r+   rO   rM   rJ   rK   r   rP   s                r   test_groupby_raises_categoryr     s   
 
B"<44D	r		B W:%%r:.....Fvzvzv 	v 	L
	v 	v 	Jv 	 ),:
v  	 ),:
!v, 	 ),;
-v8 	 ),:
9vD 	S
EvL 	MvN 	
 #'
 
 [v\ 	]v^ 	*_v` 	*avb 	
cv vd 	zevf 	HHHH 
gvx 	HHJJ 
yvJ 	zKvL 	*MvN 	:OvP 	S
QvX 	LMYvZ 	Y =>[v\ 	
]v^ 	HHGG 
_vp 	qvr 	
svt 	HHFD 
uvF 	HHGG 
GvX 		JKYvZ 	HHGG 
[v vl mvJE3p x):xx{888E3RtXFFFFFr   c                     |}|                     |          }|r|d         }d }t          j        t          d          5   t	          ||           |           d d d            d S # 1 swxY w Y   d S )NrT   r'   c                      t          d          r   r   r   s    r   r   z.test_groupby_raises_category_udf.<locals>.func4  r   r   r   r?   r   )rL   r    r"   r<   r+   rM   r   s          r    test_groupby_raises_category_udfr   +  s     
B	r		B W. . . 
y(<	=	=	=  C                 r   c           	          |}|                     |          }|r|d         }t          j        t          dft          j        t          dfi|         \  }}|rd}	nd}	t          ||| ||d|	           d S )	NrT   r'   r   r   r   r   r   r   r   )
rL   r    r"   r   r<   r+   rM   rJ   rK   rP   s
             r   test_groupby_raises_category_npr   ;  s     
B	r		B W 	KL
@
 JE3  736E3R"xPPPPPPr   c           	         |}t          g dg dd          |d<   t          ||          }|                    ||          }	|r"|	d         }	|dk    rt          |	d          rJ d S | o/t	          d	 |	j                                        D                       }
|sD| d
k    r>t          |t                    r)t          |d         t                    r|ddgk    r|
r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 |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d/t          dfd0t          d1fd2t          d3fd4dd5t          d6                    d7d8g          fd9dd:dd;t          d6                    d<d=g          fd>t          d6                    d?d@g          fdAt          dBfdCt          d6                    dDdEg          f|         \  }}|d k    r|rdFndG}| dH}ndI}t          ||| |	|||           d S )JNr8   r%   Tr9   r   )r    observedr'   rU   c              3   $   K   | ]}|j         V  d S r   )empty).0groups     r   	<genexpr>z;test_groupby_raises_category_on_category.<locals>.<genexpr>q  s$      'T'T'T'T'T'T'T'Tr   rG   r   r	   FrV   rW   rX   rY   r   rZ   r[   r\   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`   ra   rb   rc   r   rd   re   z(empty group due to unobserved categoriesrf   rg   rh   ri   r   rj   r   rk   rl   rm   rn   ro   r   rp   r   rq   rr   r   r   r   rs   rt   ru   r   r   rv   r   r   rw   r   rx   r   r   r   r   r}   r=   )r   r   r~   r   rX   groupsvalues
isinstancer)   r|   r   r   r   r   rR   )rL   r    r"   rN   r   r   r<   r+   rO   rM   empty_groupsrJ   rK   r   rP   s                  r   (test_groupby_raises_category_on_categoryr   V  s    
B555'''  BsG
 #<44D	rH	-	-B W:%%r:.....F<TC'T'TAQAQASAS'T'T'T$T$TL	;r4   r!uc""  3*
kdzdzd 	d 	L
	d 	d 	Jd 	 ),@
d  	 ),@
!d, 	 ),A
-d8 	 ),@
9dD 	67EdF 	GdH 	
 #'
 
 UdV 	WdX 	:IJJ]d^ 	:IJJcdd 	
ed df 	zgdh 	PQidj 	9TUkdl 	zmdn 	*odp 	:qdr 	y"<=sdt 	LMudv 	Y =>wdx 	
ydz 	HHGG 
{dL 	MdN 	
OdP 	HHDF 
Qdb 	HHGG 
cdt 		JKudv 	HHGG 
wd dH IdJE3L x):xx{888E3RtXFFFFFr   c                  B   t          dgdgdgd          } d}t          j        t          |          5  |                     dd          }d d d            n# 1 swxY w Y   t          j        t          d	          5  |d
          d d d            d S # 1 swxY w Y   d S )Nr   r   r   )r   r	   r&   z+DataFrame.groupby with axis=1 is deprecatedr?   r   )axisz'Cannot subset columns when using axis=1r	   )r   rD   rE   rC   r~   rH   rI   r   )r+   rK   rM   s      r   %test_subsetting_columns_axis_1_raisesr     s'   	!A3aS11	2	2B
7C		#M	=	=	= % %ZZ!Z$$% % % % % % % % % % % % % % %	z)R	S	S	S  
3                 s#   AAA>	BBB)r=   )+r1   r   numpyr   rH   pandasr   r   r   r   pandas._testing_testingrD   pandas.tests.groupbyr   fixturearraydictzipr(   r    r"   r,   r2   r6   r<   rR   markparametrizer   r   rw   ri   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      s  
  				                       8 8 8 8 8 8 		c
C###,,,--SSq6667788***++	+++	,	,ff5P5P5P.Q.QR     e}%%%  &% 	 	 	 	 	 	 	 	 	    6 6 6 6(  > > >??oG oG @?oGd  455  65  455*RVRW,=>> Q  Q ?> 65 QF  > > >??BP BP @?BPJ  455  65  455*RVRW,=>>Q Q ?> 65Q, !C!C!CDD  ED  > > >??LG LG @?LG^  455  65  455*RVRW,=>>Q Q ?> 65Q2  > > >??TG TG @?TGn    r   