
    bMhJ                     F   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                            dg d          d	             Zej                            d
g d          ej                            dddej        g          ej                            ddgddgg          d                                     Zej                            d          ej                            deeeeg          d                         ZdS )    N)lib)	DataFrameIndexSeries	Timestamp
date_range)get_groupby_method_argsc                      e Zd Zej        d             Zej                            dddg          d             Zej                            dddg          d             Z	ej                            dd	d
g          d             Z
ej                            dddg          d             Zej                            dddg          d             Zej                            dddg          d             Zd ZdS )TestNumericOnlyc                 b   t          g dg dg dt          g dd          t          g dt                    t          t          d                                        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     f/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pandas/tests/groupby/test_numeric_only.pyr3   zTestNumericOnly.df   s     " yy( >>> ???#)$u++#6#6#=#=j#I#I )		&z1===(Q<PPP/qsKKK   
 
 
4 	    methodmeanmedianc                 <   t          g d          }|                    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
        }|                     ||||           d S )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   sL    $))I)I)I#J#J ZZ  !$as l622BL4F4FGQx344344
 3EEE3EEE  AW---  !
 
 
. %V$$$777
f11(;;XFFF#+B 02JKKKKKr5   minmaxc                 \    t          g d          }|}|                     ||||           d S )N)r#   r$   r%   r(   r)   r*   r+   r   rF   r2   r3   r6   rK   rG   s        r4   test_extremazTestNumericOnly.test_extrema[   sK    
 !  

 

 $4 B 02JKKKKKr5   firstlastc                 \    t          g d          }|}|                     ||||           d S )N)	r#   r$   r%   r&   r'   r(   r)   r*   r+   rP   rQ   s        r4   test_first_lastzTestNumericOnly.test_first_lasto   sI     
 
 

 
 $4 B 02JKKKKKr5   sumcumsumc                     t          g d          }t          g d          }|dk    rt          g d          }|                     ||||           d S )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   sr    #()I)I)I#J#J  CCC
 
 X$%R%R%RSSB 02JKKKKKr5   prodcumprodc                 \    t          g d          }|}|                     ||||           d S )Nr:   rP   rQ   s        r4   test_prod_cumprodz!TestNumericOnly.test_prod_cumprod   s=     !A!A!ABB#3 B 02JKKKKKr5   cummincummaxc                 \    t          g d          }|}|                     ||||           d S )N)r#   r$   r(   r)   r*   r+   rP   rQ   s        r4   test_cummin_cummaxz"TestNumericOnly.test_cummin_cummax   sE     !SSS
 

 $4 B 02JKKKKKr5   c                    |                     d          }|                    d          rt          t          fnt          }|dv rd                    dd| dt          j        d| d	          d
d| dg          }t          j        ||          5   t          ||                       d d d            n# 1 swxY w Y   n|dv rd                    dt          j        d| d	          t          j        d| d          d| dg          }t          j        ||          5   t          ||                       d d d            n# 1 swxY w Y   n2 t          ||                      }t          j        |j        |           |dvrd                    ddd
d| dt          j        d| d	          t          j        d| d          d| dg          }t          j        ||          5   t          ||          d           d d d            d S # 1 swxY w Y   d S  t          ||          d          }t          j        |j        |           d S )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   s   ZZ  
 170A0A%0H0HW ),,i 	 LLL((0KfKKKIR6RRRSS@HvHHH	 	C y444 & &#F##%%%& & & & & & & & & & & & & & &888((CIR6RRRSSIR6RRRSSHvHHH	 C y444 & &#F##%%%& & & & & & & & & & & & & & & )WR((**F!&.2JKKK***((04@KfKKKIR6RRRSSIR6RRRSSHvHHH
 
C y444 8 8#F##77778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 )WR((e<<<F!&.2BCCCCCs6   B77B;>B;&EEE3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 ;:!LF [Xu~66L L 76L& [X'899L L :9L$ [Xx'899	L 	L :9	L [X	':;;L L <;L [X(';<<	L 	L =<	L6D 6D 6D 6D 6Dr5   r   r?   )TFNc                    |dv rt          j        d           |dv r5d}|                     t           j                            |                     t          t          j                            d          	                    d          g d	          }d
|d<   g d}|
                    |          }t          ||          }t          ||          }	ddi}
|||
d<   d}d}d| d}|||v rd}|dv rrt          j        t          |          5  t          j        t"          |          5   ||	i |
 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S d S t          j        t          |          5   ||	i |
 d d d            d S # 1 swxY w Y   d S ||vr@d}t          j        t          |          5   ||	i |
 d d d            d S # 1 swxY w Y   d S ||s|dvrd}|r(t          j        d          }t          |j        j        f}nt          }t          j        |dd                    |           d          5  t          j        t"          |          5   ||	i |
 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S t          j        t"          |          5   ||	i |
}d d d            n# 1 swxY w Y   |r|                    d	          j        n|j        } t          ||          |	 j        }|dk    r|s|                    t2                    }t          j        ||           d S )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   r?   )r\   rX   difffillna
pct_changerankshift)r\   rX   r   r   r   r   r`   r_   r   r   r   zDataFrameGroupBy.z with axis=1 is deprecated1got an unexpected keyword argument 'numeric_only')r\   rX   rj   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 kernelzBoperation 'sub' not supported for dtype 'str' with dtype 'float64'pyarrow(re   )r   )rs   skipapplymarkerr|   xfailr   nprandomdefault_rngstandard_normalr@   rB   r	   rt   ro   rC   assert_produces_warningFutureWarningimportorskipr   ArrowNotImplementedErrorrp   dropTr/   r$   assert_equal)requestgroupby_funcr?   using_infer_stringrw   r3   groupsrH   r6   argskwargsno_argshas_axiswarn_msgmsgspaerrsrJ   df_expectedrI   s                       r4   test_axis1_numeric_onlyr      s   +++KLLL+++TFK--S-99:::	
	a  0099CWCWCW
 
 
B BsG+++F	F		BR&&F"<44Da[F!-~ UGH L<KKKHLG$;$;A000y444 , ,/XNNN , ,FD+F+++, , , , , , , , , , , , , , ,, , , , , , , , , , , , , , , , , , , y444 ( (''''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (	X	%	%9]9C000 	$ 	$FD#F###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 
l
 M 9 9	
  	$Y//Brv>?DDD]4'<388D>>'<'<'<=== 	( 	(+MJJJ ( (''''( ( ( ( ( ( ( ( ( ( ( ( ( ( (	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 'XFFF 	- 	-VT,V,,F	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 1=Fbggcg**,,"$57;55t<>7""<"  u--H
)))))s   E+	E 4E E	EE	EEE	FFF	GG"GJ,	J5JJ	JJ		JJ J	KKKzkernel, has_arg))allF)anyF)bfillF)corrT)r   T)covT)r`   T)r_   T)r\   T)rX   T)r   F)ffillF)r   F)rS   T)r   T)r   T)rT   T)rN   T)r7   T)r8   T)rM   T)nthF)nuniqueF)r   F)r[   T)quantileT)semT)r   T)stdT)rW   T)varTTF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}|                    |          }t          ||           }|r|du r ||i |}	d|	j        vsJ d S | d	v s| d
v rb|t          j        u rT| dk    rt          nd }
d}t          j
        |
|          5   ||i |}	d d d            n# 1 swxY w Y   d|	j        v sJ d S |r|dusJ |                     d          rt          nt          }d                    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   ||i | d d d            d S # 1 swxY w Y   d S |sL|t          j        ur>t#          j        t          d          5   ||i | d d d            d S # 1 swxY w Y   d S | dv sJ |t          j        u sJ t#          j        t          d          5   ||i | d d d            d S # 1 swxY w Y   d S )Nr   r         )r   r   a3r   r?   Tr   rl   )r   r   r   r   r   r   r   r   %DataFrameGroupBy.fillna is deprecatedrj   rd   re   znot allowed for this dtypez+cannot be performed against 'object' dtypeszmust be a string or a.* numberr   rh   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'r   )r   r   )r   r&   r	   r   
no_defaultr@   rB   r-   r   rC   r   rm   rn   ro   rp   rq   rr   rs   rt   )kernelhas_argr?   r   r3   r   r   rH   r6   rJ   warnrw   rv   s                r4   test_numeric_onlyr   3  s2   T 
1a&Aq!f1x<PP	Q	QB"62..D3>11RR7UF	D		BR  F 7$<4''(((&.(((((( 	### RRR.. !'( 2 2}}5'C888 	- 	-VT,V,,F	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-fn$$$$$$	 %$4''''
 ,2+<+<U+C+CR''	hh,=0*<	NvNNNOO

 

 ZHCCxLCCxLC]9C000 	$ 	$FD#F###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 
$S^;;]P
 
 
 	$ 	$ FD#F###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$
 /////s~----]9,GHHH 	$ 	$FD#F###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$sH   	CC!C>	FFF	G""G&)G& 	H66H:=H:z4ignore:Downcasting object dtype arrays:FutureWarningr   c                 8   g d}t          g d|           }|                    |          }|dk    rt          ||          rJ d S t          ||          }t          g d          }|                    |          }t          ||          }	t	          ||          }
d}d}||v r| t
          u r|dk    rd}nd	}|d
k    rt          nd }d}t          j        ||          5  t          j
        t          |          5   ||
  d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   n| t
          u r|d
k    rt          nd }d}t          j        ||          5   ||
 }d d d            n# 1 swxY w Y   t          j        ||          5   |	|
 }d d d            n# 1 swxY w Y   ||v r|                    t
                    }t          j        ||           d}||vr@d}t          j
        t          |          5   ||
ddi d d d            d S # 1 swxY w Y   d S | t
          u rUd                    g d          }t          j
        t          |          5   ||
ddi d d d            d S # 1 swxY w Y   d S | t          k    rb|dk    r\d}t          j        t          |          5   ||
ddi} ||
ddi}d d d            n# 1 swxY w Y   t          j        ||           d S  ||
ddi} ||
ddi}t          j        ||           d S )N)r   r   r   )r   r   r   r   r   )r   r   r`   r_   r\   rX   r   )rS   rT   r   r   r   r   rW   r   r   r   r7   r8   rM   rN   r[   r   r   r   z!is not supported for object dtyper   r   rj   z"SeriesGroupBy.fillna is deprecated)rS   rT   rN   r7   r8   rM   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-Allowing bool dtype in SeriesGroupBy.quantileF)r   r@   hasattrrB   r	   r&   r   rC   r   rs   rt   ro   r/   assert_series_equalrp   bool)r   r   r   grouperserrH   r6   expected_serexpected_gbexpected_methodr   fails_on_numeric_object
obj_resultrw   r   r   rJ   rI   has_numeric_onlys                      r4   "test_deprecate_numeric_only_seriesr     s    iiG
%
(
(
(C	W		Bz!!2|,,,,,R&&F)))$$L&&w//Kk<88O"<55DJ* ...5F??:%%HCC5C , 8 8}}d:'H=== 	 	y444                	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 
& , 8 8}}d7'H=== 	# 	#VT]F	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#'H=== 	. 	.&-H	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.:%%v..H
vx000& +++A]9C000 	- 	-FD,t,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-	&hh  
 
 ]9C000 	- 	-FD,t,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-	$<:55='SAAA 	9 	9VT555Fvt8%88H	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	vx000001D11644e44
vx00000s    D%<DD%D	D%D	D%%D),D)!E33E7:E7F&&F*-F*	HH!$H!%	I;;I?I?6KKK)rq   numpyr   rs   pandas._libsr   pandasr0   r   r   r   r   r   pandas._testing_testingrC   pandas.tests.groupbyr	   r   r|   r}   r   r   r   filterwarningsr   r#   r$   r&   r   r~   r5   r4   <module>r      s   				                                   8 8 8 8 8 8CD CD CD CD CD CD CD CDL )<)<)<==U* U* >=U*p      # #H $s~)FGG4&4,!788B$ B$ 98 HGI# #LB$J RSS4eV"<==t1 t1 >= TSt1 t1 t1r5   