
    OwgH                     0   d dl Z d dlZd dl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      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&                  j1                  d      ej&                  j)                  deeeeg      d               Zy)    N)lib)	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        d      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      @      @abccategory)      	   20130101r   )periods
US/Eastern)r   tzz1 ss)r   freq)	groupintfloatstringcategory_stringcategory_intdatetime
datetimetz	timedeltacolumns)r   listr   astyper   pdtimedelta_range)selfdfs     ]/var/www/horilla/myenv/lib/python3.12/site-packages/pandas/tests/groupby/test_numeric_only.pyr,   zTestNumericOnly.df   sq     " (u+#)$u+#6#=#=j#I )&z1=(Q<P//qsK


0 	    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   r)   	Timedeltar   getattrtmassert_frame_equalreindex_liker&   _check)r+   r,   r/   expected_columns_numericgbexpectedresultexpected_columnss           r-   test_averageszTestNumericOnly.test_averages5   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Kr.   minmaxc                 J    t        g d      }|}| j                  ||||       y )N)r   r   r   r!   r"   r#   r$   r   r?   r+   r,   r/   rD   r@   s        r-   test_extremazTestNumericOnly.test_extremaY   s0    
 !

 $4 B 02JKr.   firstlastc                 J    t        g d      }|}| j                  ||||       y )N)r   r   r   r    r!   r"   r#   r$   rI   rJ   s        r-   test_first_lastzTestNumericOnly.test_first_lastm   s.     	
 $4 B 02JKr.   sumcumsumc                     t        g d      }t        g d      }|dk(  rt        g d      }| j                  ||||       y )Nr3   )r   r   r   r!   r$   rQ   )r   r   r!   r$   rI   )r+   r,   r/   r@   rD   s        r-   test_sum_cumsumzTestNumericOnly.test_sum_cumsum   sF    #()I#J  C
 X$%RSB 02JKr.   prodcumprodc                 J    t        g d      }|}| j                  ||||       y )Nr3   rI   rJ   s        r-   test_prod_cumprodz!TestNumericOnly.test_prod_cumprod   s(     !AB#3 B 02JKr.   cummincummaxc                 J    t        g d      }|}| j                  ||||       y )N)r   r   r!   r"   r#   r$   rI   rJ   s        r-   test_cummin_cummaxz"TestNumericOnly.test_cummin_cummax   s.     !S

 $4 B 02JKr.   c                 .   |j                  d      }|j                  d      rt        nt        }|dv rbdj	                  dd| dt        j                  d| d	      d
g      }t        j                  ||      5   t        ||              d d d        n|dv rtdj	                  dt        j                  d| d	      t        j                  d| d      g      }t        j                  ||      5   t        ||              d d d        n1 t        ||             }t        j                  |j                  |       |dvr}dj	                  ddd
d| dt        j                  d| d	      t        j                  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)rF   rG   rX   rY   rQ   rU   |zCategorical is not orderedzCannot perform z with non-ordered Categoricalagg function failed [how->,dtype->object]*function is not implemented for this dtypematch)rP   r0   r1   rT   z-category type does not support sum operationsz,dtype->string]rL   rM   zcategory type does not supportFr7   )r9   
startswithNotImplementedError	TypeErrorjoinreescapepytestraisesr;   r<   assert_index_equalr&   )	r+   r,   r/   rD   r@   rA   	exceptionmsgrC   s	            r-   r?   zTestNumericOnly._check   s   ZZ  ,2+<+<U+C'	LL((0%fX-JKII :6(/RS@C y4 &#F#%& &88((CII :6(/RSII :6(/RSC y4 &#F#%& & )WR(*F!!&..2JK**((04@%fX-JKII :6(/RSII :6(/RS	C y4 8#F#78 8 )WR(e<F!!&..2BC?& && &"8 8s$   :G32G?"H3G<?HHN)__name__
__module____qualname__rk   fixturer,   markparametrizerE   rK   rO   rS   rW   r[   r?    r.   r-   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1Dr.   r   r8   )TFNc                 0   |dv rt        j                  d       |dv r1d}| j                  t         j                  j	                  |             t        t        j                  j                  d      j                  d      g d	      }d
|d<   g d}|j                  |      }t        ||      }t        ||      }	ddi}
|||
d<   d}d}d| d}|||v rd}|dv rQt        j                  t        |      5  t        j                   t"        |      5   ||	i |
 d d d        d d d        y t        j                  t        |      5   ||	i |
 d d d        y ||vr/d}t        j                  t        |      5   ||	i |
 d d d        y ||s|dvrd}|r!dd l}t        |j&                  j(                  f}nt        }t        j                  |ddj+                  |       d      5  t        j                   t"        |      5   ||	i |
 d d d        d d d        y t        j                   t"        |      5   ||	i |
}d d d        |r|j-                  d	      j.                  n|j.                  } t        ||      |	 j.                  }|dk(  r|s|j1                  t2              }t        j4                  |       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# 1 sw Y   xY w# 1 sw Y   y xY w# 1 sw Y   xY w)N)idxmaxidxminz5idxmax and idx_min tested in test_idxmin_idxmax_axis1)corrwithskewzDGH#47723 groupby.corrwith and skew do not correctly implement axis=1)reasonr   )
      )ABCDr%   xE)
r   r   r   r   r   r   r   r   r   r~   axisr   r8   )rU   rQ   difffillna
pct_changerankshift)rU   rQ   r   r   r   r   rY   rX   ry   rx   r   zDataFrameGroupBy.z with axis=1 is deprecated1got an unexpected keyword argument 'numeric_only')rU   rQ   rb   z)got an unexpected keyword argument 'axis')r   r   )z"not supported between instances ofz2can't multiply sequence by non-int of type 'float'unsupported operand typezhas no kernelr   (r^   )r   )rk   skipapplymarkerrt   xfailr   nprandomdefault_rngstandard_normalr9   r;   r	   rl   rg   r<   assert_produces_warningFutureWarningpyarrowr   ArrowNotImplementedErrorrh   dropTr(   r   assert_equal)requestgroupby_funcr8   using_infer_stringro   r,   groupsrA   r/   argskwargsno_argshas_axiswarn_msgmsgspaerrsrC   df_expectedrB   s                       r-   test_axis1_numeric_onlyr      s   ++KL++TFKK--S-9:	
		a 009CW
B BsG+F	F	BR&F"<4Da[F!-~ UGH #<.0JKHLG$;A00y4 ,//XN ,D+F+,, , y4 (''( (	X	%9]]9C0 	$D#F#	$ 	$ 
l M 9
  rvv>>?DD]]4388D>*:!'<= 	(++MJ (''(	( 	( ''XF 	-T,V,F	- 1=bggcg*,,"$$57;5t<>>7"<  u-H
)W, ,, ,( (	$ 	$.( (	( 	(	- 	-sl   8K	KK		K<	K(+L 	K4L <	LK	KKK%(K14K=	9L  L	Lzkernel, has_arg))allF)anyF)bfillF)corrT)rz   T)covT)rY   T)rX   T)rU   T)rQ   T)r   F)ffillF)r   F)rL   T)rx   T)ry   T)rM   T)rG   T)r0   T)r1   T)rF   T)nthF)nuniqueF)r   F)rT   T)quantileT)semT)r{   T)stdT)rP   T)varTTFkeysa1a2c                 J   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        ||       }|r|du r ||i |}	d|	j                  vsJ y | d	v s| d
v rZ|t        j                  u rH| dk(  rt        nd }
d}t        j                  |
|      5   ||i |}	d d d        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}t#        j$                  ||      5   ||i | 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   y xY w# 1 sw Y   y xY w# 1 sw Y   y xY w)Nr   r         )r   r   a3br8   Tr   rd   )r   r   r   r   r   r   r   r   %DataFrameGroupBy.fillna is deprecatedrb   r]   r^   znot allowed for this dtype+cannot be performed against 'object' dtypeszmust be a string or a.* numberr   ra   r_   r`   ry   z8'<' not supported between instances of 'type' and 'type'rx   z8'>' not supported between instances of 'type' and 'type'r   )r   r   )r   objectr	   r   
no_defaultr9   r;   r&   r   r<   r   re   rf   rg   rh   ri   rj   rk   rl   )kernelhas_argr8   r   r,   r   r   rA   r/   rC   warnro   rn   s                r-   test_numeric_onlyr   *  sc   T 
1a&Aq!f1x<P	QB"62.D3>>1R7UF	D	BR F<4'((&..((( 	## RR. !'( 2}5''C8 	-T,V,F	-fnn$$$	4'''
 ,2+<+<U+C'	hh,=0*<		6vhoNO

 XLCxLC]]9C0 	$D#F#	$ 	$S^^;]]P
 	$ D#F#	$ 	$
 ////s~~---]]9,GH 	$D#F#	$ 	$K	- 	-4	$ 	$	$ 	$	$ 	$s0   ?	G4	H	H"	H4G>H
HH"z4ignore:Downcasting object dtype arrays:FutureWarningdtypec                    g d}t        g d|       }|j                  |      }|dk(  rt        ||      rJ y t        ||      }t        g d      }|j                  |      }t        ||      }	t	        ||      }
d}d}||v rk| t
        u rc|dk(  rd}nd	}|d
k(  rt        nd }d}t        j                  ||      5  t        j                  t        |      5   ||
  d d d        d d d        n| t
        u r|d
k(  rt        nd }d}t        j                  ||      5   ||
 }d d d        t        j                  ||      5   |	|
 }d d d        ||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(  rR|dk(  rMd}t        j                  t        |      5   ||
ddi} ||
ddi}d d d        t        j                         y  ||
ddi} ||
ddi}t        j                  ||       y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   wx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   xY w)N)r   r   r   )r   r   r   )r   rz   )r   r   rY   rX   rU   rQ   r   )rL   rM   r   r   r   r   rP   r   r   r   r0   r1   rF   rG   rT   r{   r   r   z!is not supported for object dtyper   r   rb   z"SeriesGroupBy.fillna is deprecated)rL   rM   rG   r0   r1   rF   rT   r   r   r{   r   rP   r   rY   rX   rU   rQ   r   r8   Tr^   )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-Allowing bool dtype in SeriesGroupBy.quantileF)r   r9   hasattrr;   r	   r   r   r<   r   rk   rl   rg   r(   assert_series_equalrh   bool)r   r   r   grouperserrA   r/   expected_serexpected_gbexpected_methodr   fails_on_numeric_object
obj_resultro   r   r   rC   rB   has_numeric_onlys                      r-   "test_deprecate_numeric_only_seriesr     s    G
%
(C	W	Bz!2|,,,R&F)$L&&w/Kk<8O"<5DJ* ..5F?:%?C5C , 8}d:''H= 	y4 	 	 
& , 8}d7''H= 	#T]F	#''H= 	.&-H	.:%v.H
vx0& ++A]]9C0 	-D,t,	- 	-	&hh
 ]]9C0 	-D,t,	- 	-	$<:5=''SA 	9T55Ft8%8H	9 	vx01D144e4
vx0s 	 		# 	#	. 	.6	- 	-	- 	-	9 	9s`   ;J
I=J
JJ$!	J1)	J=&K	=J	J

JJ!$J.1J:=K	K)ri   numpyr   rk   pandas._libsr   pandasr)   r   r   r   r   r   pandas._testing_testingr<   pandas.tests.groupbyr	   r   rt   ru   r   r   r   filterwarningsr   r   r   r   r   rv   r.   r-   <module>r      s#   	       8{D {D| )<=T* >T*n  #H $s~~)FG4&4,!78@$ 9 HI#L@$F RS4eV"<=t1 > Tt1r.   