
    Owg75                         d dl mZ d dlmZ d dlZd dlZd dlmZm	Z	m
Z
mZmZmZmZmZ d dlmZ  G d d      Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zy)    )product)ascii_lowercaseN)	DataFrameIndex
MultiIndexPeriodSeries	Timedelta	Timestamp
date_rangec                      e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zej*                  j-                  d edd      D  cg c]  }t1        d|dd       c}}}  edd      D  cg c]  }t1        d|dd       c}}}  edd      D  cg c]  }t1        d|ddd       c}}}  edd      D  cg c]  }t3        |d       c}}}  edd      D  cg c]  }t5        dd|       c}}} g      d         Zd! Zd" Zd# Zy$c c}}} w c c}}} w c c}}} w c c}}} w c c}}} w )%TestCountingc                    t        dgdgdgdgdggdg      }|j                  d      }|j                  }t        g d      }t	        j
                  ||j                                t	        j
                  ||j                                y )NabAcolumnsr         r      r   groupbyr   r	   tmassert_series_equalcumcountselfdfgsgexpecteds        Y/var/www/horilla/myenv/lib/python3.12/site-packages/pandas/tests/groupby/test_counting.pytest_cumcountzTestCounting.test_cumcount   sq    usecUSE:SEJJJsOSS/*
x6
x7    c                     t               j                  d      }t        t              j                  d      }t        d      }t	        j
                  ||j                                t	        j
                  ||j                                y Nr   )leveldtypeint64)r   r   r	   objectr   r   r   r   gesees       r$   test_cumcount_emptyz TestCounting.test_cumcount_empty   sg    [  q )&!)))2 !
q"++-0
q"++-0r&   c                 .   t        dgdgdgdgdggdgdgdz        }|j                  d      }|j                  }t        g ddgdz        }t	        j
                  ||j                                t	        j
                  ||j                                y )	Nr   r   r   r      r   indexr   r6   r   r   s        r$   test_cumcount_dupe_indexz%TestCounting.test_cumcount_dupe_index)   s    USEC53%#/#qcAg
 JJsOSS/!q9
x6
x7r&   c                 f   t        j                  ddgddgddgddgddgg      }t        dgdgdgdgdggdg|      }|j                  d      }|j                  }t        g d|	      }t        j                  ||j                                t        j                  ||j                                y )
Nr   r   r   r   r   r   r5   r   r7   )	r   from_tuplesr   r   r   r	   r   r   r   r   mir    r!   r"   r#   s         r$   test_cumcount_mizTestCounting.test_cumcount_mi5   s    ##aVaVaVaVaV$LMusecUSE:SEQSTJJsOSS/4
x6
x7r&   c                 2   t        dgdgdgdgdggdgdgdz        }|j                  g d      }|j                  }t        g ddgdz  	      }t	        j
                  ||j                                t	        j
                  ||j                                y )
Nr   r   r   r   r4   r5   r   r   r   r   r   r   r7   r   r   s        r$   test_cumcount_groupby_not_colz*TestCounting.test_cumcount_groupby_not_col@   s    USEC53%#/#qcAg
 JJ'SS/!q9
x6
x7r&   c                    t        dt        d      i      }|j                  d      }|j                  }t	        g d      }t        j                  ||j                                t        j                  ||j                                y )Nr   aaabar?   r   listr   r   r	   r   r   ngroupr   s        r$   test_ngroupzTestCounting.test_ngroupL   sa    T']+,JJsOSS/*
x4
x5r&   c                 &   t        dt        d      i      }|j                  d      }|j                  }t	        t        d      d      }t        j                  ||j                                t        j                  ||j                                y )Nr   abcder4   r,   r*   )	r   rD   r   r   r	   ranger   r   rE   r   s        r$   test_ngroup_distinctz!TestCounting.test_ngroup_distinctV   sg    T']+,JJsOSS%('2
x4
x5r&   c                    t        ddgdz  i      }|j                  d      }|j                  }t        dgdz        }t	        j
                  ||j                                t	        j
                  ||j                                y )Nr   r   r4   )r   r   r   r	   r   r   rE   r   s        r$   test_ngroup_one_groupz"TestCounting.test_ngroup_one_group`   sg    aS1W~&JJsOSS1#'?
x4
x5r&   c                     t               j                  d      }t        t              j                  d      }t        d      }t	        j
                  ||j                                t	        j
                  ||j                                y r(   )r   r   r	   r-   r   r   rE   r.   s       r$   test_ngroup_emptyzTestCounting.test_ngroup_emptyj   sg    [  q )&!)))2 !
q"))+.
q"))+.r&   c                     t        dt        d      i      }t        t        d            }t        j                  |j                  |      j                         |j                  |      j                                y )Nr   rB   )r   rD   r	   r   r   r   rE   )r   r    ss      r$    test_ngroup_series_matches_framez-TestCounting.test_ngroup_series_matches_framet   sU    T']+,4=!
rzz!}335qyy|7J7J7LMr&   c                 ,   t        dt        d      idgdz        }|j                  d      }|j                  }t	        g ddgdz        }t        j                  ||j                                t        j                  ||j                                y Nr   rB   r   r4   r7   r?   rC   r   s        r$   test_ngroup_dupe_indexz#TestCounting.test_ngroup_dupe_indexz   sq    T']+A37;JJsOSS/!q9
x4
x5r&   c                 d   t        j                  ddgddgddgddgddgg      }t        dt        d      i|      }|j	                  d      }|j
                  }t        g d|      }t        j                  ||j                                t        j                  ||j                                y )Nr   r   r   r   rB   r7   r?   )
r   r:   r   rD   r   r   r	   r   r   rE   r;   s         r$   test_ngroup_mizTestCounting.test_ngroup_mi   s    ##aVaVaVaVaV$LMT']+26JJsOSS/4
x4
x5r&   c                 0   t        dt        d      idgdz        }|j                  g d      }|j                  }t	        g ddgdz        }t        j                  ||j                                t        j                  ||j                                y rS   rC   r   s        r$   test_ngroup_groupby_not_colz(TestCounting.test_ngroup_groupby_not_col   sr    T']+A37;JJ'SS/!q9
x4
x5r&   c                 `   t        g ddg      }|j                  dg      }t        g d      }t        g d      }t        j                  ||j
                  dz
  |z
         t        j                  ||j                  d             t        j                  ||j                  d	             y )
N)r   r   r   r   r   r   r   )r   r   r   r   r   )r   r   r   r   r   r   T)	ascendingF)r   r   r	   r   r   ngroupsrE   )r   r    r!   rZ   
descendings        r$   test_ngroup_descendingz#TestCounting.test_ngroup_descending   s    03%@JJu?+	O,

zAIIMY+FG
y!((T(*BC
z188e8+DEr&   c                 2   t        ddgddgddgddgddggddg      }|j                  ddg      }|j                         }|j                         }t	        g d      }t	        g d	      }t        j                  ||       t        j                  ||       y )
Nr   xyr   r   Xr   r   r?   )r   r   rE   r   r	   r   r   )r   r    r!   g_ngroup
g_cumcountexpected_ngroupexpected_cumcounts          r$   test_ngroup_matches_cumcountz)TestCounting.test_ngroup_matches_cumcount   s    3Z#sc3Z#sc3ZH#J
 JJSz"88:ZZ\
 1"?3
x9
z+<=r&   c                    t        t        d      d      D ]  }t        d|i      }|j                  dg      }t	        t        |            }|D cg c]  }|j                  |       }}t        |      D cg c]  \  }}|d | j                  |       }}}t        j                  |j                         t        |             t        j                  |j                         t        |              y c c}w c c}}w )Nr      )repeatr   )r   rI   r   r   sortedsetr6   	enumeratecountr   r   rE   r	   r   )	r   pr    r!   ordervalngroupdi
cumcounteds	            r$   test_ngroup_cumcount_pairz&TestCounting.test_ngroup_cumcount_pair   s    q!, 		EAC8$B

C5!A3q6NE345Cu{{3'5G59B1Fvq#!BQ%++c*FJF""188:vg?""1::<
1CD		E
 6Fs   C79C<c                 j   t        dt        j                  j                  d      j	                  t        d      d      i      }|j                  d|      }d|d<   d|d<   t        |      D ]Q  \  }\  }}||j                  |j                  df<   t        |j                        D ]  \  }}||j                  |df<    S t        j                  t        |d   j                        |j                                t        j                  t        |d   j                        |j                                y )	Nr   r   abcdefd   )sortgroup_idgroup_index)r   nprandomdefault_rngchoicerD   r   rl   locr6   r   r   r	   valuesrE   r   )	r   rx   r    r!   rr   _groupjinds	            r$   "test_ngroup_respects_groupby_orderz/TestCounting.test_ngroup_respects_groupby_order   s   RYY2215<<T(^SQRSJJsJ&:=&q\ 	/MAz5./BFF5;;
*+#EKK0 /3-.sM)*/	/
 	vbn&;&;<ahhjI
vb&7&>&>?Nr&   datetimeliker   rh   z2016-05-02dz 20:09:25+00:00z	 20:09:25UTC)tzh)unit2Wi  )freqyearmonthc                     t        g d|d      }|j                  d      j                         }t        dddgiddg	      }d|j                  _        t        j                  ||       y )
N)r   r   r   )r_   r`   r_   r`   r   r   r   r   r7   )r   r   rm   r6   namer   assert_frame_equal)r   r   r    resr#   s        r$   test_count_with_datetimelikez)TestCounting.test_count_with_datetimelike   s]     _<@Ajjo##%cAq6]3*=!
h,r&   c                 R   t        t        j                  t        j                  gddgddgd      }|j                  ddg      j                  j                         }t        g ddggg g gddg      }t        g |t        j                  d	
      }t        j                  ||d       y )Nr   r   r   r   r   BCr   r   )levelscodesnamesr   )r6   r+   r   F)check_index_type)r   r|   nanr   r   rm   r   r	   r,   r   r   )r   r    resultr<   r#   s        r$   (test_count_with_only_nans_in_first_groupz5TestCounting.test_count_with_only_nans_in_first_group   s    bffbff-S#JaVLMS#J'))//1S#J/BxSzR"BbhhSA
vx%Hr&   c                     t        g dddt        j                  ddgd      }|j                  dg      j	                         }t        t        g dd	      d
g di      }t        j                  ||       y )N)r   r   r   r   r   r4   rh   r   r   )r   r   r   )g        g      @g      @g      @r   r   )r   r   r   r   )r6   data)r   r|   r   r   rm   r   r   r   )r   r    r   r#   s       r$   4test_count_groupby_column_with_nan_in_groupby_columnzATestCounting.test_count_groupby_column_with_nan_in_groupby_column   sg    _Aq"&&!Q3GHIjj#%%',37sL>Q
 	h,r&   c                    t        ddd      }t        t        j                  d      |t        j                  d      g      }|j	                  d       }|j                         }t        t        j                  d      t        j                  d      |g      }|j	                  d       }|j                         }t        j                  ||       y )Nz1/1/20125min
   )startr   periodsr7   c                     | d   dz  dk(  S )Nr   r   r    r_   s    r$   <lambda>z@TestCounting.test_groupby_count_dateparseerror.<locals>.<lambda>       !qA r&   c                     | d   dz  dk(  S )Nr   r   r   r   s    r$   r   z@TestCounting.test_groupby_count_dateparseerror.<locals>.<lambda>   r   r&   )r   r	   r|   aranger   rm   r   r   )r   drsergroupedr   r#   s         r$   !test_groupby_count_dateparseerrorz.TestCounting.test_groupby_count_dateparseerror   s    jvrB RYYr]2ryy}*=>++56RYYr]299R="*=>++56==?
vx0r&   N)__name__
__module____qualname__r%   r2   r8   r=   r@   rF   rJ   rL   rN   rQ   rT   rV   rX   r]   rf   rt   r   pytestmarkparametrizerI   r   r
   r   r   r   r   r   ).0rr   r   r_   r
   r   s   000000r$   r   r      s_   81
8	8
8666/N666	F>EO [[CHA;OOaY!C89O=B1a[IIY!C	23IGLQPQ{SS!Y!C	2u=S-21a[99Yqs#9<A!QKHHqVD2H	
	-	-I-1E PIS9Hs   D)D0+D7D>:Er   c                  .   t        t        d      t        j                  d      j	                  d      d      } t        ddgt        ddgd	      d
      }| j                  d      j                  j                         }t        j                  ||       y )Nababrh   ztimedelta64[ns])r!   deltar   r   r   r!   r   r   r6   r   )r   rD   r|   r   astyper	   r   r   r   rm   r   r   )r    r#   r   s      r$   #test_groupby_timedelta_cython_countr     sw    	8nryy|':':;L'MN
B q!fE3*3$?gNHZZ_""((*F8V,r&   c                     d} t        d| dz  d      }t        t        j                  j	                  d      j                  t        t              |       t        j                  j	                  d      j                  dd|       t        j                  j	                  d      j                  |       j                  d	      t        j                  j	                  d      j                  d
d|       t        j                  j	                  d      j                  ||       t        j                  j	                  d      j                  |       j                  d	      t        j                  j	                  d      j                  |       j                  d	      t        j                  j	                  d      j                  ||       t        j                  j	                  d      j                  |d      z
  t        j                  j	                  d      j                  t        t              |       d	      }|j                  j                  g d      D ]Q  }t        j                  |j                  t        j                  j	                  d      j                  | | dz        |f<   S |d   j                  d      |d<   ddddgfD ]  }|j!                  |      j#                         }d}t%        j&                  t(        |      5  |j!                  |      j+                  t        j"                        j                  |d      }d d d        t%        j,                  |        y # 1 sw Y   "xY w)Ni   z
2015-08-30r   min)r   r   r   r   r4   r   ir   )	1st2nd3rd4th5th6th7th8th9th)r   r   r   r   categoryr   r   z7DataFrameGroupBy.apply operated on the grouping columns)match)axis)r   r   r|   r}   r~   r   rD   r   integersstandard_normalroundr   dropr   r   r   r   rm   r   assert_produces_warningDeprecationWarningapplyr   )nr   r    colkeyleftmsgrights           r$   
test_countr   
  s   A	L!r'	>B	99((+2243H!L99((+44Q1=99((+;;A>DDQG99((+44S"a@99((+222q999((+;;A>DDQG99((+;;A>DDQG99((+222q9ii##A&--b!4599((+2243H!L	

B zz45 JCE66ryy$$Q'..q!r':C?@J 5	  ,BuIuuen- +zz#$$&G''(:#F 	MJJsO)))//:??!?LE	M
dE*+	M 	Ms   A M##M,	c                  H   t        g ddt        j                  dgdt        j                  t        j                  ggg d      } | j                  d      j	                         }| j                  dd	      j	                         }t        dd
gddggddgddg      }d|j
                  _        t        j                  ||j                                t        j                  ||       | j                  d      d   j	                         }t        j                  ||d          y )N)r   r   foor   barr   r   r   r   F)as_indexr   r   r   r   r5   )r   r|   r   r   rm   r6   r   r   r   reset_indexr   )r    count_ascount_not_asr#   count_Bs        r$   test_count_non_nullsr   *  s     
	BFFE*Q,?@
B
 zz#$$&H::cE:288:L1a&1a&)C:aVLHHNN,(<(<(>?(H-jjoc"((*G7HSM2r&   c                  :   t        dgdz  dgdz  z   dgdz  dgdz  z   d      } | j                  d      j                  j                         }t	        ddgt        ddgd      d      }t        j                  ||       t        dt        j                  t        j                  gdgdz  z   dgdz  dgdz  z   d      } | j                  d      j                  j                         }t	        d	dgt        ddgd      d      }t        j                  ||       y )
Nr   r   r   r   )r   cr   r   r   r   )
r   r   r   rm   r	   r   r   r   r|   r   r    r   r#   s      r$   test_count_objectr   >  s    	#cUQY.aS1WsQw5FG	HBZZ_$$&Fq!fE1a&s$;#FH68,	#rvvrvv.#:!qA3QR7ARS	TBZZ_$$&Fq!fE1a&s$;#FH68,r&   c                  l   t        j                  t         j                  j                  d      j	                  ddd      t         j                  j                  d      j	                  ddd      f      j                  d      } t        | g d      }t         j                  ||dk(  <   |j                  dd	g      j                         }d
D ]g  }|d   j                  |      |d<   |d   j                  |      |d<   |j                  dd	g      j                         }t        j                  ||       i y )Nr   r   r4   )rw   r   float64)r   r   r   dr   r   r   )float32r-   r   r   )r|   hstackr}   r~   r   r   r   r   r   rm   r   r   )valsr    r#   tr   s        r$   test_count_cross_typer   J  s	    99II!!!$--aH=II!!!$--aH=	

 fY 	 
4!5	6B&&BrQwKzz3*%++-H" 0S'..#3S'..#3S#J'--/
fh/	0r&   c                     t        t        j                  g dt        j                        t        j                  g dt        j                        t        j                  g dt        j
                        t        d      d      } | j                  d      j                         }t        ddgddgddgdt        t        d	      d
            }t        j                  ||       y )N)r   r   r   rw   )r   r   r      )rh   r4   r      r   )r   r   r   grpr   r   )r   r   r   abr   r7   )r   r|   arrayint8uint32int16rD   r   rm   r   r   r   r   s      r$   test_lower_int_prec_countr   _  s    	."''2,		2,1>		

B ZZ$$&F!fAq6A/uT$Ze7TH &(+r&   c                  `    G d dt                G fdd      } t        t        d      D cg c]	  } |         c}t        d      d      }|j	                  d      j                         }t        d	d
d
git        t        d      d            }t        j                  ||       y c c}w )Nc                       e Zd Zy)Atest_count_uses_size_on_exception.<locals>.RaisingObjectExceptionN)r   r   r   r   r&   r$   RaisingObjectExceptionr   p  s    r&   r   c                   .     e Zd Zdd fdZfdZ xZS )8test_count_uses_size_on_exception.<locals>.RaisingObjectc                 0    t         |           || _        y N)super__init__r   )r   r   	__class__s     r$   r  zAtest_count_uses_size_on_exception.<locals>.RaisingObject.__init__t  s    GDHr&   c                 (     | j                         r  )r   )r   otherr   s     r$   __eq__z?test_count_uses_size_on_exception.<locals>.RaisingObject.__eq__x  s    (22r&   )zI will raise inside Cython)returnN)r   r   r   r  r
  __classcell__)r  r   s   @r$   RaisingObjectr  s  s    		3 	3r&   r  rh   r   )r   r   r   r   r   r   r   r7   )		Exceptionr   rI   rD   r   rm   r   r   r   )r  r   r    r   r#   r   s        @r$   !test_count_uses_size_on_exceptionr  o  s     3 3 
58<a-/<T(^T	UBZZ$$&F#1veDJU.KLH&(+ =s   B+c                 
   t        j                  d       t        g dt        g d|       d      }|j	                  d      j                         }t        ddit        g dd	      
      }t        j                  ||       y )Npyarrow)r   r   r   )r   r   r   r*   )r   r   r   r   r   r   r7   )	r   importorskipr   r	   r   rm   r   r   r   )any_string_dtyper    r   r#   s       r$   test_count_arrow_string_arrayr    si    
	"	f_<LMN
B ZZ_""$F#qys)CDH&(+r&   )	itertoolsr   stringr   numpyr|   r   pandasr   r   r   r   r	   r
   r   r   pandas._testing_testingr   r   r   r   r   r   r   r   r  r  r   r&   r$   <module>r     s[     "  	 	 	 j1 j1Z-+@3(	-0*, ,&,r&   