gL i25ddlmZddlmZddlZddlZddlmZm Z m Z m Z m Z m Z mZmZddlmZGddZdZdZd Zd Zd Zd Zd ZdZy))product)ascii_lowercaseN) DataFrameIndex MultiIndexPeriodSeries Timedelta Timestamp date_rangeceZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZej*j-deddDcgc]}t1d|ddc}}}eddDcgc]}t1d|ddc}}}eddDcgc]}t1d|dddc}}}eddDcgc]}t3|dc}}}eddDcgc]}t5dd|c}}}gd Zd!Zd"Zd#Zy$cc}}}wcc}}}wcc}}}wcc}}}wcc}}}w)% TestCountingctdgdgdgdgdggdg}|jd}|j}tgd}t j ||j t j ||j y)NabAcolumnsrrrgroupbyrr tmassert_series_equalcumcountselfdfgsgexpecteds h/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pandas/tests/groupby/test_counting.py test_cumcountzTestCounting.test_cumcountsq usecUSE:SE J JJsO SS/* x6 x7c tjd}ttjd}td}t j ||j t j ||j yNr)leveldtypeint64)rrr objectrrrrgesees r$test_cumcount_emptyz TestCounting.test_cumcount_emptysg [ q ) & ! ) ) ) 2  ! q"++-0 q"++-0r&c.tdgdgdgdgdggdgdgdz}|jd}|j}tgddgdz}t j ||j t j ||j y) Nrrrrrindexrr6rrs r$test_cumcount_dupe_indexz%TestCounting.test_cumcount_dupe_index)s USEC53%# /#qcAg  JJsO SS/!q9 x6 x7r&cftjddgddgddgddgddgg}tdgdgdgdgdggdg|}|jd}|j}t gd| }t j||jt j||jy) Nrrrrrrr5rr7) r from_tuplesrrrr rrrrmir r!r"r#s r$test_cumcount_mizTestCounting.test_cumcount_mi5s  # #aVaVaVaVaV$L M usecUSE:SEQS T JJsO SS/4 x6 x7r&c2tdgdgdgdgdggdgdgdz}|jgd}|j}tgddgdz }t j ||j t j ||j y) Nrrrrr4r5rrrrrrr7rrs r$test_cumcount_groupby_not_colz*TestCounting.test_cumcount_groupby_not_col@s USEC53%# /#qcAg  JJ ' SS/!q9 x6 x7r&ctdtdi}|jd}|j}t gd}t j ||jt j ||jy)Nraaabar?rlistrrr rrngrouprs r$ test_ngroupzTestCounting.test_ngroupLsa T']+ , JJsO SS/* x4 x5r&c&tdtdi}|jd}|j}t t dd}t j||jt j||jy)Nrabcder4r,r*) rrDrrr rangerrrErs r$test_ngroup_distinctz!TestCounting.test_ngroup_distinctVsg T']+ , JJsO SS%('2 x4 x5r&ctddgdzi}|jd}|j}tdgdz}t j ||j t j ||j y)Nrrr4)rrrr rrrErs r$test_ngroup_one_groupz"TestCounting.test_ngroup_one_group`sg aS1W~ & JJsO SS1#'? x4 x5r&c tjd}ttjd}td}t j ||j t j ||j yr()rrr r-rrrEr.s r$test_ngroup_emptyzTestCounting.test_ngroup_emptyjsg [ q ) & ! ) ) ) 2  ! q"))+. q"))+.r&ctdtdi}ttd}tj|j |j |j |j y)NrrB)rrDr rrrrE)rr ss r$ test_ngroup_series_matches_framez-TestCounting.test_ngroup_series_matches_frametsU T']+ , 4= ! rzz!}335qyy|7J7J7LMr&c,tdtdidgdz}|jd}|j}t gddgdz}t j ||jt j ||jyNrrBrr4r7r?rCrs r$test_ngroup_dupe_indexz#TestCounting.test_ngroup_dupe_indexzsq T']+A37 ; JJsO SS/!q9 x4 x5r&cdtjddgddgddgddgddgg}tdtdi|}|j d}|j }t gd|}tj||jtj||jy)NrrrrrBr7r?) rr:rrDrrr rrrEr;s r$test_ngroup_mizTestCounting.test_ngroup_mis  # #aVaVaVaVaV$L M T']+2 6 JJsO SS/4 x4 x5r&c0tdtdidgdz}|jgd}|j}t gddgdz}t j ||jt j ||jyrSrCrs r$test_ngroup_groupby_not_colz(TestCounting.test_ngroup_groupby_not_colsr T']+A37 ; JJ ' SS/!q9 x4 x5r&c`tgddg}|jdg}tgd}tgd}tj||j dz |z tj||j dtj||j d y) N)rrrrrrr)rrrrr)rrrrrrT) ascendingF)rrr rrngroupsrE)rr r!rZ descendings r$test_ngroup_descendingz#TestCounting.test_ngroup_descendings 03% @ JJu ?+ O,  zAIIMY+FG y!((T(*BC z188e8+DEr&c2tddgddgddgddgddggddg}|jddg}|j}|j}t gd}t gd }t j ||t j ||y) NrxyrrXrrr?)rrrErr rr)rr r!g_ngroup g_cumcountexpected_ngroupexpected_cumcounts r$test_ngroup_matches_cumcountz)TestCounting.test_ngroup_matches_cumcounts 3Z#sc3Z#sc3Z H#J  JJSz "88:ZZ\  1"?3 x9 z+<=r&cttddD]}td|i}|jdg}t t |}|Dcgc]}|j |}}t|Dcgc]\}}|d|j|}}}tj|jt|tj|jt|ycc}wcc}}w)Nr)repeatr)rrIrrsortedsetr6 enumeratecountrrrEr r) rpr r!ordervalngroupdi cumcounteds r$test_ngroup_cumcount_pairz&TestCounting.test_ngroup_cumcount_pairsq!, EAC8$B C5!A3q6NE345Cu{{3'5G59B1Fvq#!BQ%++c*FJF  " "188:vg ?  " "1::< 1C D E 6Fs C79C<cjtdtjjdj t ddi}|j d|}d|d<d|d<t|D]Q\}\}}||j|jdf<t|jD]\}}||j|df<Stjt|dj|jtjt|dj|jy) Nrrabcdefd)sortgroup_id group_index)rnprandom default_rngchoicerDrrllocr6rrr valuesrEr) rrxr r!rr_groupjinds r$"test_ngroup_respects_groupby_orderz/TestCounting.test_ngroup_respects_groupby_orders RYY2215<&>?Nr& datetimelikerrhz2016-05-02dz 20:09:25+00:00z 20:09:25UTC)tzh)unit2Wi)freqyearmonthctgd|d}|jdj}tdddgiddg }d|j_t j ||y) N)rrr)r_r`r_r`rrrrr7)rrrmr6namerassert_frame_equal)rrr resr#s r$test_count_with_datetimelikez)TestCounting.test_count_with_datetimelikes]_<@ Ajjo##%cAq6]3*=! h,r&cRttjtjgddgddgd}|jddgjj }t gddgggggddg}tg|tjd }tj||d y) NrrrrrBCrr)levelscodesnamesr)r6r+rF)check_index_type) rr|nanrrrmrr r,rr)rr resultr<r#s r$(test_count_with_only_nans_in_first_groupz5TestCounting.test_count_with_only_nans_in_first_groups bffbff-S#JaVL MS#J'))//1 S#J/BxSz R"BbhhSA vx%Hr&ctgdddtjddgd}|jdgj }tt gdd d gd i }t j||y) N)rrrrrr4rhrr)rrr)gg@g@g@rr)rrrr)r6data)rr|rrrmrrr)rr rr#s r$4test_count_groupby_column_with_nan_in_groupby_columnzATestCounting.test_count_groupby_column_with_nan_in_groupby_columnsg _Aq"&&!Q3GH Ijj#%%',37sL>Q  h,r&ctddd}ttjd|tjdg}|j d}|j }ttjdtjd|g}|j d}|j }t j||y)Nz1/1/20125min )startrperiodsr7c|ddzdk(S)Nrrrr_s r$z@TestCounting.test_groupby_count_dateparseerror..!qA r&c|ddzdk(S)Nrrrrs r$rz@TestCounting.test_groupby_count_dateparseerror..rr&)r r r|arangerrmrr)rdrsergroupedrr#s r$!test_groupby_count_dateparseerrorz.TestCounting.test_groupby_count_dateparseerrors jvr BRYYr]2ryy}*=>++56RYYr]299R="*=>++56==? vx0r&N)__name__ __module__ __qualname__r%r2r8r=r@rFrJrLrNrQrTrVrXr]rfrtrpytestmark parametrizerIr r rrrrr).0rrr r_r rs000000r$rrs_81 8 8 8666/N 666 F > E O [[CHA; O OaY!C8 9 O=B1a[ I IY!C 2 3 IGLQPQ{ S S!Y!C 2u = S-21a[ 9 9Yqs # 9:Erc.ttdtjdj dd}t ddgt ddgd d }|jdjj}tj||y) Nababrhztimedelta64[ns])r!deltarrrr!rrr6r) rrDr|rastyper rrrrmrr)r r#rs r$#test_groupby_timedelta_cython_countrsw 8nryy|':':;L'MN Bq!fE3*3$?gNH ZZ_ " " ( ( *F8V,r&cd}td|dzd}ttjj dj t t|tjj djdd|tjj dj|jd tjj djd d|tjj dj ||tjj dj|jd tjj dj|jd tjj dj ||tjj dj |d z tjj dj t t|d }|jjgd D]Q}tj|jtjj dj ||dz|f<S|djd|d<ddddgfD]}|j!|j#}d}t%j&t(|5|j!|j+tj"j|d }dddt%j,|y#1swY"xYw)Niz 2015-08-30rmin)rrrrr4rir) 1st2nd3rd4th5th6th7th8th9th)rrrrcategoryrrz7DataFrameGroupBy.apply operated on the grouping columns)match)axis)r rr|r}r~rrDrintegersstandard_normalroundrdroprrrrrmrassert_produces_warning FutureWarningapplyr)nrr colkeyleftmsgrights r$ test_countr sA L!r' >B 99((+2243H!L99((+44Q1=99((+;;A>DDQG99((+44S"a@99((+222q999((+;;A>DDQG99((+;;A>DDQG99((+222q9ii##A&--b!4599((+2243H!L  Bzz45JCE66ryy$$Q'..q!r':C?@J5   ,BuIuuen-+zz#$$&G  ' ' S A MJJsO)))//:??!?LE M dE* + M Ms AM##M, cHtgddtjdgdtjtjgggd}|jdj }|jdd j }tdd gd d ggd d gddg}d|j _tj||jtj|||jdd j }tj||d y)N)rrfoorbarrrrrF)as_indexrrrrr5) rr|rrrmr6rrr reset_indexr)r count_as count_not_asr#count_Bs r$test_count_non_nullsr*s  BFFE*Q,?@ B zz#$$&H::cE:288:L1a&1a&)C:aVLHHNN,(<(<(>?(H-jjoc"((*G7HSM2r&c:tdgdzdgdzzdgdzdgdzzd}|jdjj}t ddgt ddgdd}t j||tdtjtjgdgdzzdgdzdgdzzd}|jdjj}t d dgt ddgdd}t j||y) Nrrrr)rcrrrr) rrrrmr rrrr|rr rr#s r$test_count_objectr>s #cUQY.aS1WsQw5FG HB ZZ_   $ $ &Fq!fE1a&s$;#FH68, #rvvrvv.#:!qA3QR7ARS TB ZZ_   $ $ &Fq!fE1a&s$;#FH68,r&cltjtjjdj dddtjjdj dddfj d}t |gd}tj||dk(<|jdd gj}d D]g}|d j ||d <|d j ||d <|jdd gj}tj||iy) Nrrr4)rwrfloat64)rrrdrrr)float32r-rr) r|hstackr}r~rrrrrrmrr)valsr r#trs r$test_count_cross_typerJs  99 II ! !! $ - -aH = II ! !! $ - -aH =    fY   4!5 6B&&BrQwKzz3*%++-H "0S'..#3S'..#3S#J'--/ fh/ 0r&cttjgdtjtjgdtjtjgdtj t dd}|jdj}tddgddgddgdtt d d  }tj||y) N)rrrrw)rrr)rhr4rr)rrrgrprr)rrrabrr7) rr|arrayint8uint32int16rDrrmrrrrs r$test_lower_int_prec_countr_s ."''2, 2,1>   BZZ  $ $ &F!fAq6A/uT$Ze7TH&(+r&c`GddtGfdd}ttdDcgc] }| c}tdd}|j dj }td d d git td d  }tj||ycc}w)Nc eZdZy)Atest_count_uses_size_on_exception..RaisingObjectExceptionN)rrrrr&r$RaisingObjectExceptionrps r&rc.eZdZddfd ZfdZxZS)8test_count_uses_size_on_exception..RaisingObjectc0t|||_yN)super__init__r)rr __class__s r$rzAtest_count_uses_size_on_exception..RaisingObject.__init__ts G  DHr&c(|jr)r)rotherrs r$__eq__z?test_count_uses_size_on_exception..RaisingObject.__eq__xs(2 2r&)zI will raise inside Cython)returnN)rrrrr  __classcell__)rrs@r$ RaisingObjectrss  3 3r&r rhr)rrrrrrrr7) ExceptionrrIrDrrmrrr)r rr rr#rs @r$!test_count_uses_size_on_exceptionros  33 58rs["    j1j1Z-+@3( -0* , ,&,r&