
    .iwZ                        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j8                  j;                  dg d      d        Zej8                  j;                  dddg      d        Zej8                  j;                  dddg      ej8                  j;                  dej@                  ejB                  g      d               Z"ej8                  j;                  dg d      d        Z#ej8                  j;                  dddg      d         Z$ej8                  j;                  dddg      ej8                  j;                  dej@                  ejB                  g      d!               Z%ej8                  j;                  d"g d#      d$        Z&ej8                  j;                  dg d      d%        Z'ej8                  j;                  dddg      d&        Z(ej8                  j;                  dddg      ej8                  j;                  dej@                  ejB                  g      d'               Z)ej8                  jU                  d(      ej8                  j;                  dg d      d)               Z+y)+    N)Pandas4Warning)Categorical	DataFrameGrouperSeries)get_groupby_method_argsab)keyc                     | dz  S )N    xs    ^/var/www/app/trading-bot/venv/lib/python3.12/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                  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_colr4   ;   s?    	,,q""4Ar2r6B		

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:   H   s6    	,,q=/			

B Ir   c                    t        j                  ||d      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)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_checkrO   Y   s     
	#	#X
 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5AC7CC	CCrI   )r>   r?   rD   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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|   \  }	}
|r{|d2v rd3| d4}
|d5v rmt        }	nf|d"k(  r|d   j                  j                  d6k(  rd7}
nB|dk(  r|d   j                  j                  d6k(  rd8}
n|d9v r|
j                  d:d;      }
n|dk(  rd<}
|dk(  r	t        }d=}nd }d>}t        |	|
| |||||       y )?N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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 deprecatedrU   )r   groupbyhasattr	TypeErrorNotImplementedErrorreescape
ValueErrordtypestoragereplacer   rO   )rI   r"   r$   rK   r.   using_infer_stringr-   rL   rJ   rG   rH   rM   rN   s                r   test_groupby_raises_stringr   p   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
=;D 	IIGH
E;L 	zM;N 	*O;P 	:Q;R 	y"<=S;T 	IIEF
U;\ 	Y VW];^ 	
_;` 	
?@a;b 	c;d 	
e;f 	@Ag;h 	@Ai;j 	
?@k;l 	zm;n 	II=>
o;v w;JE3z  
 
 =\N!LC==!\)bgmm.C.Cy.P WCV#3(=(=(J SC11++h.CZ'ECz!&<E3Rt]HUr   r?   rD   c                     |}|j                  |      }|r|d   }d }t        j                  t        d      5   t	        ||       |       d d d        y # 1 sw Y   y xY w)NrQ   r)   c                     t        d      NTest error messager~   r   s    r   funcz,test_groupby_raises_string_udf.<locals>.func       ,--r   r   r@   r|   rE   rF   r~   rC   )rI   r"   r$   r.   r-   rJ   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        dfi|   \  }}	|r(|t        j                  u rt        }d|j
                   d}	t        ||	| ||d       y )NrQ   r)   rT   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__rO   )
rI   r"   r$   r   r.   r   r-   rJ   rG   rH   s
             r   test_groupby_raises_string_npr      s     
B	r	BW 	

@
 JE3 bgg%E*?+C+C*DDWXE3R"=r   c           
      j   |}t        ||      }|j                  |      }|r|d   }|dk(  rt        |d      rJ y 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)j	                  d*d+g      fd,t        d)j	                  d*d-g      fd.d	d/t        d0fd1t        d2f|   \  }}	|dk(  r	t
        }
d3}nd }
d4}t        ||	| ||||
|       y )5NrQ   r)   rR   rS   z3'all' with datetime64 dtypes is no longer supportedrV   z3'any' with datetime64 dtypes is no longer supportedrW   rT   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{   rU   )r   r|   r}   r~   joinr   rO   )rI   r"   r$   rK   r4   r-   rL   rJ   rG   rH   rM   rN   s               r   test_groupby_raises_datetimer     s    
B"<4D	r	BW:%r:...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( 	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f g3JE3j z!&<E3Rt]HUr   c                     |}|j                  |      }|r|d   }d }t        j                  t        d      5   t	        ||       |       d d d        y # 1 sw Y   y xY w)NrQ   r)   c                     t        d      r   r   r   s    r   r   z.test_groupby_raises_datetime_udf.<locals>.funck  r   r   r   r@   r   )rI   r"   r$   r4   r-   rJ   r   s          r    test_groupby_raises_datetime_udfr   c  s_    	B	r	BW. 
y(<	= C  r   c                     |}|j                  |      }|r|d   }t        j                  t        t	        j
                  d      ft        j                  di|   \  }}t        ||| ||d       y )NrQ   r)   z/datetime64[us] does not support operation 'sum'rT   r   )r|   r   ru   r~   r   r   rf   rO   )	rI   r"   r$   r   r4   r-   rJ   rG   rH   s	            r   test_groupby_raises_datetime_npr   r  sw     
B	r	BW 	IIGH
 	 JE3 E3R"=r   r   )rl   r\   rr   rs   rv   c                     t        g dg dt        d      t        j                  d      d      }|j	                  d      }t        t        d	d
|| g        y )Nr   r   r   r   )daysr'   r	   rQ   z/timedelta64 type does not support .* operationsr>   )r   r*   r3   	timedeltar|   rO   r~   )r   r-   rJ   s      r   test_groupby_raises_timedeltar     sX    	,,q##+		

B 
s	B9

r   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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-d.g      fd/dd0dd1t        dj                  d2d3g      fd4t        dj                  d5d6g      fd7t        dj                  d8d9g      fd:t        d;fd<t        dj                  d=d>g      f|   \  }}	|dk(  r	t        }
d?}nd }
d@}t        ||	| ||||
|       y )ANrQ   r)   rR   rS   rT   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{   rU   )r   r|   r}   r~   r   r   r   rO   )rI   r"   r$   rK   r:   r-   rL   rJ   rG   rH   rM   rN   s               r   test_groupby_raises_categoryr     s   
 
B"<4D	r	BW:%r:...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 	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p qxJE3t z!&<E3Rt]HUr   c                     |}|j                  |      }|r|d   }d }t        j                  t        d      5   t	        ||       |       d d d        y # 1 sw Y   y xY w)NrQ   r)   c                     t        d      r   r   r   s    r   r   z.test_groupby_raises_category_udf.<locals>.func:  r   r   r   r@   r   )rI   r"   r$   r:   r-   rJ   r   s          r    test_groupby_raises_category_udfr   1  sa     
B	r	BW. 
y(<	= C  r   c                     |}|j                  |      }|r|d   }t        j                  t        dft        j                  t        dfi|   \  }}t        ||| ||d       y )NrQ   r)   z/dtype category does not support operation 'sum'z0dtype category does not support operation 'mean'r   )r|   r   ru   r~   rf   rO   )	rI   r"   r$   r   r:   r-   rJ   rG   rH   s	            r   test_groupby_raises_category_npr   A  sq     
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        ||      }|j                  ||      }|r|d   }|dk(  rt        |d      rJ y | xr* t	        d	 |j
                  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        d2j                  d3d4g      fd5dd6dd7t        d2j                  d8d9g      fd:t        d2j                  d;d<g      fd=t        d2j                  d>d?g      fd@t        dAfdBt        d2j                  dCdDg      f|   \  }
}|dk(  r	t        }dE}nd }dF}t        |
|| |||||       y )GNr6   r'   Tr7   r	   )r"   observedr)   rR   c              3   4   K   | ]  }|j                     y wr   )empty).0groups     r   	<genexpr>z;test_groupby_raises_category_on_category.<locals>.<genexpr>r  s     'T'Ts   rD   FrS   rT   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{   rU   )r   r   r|   r}   rV   groupsvaluesr~   r   r   r   r   rO   )rI   r"   r$   rK   r   r:   r-   rL   rJ   empty_groupsrG   rH   rM   rN   s                 r   (test_groupby_raises_category_on_categoryr   W  s    
B5'BsG
 #<4D	rH	-BW:%r:...<TC'TAQAQAS'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OfP 	 IJUfV 	
WfX 	zY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L MfJE3P z!&<E3Rt]HUr   rT   ),r3   r   numpyr   rE   pandas.errorsr   pandasr   r   r   r   pandas._testing_testingrA   pandas.tests.groupbyr   fixturearraydictzipr*   r"   r$   r.   r4   r:   rO   markparametrizer   r   ru   rf   r   r   r   r   r   r   r   r   filterwarningsr   r   r   r   <module>r      s  
  	   (   8 		c
C#,-Sq6tDE*+	+	,f5P.QR e}% & 	 	 	 	  " KM6.  >?qV @qVh  45 6  45*RVVRWW,=>> ? 6>@  >?IV @IVX  45 6  45*RVVRWW,=>> ? 6>( !KL M*  >?OV @OVd  45 6  45*RVVRWW,=>> ? 6>( BC >?LV @ DLVr   