
    o[weeR                     v   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 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    @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   | A|dk    r t          ||          |  d S |dk    r |j        |g|R   d S  |j        |g|R   d S t          j        | |          5  |dk    r t          ||          |  n#|dk    r |j        |g|R   n |j        |g|R   d d d            d S # 1 swxY w Y   d S )Nmethodaggmatch)getattrr?   	transformpytestraises)klassmsghowgbgroupby_funcargss         r   _call_and_checkrL   d   sR   }(??%GB%%t,,,,E\\BF<'$''''''BL-------]5,,, 	2 	2h)L))4000|+d+++++\1D1111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s   >B%%B),B)rH   )r>   r?   rC   c                 F   |}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|         \  }}	t          ||	| |||           d S )2Nr    r'   corrwithallN 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mean-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]quantilez,cannot be performed against 'object' dtypes!ranksemz!could not convert string to floatshiftsizeskewstdsumvarz,agg function failed [how->var,dtype->object])	r   groupbyhasattr	TypeErrorNotImplementedErrorreescape
ValueErrorrL   )
rH   r    r"   rJ   r,   r+   rK   rI   rF   rG   s
             r   test_groupby_raises_stringr|   v   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 NO_;` 	
a;b 	
?@c;d 	e;f 	
g;h 	@Ai;j 	
?@k;l 	zm;n 	IDEE
o; ;v w;JE3z E3Rt<<<<<r   r?   rC   c                     |}|                     |          }|r|d         }d }t          j        t          d          5   t	          ||           |           d d d            d S # 1 swxY w Y   d S )NrN   r'   c                      t          d          NTest error messagerw   r   s    r   funcz,test_groupby_raises_string_udf.<locals>.func       ,---r   r   r@   ru   rD   rE   rw   rB   )rH   r    r"   r,   r+   rI   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          t          j        d          fi|         \  }}|rd}	nd}	t          j        t          |	          5  t          ||| ||d           d d d            d S # 1 swxY w Y   d S )	NrN   r'   rQ   re   using SeriesGroupBy.[sum|mean]!using DataFrameGroupBy.[sum|mean]r@   r   )ru   nprs   rd   rw   ry   rz   tmassert_produces_warningFutureWarningrL   )
rH   r    r"   r   r,   r+   rI   rF   rG   warn_msgs
             r   test_groupby_raises_string_npr      s"    
B	r		B W 	

IEFF
 JE3  736		#M	B	B	B B BsC_bAAAB B B B B B B B B B B B B B B B B Bs   B##B'*B'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|         \  }}	d }
d0| d1}|d2v rt
          }
t          j        |
|3          5  t          ||	| |||           d d d            d S # 1 swxY w Y   d S )4NrN   r'   rO   rP   rQ   rS   rT   z+cannot perform __mul__ with this index typerU   rV   rW   rX   rY   z3datetime64 type does not support cumprod operationsrZ   z2datetime64 type does not support cumsum operationsr[   r]   r^   r_   r`   ra   rb   rc   rd   rf   rg   rh   ri   rj   z/cannot perform __truediv__ with this index typerk   z%datetime64 type does not support prodrl   rm   rn   ro   rp   rq   |z1dtype datetime64\[ns\] does not support reductionz0datetime64 type does not support skew operationsrr   rs   /datetime64 type does not support sum operationsrt   z/datetime64 type does not support var operations'z&' with datetime64 dtypes is deprecated)rS   rP   r@   )	r   ru   rv   rw   joinr   r   r   rL   )rH   r    r"   rJ   r2   r+   rK   rI   rF   rG   warnr   s               r   test_groupby_raises_datetimer      s7    
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 DG<GGGH~%%		#D	9	9	9 A AsC\4@@@A A A A A A A A A A A A A A A A A As   6EEEc                     |}|                     |          }|r|d         }d }t          j        t          d          5   t	          ||           |           d d d            d S # 1 swxY w Y   d S )NrN   r'   c                      t          d          r   r   r   s    r   r   z.test_groupby_raises_datetime_udf.<locals>.func=  r   r   r   r@   r   )rH   r    r"   r2   r+   rI   r   s          r    test_groupby_raises_datetime_udfr   5  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          j        t          |	          5  t          ||| ||d           d d d            d S # 1 swxY w Y   d S )	NrN   r'   r   rQ   r   r   r@   r   	ru   r   rs   rw   rd   r   r   r   rL   )
rH   r    r"   r   r2   r+   rI   rF   rG   r   s
             r   test_groupby_raises_datetime_npr   D  s    
B	r		B W 	MN
 JE3
  736		#M	B	B	B B BsC_bAAAB B B B B B B B B B B B B B B B B Bs   /BBBr   )rk   rY   rq   rt   c                 h    |}|                     d          }t          t          dd|| g            d S )Nr   rN   z/timedelta64 type does not support .* operationsr>   )ru   rL   rw   )r   r6   r+   rI   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|         \  }	}
t          |	|
| |||           d S )>NrN   r'   rO   rP   rQ   rS   rT   =unsupported operand type\(s\) for \*: 'Categorical' and 'int'rU   rV   rW   zz(category type does not support cummax operations|category dtype not supported|cummax is not supported for category dtype)rX   zz(category type does not support cummin operations|category dtype not supported|cummin is not supported for category dtype)rY   z|(category type does not support cumprod operations|category dtype not supported|cumprod is not supported for category dtype)rZ   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]   r^   SCannot setitem on a Categorical with a new category \(0\), set the categories firstr_   r`   ra   rb   rc   rd   r   z2'Categorical' .* does not support reduction 'mean'2category dtype does not support aggregation 'mean'rf   z4'Categorical' .* does not support reduction 'median'4category dtype does not support aggregation 'median'rg   rh   ri   rj   zDunsupported operand type\(s\) for /: 'Categorical' and 'Categorical'rk   .category type does not support prod operationsrl   zNo matching signature foundrm   rn   1'Categorical' .* does not support reduction 'sem'1category dtype does not support aggregation 'sem'ro   rp   rq   0dtype category does not support reduction 'skew'.category type does not support skew operationsrr   1'Categorical' .* does not support reduction 'std'1category dtype does not support aggregation 'std'rs   -category type does not support sum operationsrt   1'Categorical' .* does not support reduction 'var'1category dtype does not support aggregation 'var')r   ru   rv   rw   rx   r   rL   )rH   r    r"   rJ   using_copy_on_writer<   r+   rK   rI   rF   rG   s              r   test_groupby_raises_categoryr   l  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 E3Rt<<<<<r   c                     |}|                     |          }|r|d         }d }t          j        t          d          5   t	          ||           |           d d d            d S # 1 swxY w Y   d S )NrN   r'   c                      t          d          r   r   r   s    r   r   z.test_groupby_raises_category_udf.<locals>.func   r   r   r   r@   r   )rH   r    r"   r<   r+   rI   r   s          r    test_groupby_raises_category_udfr     s     
B	r		B W. . . 
y(<	=	=	=  C                 r   c           	      J   |}|                     |          }|r|d         }t          j        t          dft          j        t          dfi|         \  }}|rd}	nd}	t          j        t          |	          5  t          ||| ||d           d d d            d S # 1 swxY w Y   d S )	NrN   r'   r   r   r   r   r@   r   r   )
rH   r    r"   r   r<   r+   rI   rF   rG   r   s
             r   test_groupby_raises_category_npr     s    
B	r		B W 	KL
@
 JE3  736		#M	B	B	B B BsC_bAAAB B B B B B B B B B B B B B B B B Bs   6BBBc                 B   |}t          g dg dd          |d<   t          ||          }|                    ||          }	|r"|	d         }	|dk    rt          |	d          rJ d S t	          d	 |	j                                        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d-t          d.fd/t          d0fd1dd2t          d3
                    d4d5g          fd6dd7dd8t          d3
                    d9d:g          fd;t          d3
                    d<d=g          fd>t          d?fd@t          d3
                    dAdBg          f|         \  }}t          ||| |	||           d S )CNr8   r%   Tr9   r   )r    observedr'   rO   c              3   $   K   | ]}|j         V  d S r   )empty).0groups     r   	<genexpr>z;test_groupby_raises_category_on_category.<locals>.<genexpr>>  s$      CCuu{CCCCCCr   rP   rQ   rS   rT   r   rU   rV   rW   zz(cummax is not supported for category dtype|category dtype not supported|category type does not support cummax operations)rX   zz(cummin is not supported for category dtype|category dtype not supported|category type does not support cummin operations)rY   z|(cumprod is not supported for category dtype|category dtype not supported|category type does not support cumprod operations)rZ   zz(cumsum is not supported for category dtype|category dtype not supported|category type does not support cumsum operations)r[   r\   r]   r^   r   r_   r`   z*attempt to get argmax of an empty sequencera   z*attempt to get argmin of an empty sequencerb   rc   rd   r   rf   r   rg   rh   ri   rj   rk   r   rl   rR   rm   rn   r   r   r   ro   rp   rq   r   r   rr   r   r   rs   r   rt   r   r   )r   r   ru   rv   rS   groupsvaluesrw   rx   r{   r   rL   )rH   r    r"   rJ   r   r   r<   r+   rK   rI   empty_groupsrF   rG   s                r   (test_groupby_raises_category_on_categoryr   #  s-    
B555'''  BsG
 #<44D	rH	-	-B W:%%r:.....FCC	0@0@0B0BCCCCCL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 	:KLL]d^ 	:KLL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Ow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 E3Rt<<<<<r   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   r   r   r   ru   rD   rE   r{   )r+   rG   rI   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)+r1   ry   numpyr   rD   pandasr   r   r   r   pandas._testing_testingr   pandas.tests.groupbyr   fixturearraydictzipr(   r    r"   r,   r2   r6   r<   rL   markparametrizer|   r   rs   rd   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}%%%  &% 	 	 	 	 	 	 	 	 	    2 2 2$  > > >??K= K= @?K=\  455  65  455*RVRW,=>>B B ?> 65B4  > > >??AA AA @?AAH  455  65  455*RVRW,=>>B B ?> 65B. !C!C!CDD  ED  > > >??G= G= @?G=T  455  65  455*RVRW,=>>B B ?> 65B4  > > >??B= B= @?B=J    r   