
    OwgV                     `   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j6                  j9                  dg d      d        Zej6                  j9                  dddg      d        Zej6                  j9                  dddg      ej6                  j9                  dej>                  ej@                  g      d               Z!ej6                  j9                  dg d      d        Z"ej6                  j9                  dddg      d        Z#ej6                  j9                  dddg      ej6                  j9                  dej>                  ej@                  g      d                Z$ej6                  j9                  d!g d"      d#        Z%ej6                  j9                  dg d      d$        Z&ej6                  j9                  dddg      d%        Z'ej6                  j9                  dddg      ej6                  j9                  dej>                  ej@                  g      d&               Z(ej6                  j9                  dg d      d'        Z)d( Z*y)*    N)Categorical	DataFrameGrouperSeries)get_groupby_method_argsab)keyc                     | dz  S )N    xs    W/var/www/horilla/myenv/lib/python3.12/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                  R    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,   ,   s-    	,,qk"		

B Ir   c                  r    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   s?    	,,q""4Ar2r6B		

B Ir   c                  h    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   s3    	,,q##+		

B Ir   c            
      `    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   s6    	,,q=/			

B Ir   c                    |dk(  rd nt         }t        j                  ||      5  | B|dk(  r t        ||      |  n|dk(  r |j                  |g|  nu |j
                  |g|  nat        j                  | |      5  |dk(  r t        ||      |  n,|dk(  r |j                  |g|  n |j
                  |g|  d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)N 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=h)L)40|+d+\1D1uC0 6(?-GB-t4E\BFF</$/ BLL5566 66 66 6s%   AC ACC C	C  C)rL   )rA   rB   rG   c           	         |}t        ||      }|j                  |      }|r|d   }|dk(  rt        |d      rJ y 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|   \  }}	|dk(  r|rd2nd3}
|
 d4}nd5}t        ||	| ||||       y )6N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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->r   r   GroupBy.fillna is deprecatedr>   )	r   groupbyhasattr	TypeErrorNotImplementedErrorreescape
ValueErrorrR   )rL   r    r"   rN   r,   r+   rO   rM   rJ   rK   kindrP   s               r   test_groupby_raises_stringr   x   s    
B"<4D	r	BW:%r:...;z;z; 	; 	Y 34	;
 	; 	J; 	 ),V
; 	 ),V
; 	 ),W
;& 	 ),V
';. 	67/;0 	1;2 	*3;4 	5;6 	*7;8 	*9;: 	
;;< 	z=;> 	IIEF
?;F 	IIGH
G;N 	zO;P 	*Q;R 	:S;T 	y"<=U;V 	IIEF
W;^ 	Y NO_;` 	
a;b 	
?@c;d 	e;f 	
g;h 	@Ai;j 	
?@k;l 	zm;n 	II=>
o;v w;JE3z x)x{V78E3RtXFr   rB   rG   c                     |}|j                  |      }|r|d   }d }t        j                  t        d      5   t	        ||       |       d d d        y # 1 sw Y   y xY w)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groupby_func_npc           	          |}|j                  |      }|r|d   }t        j                  dt        j                  t        t        j                  d      fi|   \  }}|rd}	nd}	t        ||| ||d|	       y )	NrT   r'   rW   rj   using SeriesGroupBy.[sum|mean]!using DataFrameGroupBy.[sum|mean]r   rP   )r{   nprx   ri   r}   r   r   rR   )
rL   r    r"   r   r,   r+   rM   rJ   rK   rP   s
             r   test_groupby_raises_string_npr      s     
B	r	BW 	

IIEF
 JE3 36E3R"xPr   c           	      <   |}t        ||      }|j                  |      }|r|d   }|dk(  rt        |d      rJ y 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(j	                  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       y )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   rk   rl   rm   rn   ro   z/cannot perform __truediv__ with this index typerp   z%datetime64 type does not support prodrq   rr   rs   rt   ru   rv   |z1dtype datetime64\[ns\] does not support reductionz0datetime64 type does not support skew operationsrw   rx   /datetime64 type does not support sum operationsry   z/datetime64 type does not support var operations)rX   rV   'z&' with datetime64 dtypes is deprecatedr   r   rz   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"<4D	r	BW:%r:...+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 ~%|n$JK		!)x{V78E3RthOr   c                     |}|j                  |      }|r|d   }d }t        j                  t        d      5   t	        ||       |       d d d        y # 1 sw Y   y xY w)NrT   r'   c                     t        d      r   r   r   s    r   r   z.test_groupby_raises_datetime_udf.<locals>.funcD  r   r   r   r?   r   )rL   r    r"   r2   r+   rM   r   s          r    test_groupby_raises_datetime_udfr   <  s_    	B	r	BW. 
y(<	= C  r   c           	          |}|j                  |      }|r|d   }t        j                  t        dft        j                  di|   \  }}|rd}	nd}	t        ||| ||d|	       y )	NrT   r'   r   rW   r   r   r   r   r{   r   rx   r}   ri   rR   )
rL   r    r"   r   r2   r+   rM   rJ   rK   rP   s
             r   test_groupby_raises_datetime_npr   K  sw     
B	r	BW 	MN
 JE3
 36E3R"xPr   r   )rp   r^   rv   ry   c                 T    |}|j                  d      }t        t        dd|| g        y )Nr   rT   z/timedelta64 type does not support .* operationsrA   )r{   rR   r}   )r   r6   r+   rM   s       r   test_groupby_raises_timedeltar   c  s1    	B	s	B9

r   c           	      r   |}t        ||      }|j                  |      }|r|d   }|dk(  rt        |d      rJ y 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j                  dd g      fd!t        dj                  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j                  d/d0g      fd1dd2dd3t        dj                  d4d5g      fd6t        dj                  d7d8g      fd9t        d:fd;t        dj                  d<d=g      f|   \  }	}
|dk(  r|rd>nd?}| d@}ndA}t        |	|
| ||||       y )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'rk   z4'Categorical' .* does not support reduction 'median'4category dtype does not support aggregation 'median'rl   rm   rn   ro   zDunsupported operand type\(s\) for /: 'Categorical' and 'Categorical'rp   .category type does not support prod operationsrq   zNo matching signature foundrr   rs   1'Categorical' .* does not support reduction 'sem'1category dtype does not support aggregation 'sem'rt   ru   rv   0dtype category does not support reduction 'skew'.category type does not support skew operationsrw   1'Categorical' .* does not support reduction 'std'1category dtype does not support aggregation 'std'rx   -category type does not support sum operationsry   1'Categorical' .* does not support reduction 'var'1category dtype does not support aggregation 'var'r   r   rz   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   r  s   
 
B"<4D	r	BW:%r:...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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l mvJE3p x)x{V78E3RtXFr   c                     |}|j                  |      }|r|d   }d }t        j                  t        d      5   t	        ||       |       d d d        y # 1 sw Y   y xY w)NrT   r'   c                     t        d      r   r   r   s    r   r   z.test_groupby_raises_category_udf.<locals>.func  r   r   r   r?   r   )rL   r    r"   r<   r+   rM   r   s          r    test_groupby_raises_category_udfr     sa     
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        ||| ||d|	       y )	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 36E3R"xPr   c           	      \   |}t        g dg dd      |d<   t        ||      }|j                  ||      }	|r|	d   }	|dk(  rt        |	d      rJ y | xr* t	        d	 |	j
                  j                         D              }
|s5| d
k7  r0t        |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        d6j                  d7d8g      fd9dd:dd;t        d6j                  d<d=g      fd>t        d6j                  d?d@g      fdAt        dBfdCt        d6j                  dDdEg      f|   \  }}|d k(  r|rdFndG}| dH}nd3}t        ||| |	|||       y )INr8   r%   Tr9   r   )r    observedr'   rU   c              3   4   K   | ]  }|j                     y wr   )empty).0groups     r   	<genexpr>z;test_groupby_raises_category_on_category.<locals>.<genexpr>H  s     'T'Ts   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   rk   r   rl   rm   rn   ro   rp   r   rq   r>   rr   rs   r   r   r   rt   ru   rv   r   r   rw   r   r   rx   r   ry   r   r   r   r   rz   )r   r   r{   r|   rX   groupsvalues
isinstancer)   strr}   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   -  s,    
B5'BsG
 #<4D	rH	-BW:%r:...<TC'TAQAQAS'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]d^ 	 IJcdd 	
e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H IdJE3L x)x{V78E3RtXFr   c                     t        dgdgdgd      } d}t        j                  t        |      5  | j	                  dd      }d d d        t        j                  t        d	      5  d
    d d d        y # 1 sw Y   3xY w# 1 sw Y   y xY w)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	2B
7C		#	#M	= %ZZ!Z$%	z)R	S 
3 % % s   A6'B6A?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   rx   ri   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      s  
  	     8 		c
C#,-Sq678*+	+	,f5P.QR e}% & 	 	 	 	 	 	   6(  >?PG @PGf  45 6  45*RVVRWW,=>Q ? 6Q2  >?BP @BPJ  45 6  45*RVVRWW,=>Q ? 6Q, !CD E  >?LG @LG^  45 6  45*RVVRWW,=>Q ? 6Q2  >?TG @TGnr   