
    .i;                        d dl Z d dlZd dlmZ d dlmZ d dlZd dlmZm	Z	m
Z
mZmZ d dlmZ d dlmZ  G d d      Zej&                  j)                  dg d	      ej&                  j)                  d
ddej*                  g      ej&                  j)                  ddgddgg      d                      Zej&                  j)                  deeeeg      d        Zy)    N)lib)Pandas4Warning)	DataFrameIndexSeries	Timestamp
date_range)get_groupby_method_argsc                      e Zd Zej                  d        Zej                  j                  dddg      d        Zej                  j                  dddg      d        Z	ej                  j                  dd	d
g      d        Z
ej                  j                  dddg      d        Zej                  j                  dddg      d        Zej                  j                  dddg      d        Zd Zy)TestNumericOnlyc                 "   t        g dg dg dt        g dd      t        g dt              t        t        d            j	                  d      g d	t        d
d      t        d
dd      t        j                  ddd      d
g d      }|S )N)   r      )r   r      )g      @g      @      @)abcstrdtypeabccategory)      	   20130101r   )periods
US/Eastern)r   tzz1 ss)r   freq)
groupintfloatstringobjectcategory_stringcategory_intdatetime
datetimetz	timedelta)columns)r   r   r'   listastyper	   pdtimedelta_range)selfdfs     d/var/www/app/trading-bot/venv/lib/python3.12/site-packages/pandas/tests/groupby/test_numeric_only.pyr3   zTestNumericOnly.df   s~     " ( > ?#)$u+#6#=#=j#I )&z1=(Q<P//qsK
4 	    methodmeanmedianc                    t        g d      }|j                  d      }t        ddgddgt        j                  d      t        j                  d      gd	d
gt        d      t        d      gt        dd      t        dd      gdt        ddgd      g d      } t        ||      d      }t        j                  |j                  |      |       |j                  }| j                  ||||       y )Nr$   r%   r)   r#   g      @r   g      @r   z1.5s3sg      ?r   z2013-01-01 12:00:00z2013-01-03 00:00:00r   )r    )r)   r%   r,   r$   r*   r+   r   r   )name)indexr-   Tnumeric_only)r   groupbyr   r0   	Timedeltar   getattrtmassert_frame_equalreindex_liker-   _check)r2   r3   r6   expected_columns_numericgbexpectedresultexpected_columnss           r4   test_averageszTestNumericOnly.test_averages7   s     $))I#J ZZ !$as ll62BLL4FGQx3434
 3E3E AW-!
. %V$$7
f11(;XF#++B 02JKr5   minmaxc                 J    t        g d      }|}| j                  ||||       y )N)r$   r%   r&   r)   r*   r+   r,   r   rF   r2   r3   r6   rK   rG   s        r4   test_extremazTestNumericOnly.test_extrema[   s0    
 !

 $4 B 02JKr5   firstlastc                 J    t        g d      }|}| j                  ||||       y )N)	r$   r%   r&   r'   r(   r)   r*   r+   r,   rP   rQ   s        r4   test_first_lastzTestNumericOnly.test_first_lasto   s.     

 $4 B 02JKr5   sumcumsumc                     t        g d      }t        g d      }|dk(  rt        g d      }| j                  ||||       y )Nr:   )r$   r%   r&   r)   r,   rX   )r$   r%   r)   r,   rP   )r2   r3   r6   rG   rK   s        r4   test_sum_cumsumzTestNumericOnly.test_sum_cumsum   sF    #()I#J  C
 X$%RSB 02JKr5   prodcumprodc                 J    t        g d      }|}| j                  ||||       y )Nr:   rP   rQ   s        r4   test_prod_cumprodz!TestNumericOnly.test_prod_cumprod   s(     !AB#3 B 02JKr5   cummincummaxc                 J    t        g d      }|}| j                  ||||       y )N)r$   r%   r)   r*   r+   r,   rP   rQ   s        r4   test_cummin_cummaxz"TestNumericOnly.test_cummin_cummax   s.     !S

 $4 B 02JKr5   c                 X   |j                  d      }|j                  d      rt        t        fnt        }|dv rgdj	                  dd| dt        j                  d| d	      d
d| dg      }t        j                  ||      5   t        ||              d d d        n|dv rydj	                  dt        j                  d| d	      t        j                  d| d      d| dg      }t        j                  ||      5   t        ||              d d d        n1 t        ||             }t        j                  |j                  |       |dvrdj	                  ddd
d| dt        j                  d| d	      t        j                  d| d      d| dg      }t        j                  ||      5   t        ||      d       d d d        y  t        ||      d      }t        j                  |j                  |       y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nr#   cum)rM   rN   r_   r`   rX   r\   |zCategorical is not orderedzCannot perform z with non-ordered Categoricalagg function failed [how->,dtype->object]*function is not implemented for this dtypez(dtype 'str' does not support operation ''match)rW   r7   r8   r[   z-category type does not support sum operationsz,dtype->string]rS   rT   zcategory type does not supportFr>   )r@   
startswithNotImplementedError	TypeErrorjoinreescapepytestraisesrB   rC   assert_index_equalr-   )	r2   r3   r6   rK   rG   rH   	exceptionmsgrJ   s	            r4   rF   zTestNumericOnly._check   sC   ZZ 
 170A0A%0H ),i 	 LL((0%fX-JKII :6(/RS@>vhaH	C y4 &#F#%& &88((CII :6(/RSII :6(/RS>vhaH	C y4 &#F#%& & )WR(*F!!&..2JK**((04@%fX-JKII :6(/RSII :6(/RS>vhaH
C y4 8#F#78 8 )WR(e<F!!&..2BCC& && &$8 8s$   HH7H HH H)N)__name__
__module____qualname__rs   fixturer3   markparametrizerL   rR   rV   rZ   r^   rb   rF    r5   r4   r   r      s(    ^^ > [[X'9:!L ;!LF [[Xu~6L 7L& [[X'89L :L$ [[Xx'89	L :	L [[X	':;L <L [[X(';<	L =	L6Dr5   r   zkernel, has_arg))allF)anyF)bfillF)corrT)corrwithT)covT)r`   T)r_   T)r\   T)rX   T)diffF)ffillF)rS   T)idxmaxT)idxminT)rT   T)rN   T)r7   T)r8   T)rM   T)nthF)nuniqueF)
pct_changeF)r[   T)quantileT)semT)skewT)kurtT)stdT)rW   T)varTr?   TFkeysa1a2c                    t        ddgddgddgdt        gz  d      }t        | |      }|t        j                  u ri nd|i}|j                  |      }t        ||       }|rO|du rK| dk(  r	t        }	d	}
nd }	d
}
t        j                  |	|
      5   ||i |}d d d        dj                  vsJ y | dv s| dv r+|t        j                  u r ||i |}d|j                  v sJ y |r|dusJ | j                  d      rt        nt        }dj                  dddddt        j                   d|  d      g      }
| dk(  rd}
n| dk(  rd}
n| dk(  rd}
t#        j$                  ||
      5  | dk(  r	t        }	d	}
nd }	d
}
t        j                  |	|
      5   ||i | d d d        d d d        y |s?|t        j                  ur-t#        j$                  t        d      5   ||i | d d d        y | dv sJ |t        j                  u sJ t#        j$                  t        d      5   ||i | d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w# 1 sw Y   y xY w# 1 sw Y   y xY w) Nr   r         )r   r   a3r   r?   Tr   z'DataFrameGroupBy.corrwith is deprecated rj   r   rl   )r   r   r   r   r   r   rd   re   znot allowed for this dtypez+cannot be performed against 'object' dtypesz!must be a string or a real numberzunsupported operand typerh   rf   rg   r   4dtype 'object' does not support operation 'quantile'r   z8'<' not supported between instances of 'type' and 'type'r   z8'>' not supported between instances of 'type' and 'type'1got an unexpected keyword argument 'numeric_only')r   r   )r   r'   r
   r   
no_defaultr@   rB   r   rC   assert_produces_warningr-   rm   rn   ro   rp   rq   rr   rs   rt   )kernelhas_argr?   r   r3   argskwargsrH   r6   warnrw   rJ   rv   s                r4   test_numeric_onlyr      s   T 
1a&Aq!f1x<P	QB"62.D3>>1R7UF	D	BR F<4'Z!D;CDC''C8 	-T,V,F	-&..((( 	## HH. ((fnn$$$	4'''
 ,2+<+<U+C'	hh,=3*<		6vhoNO	
 ZHCxLCxLC]]9C0 	(#%?++D< (''(	( 	( S^^;]]P
 	$ D#F#	$ 	$
 ////s~~---]]9,GH 	$D#F#	$ 	$q	- 	-Z( (	( 	(	$ 	$	$ 	$sH   	H1%*I
	H>I
	I	I"1H;>I	I

II"I+r   c                 "   g d}t        g d|       }|j                  |      }|dk(  rt        ||      rJ y t        ||      }t        g d      }|j                  |      }t        ||      }	t	        ||      }
d}d}||v r<| t
        u r4|dk(  rd}nd	}t        j                  t        |
      5   ||
  d d d        nA| t
        u r9 ||
 } |	|
 }||v r|j                  t
              }t        j                  ||       d}||vr/d}t        j                  t        |
      5   ||
ddi d d d        y | t
        u r@dj                  g d      }t        j                  t        |
      5   ||
ddi d d d        y | t        k(  r4|dk(  r/d}t        j                  t        |
      5   ||
ddi d d d        y  ||
ddi} ||
ddi}t        j                  ||       y # 1 sw Y   xY w# 1 sw Y   y xY w# 1 sw Y   y xY w# 1 sw Y   y xY w)N)r   r   r   )r   r   r   r   r   )r   r   r`   r_   r\   rX   r   )rS   rT   r   r   r   shiftrW   r   r   r   r7   r8   rM   rN   r[   r   r   r   r   z!is not supported for object dtyperj   )rS   rT   rN   r7   r8   rM   r[   r   r   r   r   r   rW   r   r`   r_   r\   rX   r   r?   Tre   )z@SeriesGroupBy.sem called with numeric_only=True and dtype objectz=Series.skew does not allow numeric_only=True with non-numericz7cum(sum|prod|min|max) is not supported for object dtypezCCannot use numeric_only=True with SeriesGroupBy\..* and non-numericz#Cannot use quantile with bool dtypeF)r   r@   hasattrrB   r
   r'   rs   rt   ro   r/   rC   assert_series_equalrp   bool)r   groupby_funcrequestgrouperserrH   r6   expected_serexpected_gbexpected_methodr   fails_on_numeric_object
obj_resultrw   rJ   rI   has_numeric_onlys                    r4   "test_deprecate_numeric_only_seriesr   O  s4    G
%
(C	W	Bz!2|,,,R&F)$L&&w/Kk<8O"<5DJ, ..5F?:%HC5C]]9C0 	DM	 		&"D):%v.H
vx0( ++A]]9C0 	-D,t,	- 	-	&hh
 ]]9C0 	-D,t,	- 	-	$<:53]]9C0 	.D-u-	. 	. 1D144e4
vx0i	 	>	- 	-	- 	-	. 	.s0   0G!#	G-+	G9(	H!G*-G69HH)rq   rs   pandas._libsr   pandas.errorsr   pandasr0   r   r   r   r   r	   pandas._testing_testingrC   pandas.tests.groupbyr
   r   r|   r}   r   r   r   r$   r%   r'   r   r~   r5   r4   <module>r      s    	   (    8CD CDL  #H $s~~)FG4&4,!78L$ 9 HI#LL$^ 4eV"<=m1 >m1r5   