gL i\`ddlZddlZddlZddlZddlmZmZmZm Z ddl m Z ddl mZejddgddgeddgdej gdeeed gde gd e gd e gd gg d Zejddg dZejdZejdZejdZejdZd)dZej6j9dgddZej6j9dddgdZej6j9dddgej6j9dej>ej@gdZ!ej6j9dgddZ"ej6j9dddgdZ#ej6j9dddgej6j9dej>ej@gd Z$ej6j9d!gd"d#Z%ej6j9dgdd$Z&ej6j9dddgd%Z'ej6j9dddgej6j9dej>ej@gd&Z(ej6j9dgdd'Z)d(Z*y)*N) Categorical DataFrameGrouperSeries)get_groupby_method_argsab)keyc |dzS)Nxs f/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pandas/tests/groupby/test_raises.pyrs !a%) rrrr r r r rrrrrr r r r rrrrrrrr)paramsc|jSNparamrequests rbyr s ==rTFc|jSrrrs rgroupby_seriesr"'s ==rcRtgdgdtdtdd}|S)Nrrr xyzwtyuiorr cd)rrangelistdfs rdf_with_string_colr,,s- ,,qk"   B Ircrtgdgdtdtjddddddd d }|S) Nrrrir i`=r%)rr(datetimer*s rdf_with_datetime_colr29s? ,,q""4Ar2r6B   B Irchtgdgdtdtjdd}|S)Nrrrr)daysr%)rr(r1 timedeltar*s rdf_with_timedelta_colr6Fs3 ,,q##+   B Irc `tgdgdtdtgdgddd}|S)Nrrr rrrrr r r r r&r%T categoriesordered)rr(rr*s rdf_with_cat_colr<Ss6 ,,q=/  B Irc|dk(rdnt}tj||5|B|dk(rt|||n|dk(r|j|g|nu|j |g|nat j||5|dk(rt|||n,|dk(r|j|g|n|j |g|ddddddy#1swYxYw#1swYyxYw)Nmatchmethodagg) FutureWarningtmassert_produces_warninggetattrrB transformpytestraises)klassmsghowgb groupby_funcargswarn_msg warn_klasss r_call_and_checkrRds!R]J # #Jh ?6 =h)L)40|+d+ \1D1uC0 6(?-GB -t4E\BFF</$/ BLL55  666 6 666s%AC ACC C C  C)rL)rArBrGc |}t||}|j|}|r|d}|dk(rt|drJyidddddddtdfd dd dd ttfd fd ttfdfdttfdfdttfdfdtdfddddddddddddidddtt j dfdtt j dfd dd!dd"dd#tdfd$tt j d%fd&td'fd(dd)td*fd+dd,dd-td*fd.td*fd/dd0tt j d1f|\} } |r{|d2vrd3|d4} |d5vrmt} nf|d#k(r|djjd6k(rd7} nB|dk(r|djjd6k(rd8} n|d9vr| jd:d;} n|dk(rd<} |dk(r |rd=nd>} | d?} nd@} t| | ||||| y)ANr r'corrwithallNr>anybfillzCould not convertcountcumcountcummaxzH(function|cummax) is not (implemented|supported) for (this|object) dtypecumminzH(function|cummin) is not (implemented|supported) for (this|object) dtypecumprodzI(function|cumprod) is not (implemented|supported) for (this|object) dtypecumsumzH(function|cumsum) is not (implemented|supported) for (this|object) dtypediffunsupported operand typeffillfillnafirstidxmaxidxminlastmaxmeanz-agg function failed [how->mean,dtype->object]medianz/agg function failed [how->median,dtype->object]minngroupnunique pct_changeprodz-agg function failed [how->prod,dtype->object]quantilez4dtype 'object' does not support operation 'quantile'ranksemz!could not convert string to floatshiftsizeskewstdsumvarz%agg function failed [how->var,dtype->) rorirjr_r^rvrrrxrurpz(dtype 'str' does not support operation '')rrrvrupyarrowzBoperation 'truediv' not supported for dtype 'str' with dtype 'str'z>operation 'sub' not supported for dtype 'str' with dtype 'str')r]r\objectstrz1Cannot perform reduction 'mean' with string dtyperrGroupBy.fillna is deprecatedr>) rgroupbyhasattr TypeErrorNotImplementedErrorreescape ValueErrordtypestoragereplacerR) rLr r"rNr,using_infer_stringr+rOrMrJrKkindrPs rtest_groupby_raises_stringrxs B "< 4D r B W : %r:. .. ; z; z; ; Y 34 ;  ; J ;  ) , V ;  ) , V ;  ) , W ;&  ) , V ';. 67/;0 1;2 *3;4 5;6 *7;8 *9;:  ;;< z=;>   IIE F ?;F   IIG H G;N zO;P *Q;R :S;T y"<=U;V   IIE F W;^ Y VW_;`  a;b  ?@c;d e;f  g;h @Ai;j  ?@k;l zm;n   II= > o;vw;JE3z   =\N!LC55! \ )bgmm.C.Cy.PWC V #3 (=(=(JSC 1 1++h.C Z 'ECx)x{V78E3RtXFrrBrGc|}|j|}|r|d}d}tjtd5t |||dddy#1swYyxYw)NrTr'ctdNTest error messagerrs rfuncz,test_groupby_raises_string_udf..func,--rrr?r~rHrIrrF)rLr r"r,r+rMrs rtest_groupby_raises_string_udfrs_ B r B W. y(< =C AAgroupby_func_npc |}|j|}|r|d}tjdtjtdfi|\}} |r|tjurt}d} |rd} nd} t || |||d| y) NrTr'rWzEagg function failed|Cannot perform reduction 'mean' with string dtypez-dtype 'str' does not support operation 'mean'using SeriesGroupBy.[sum|mean]!using DataFrameGroupBy.[sum|mean]r rP)r~nprwrirrR) rLr r"rr,rr+rMrJrKrPs rtest_groupby_raises_string_nprs B r B W     S   JE3 bgg %E=36E3R"xPrc <|}t||}|j|}|r|d}|dk(rt|drJyidddddddtdfd dd dd dd dd tdfdtdfddddddddddddddidddddddddddddtdfd td!fd"dd#dd$dd%dd&dd'td(j d)d*gfd+dd,td-fd.td/f|\}} |d0vrd1|d2} n|dk(r |rd3nd4} | d5} nd6} t || ||||| 7y)8NrTr'rUrVrWrXrYz+cannot perform __mul__ with this index typerZr[r\r]r^z3datetime64 type does not support cumprod operationsr_z2datetime64 type does not support cumsum operationsr`rbrcrdrerfrgrhrirjrkrlrmrnz/cannot perform __truediv__ with this index typeroz%datetime64 type does not support prodrprqrrrsrtru|z1dtype datetime64\[ns\] does not support reductionz0datetime64 type does not support skew operationsrvrw/datetime64 type does not support sum operationsrxz/datetime64 type does not support var operations)rXrVryz&' with datetime64 dtypes is deprecatedrrr}r>r)rr~rrjoinrR) rLr r"rNr2r+rOrMrJrKrPrs rtest_groupby_raises_datetimers B "< 4D r B W : %r:. .. + z+ z+ + Y MN +  + J + *+ *+ ITU+ 9RS+  + + *+ + *+ *!+"  #+$ z%+&  '+( *)+* z++, *-+. :/+0 y"ST1+2 CD3+4 J5+6  7+8 z9+: ;+<  =+>   HHHF  ?+P zQ+R  LMS+T  LMU+VW+JE3Z~%|n$JK  !)x{V78E3RthOrc|}|j|}|r|d}d}tjtd5t |||dddy#1swYyxYw)NrTr'ctdrrrs rrz.test_groupby_raises_datetime_udf..funcmrrrr?r)rLr r"r2r+rMrs r test_groupby_raises_datetime_udfres_ B r B W. y(< =Crc |}|j|}|r|d}tjtdftjdi|\}}|rd} nd} t |||||d| y) NrTr'rrWrrr rr~rrwrrirR) rLr r"rr2r+rMrJrKrPs rtest_groupby_raises_datetime_nprtsw B r B W MN JE3 36E3R"xPrr)ror^rurxcT|}|jd}ttdd||gy)NrrTz/timedelta64 type does not support .* operationsrA)r~rRr)rr6r+rMs rtest_groupby_raises_timedeltars1 B s B9   rc r|}t||}|j|}|r|d}|dk(rt|drJyidddddddtdfd dd dd ttfd fd ttfdfdttfdfdttfdfdtdfddd|stdfndddddddddidddtdj dd gfd!tdj d"d#gfd$dd%dd&dd'td(fd)td*fd+td,fd-dd.tdj d/d0gfd1dd2dd3tdj d4d5gfd6tdj d7d8gfd9td:fd;tdj dnd?} | d@} ndA} t | | ||||| y)BNrTr'rUrVrWrXrY=unsupported operand type\(s\) for \*: 'Categorical' and 'int'rZr[r\zz(category type does not support cummax operations|category dtype not supported|cummax is not supported for category dtype)r]zz(category type does not support cummin operations|category dtype not supported|cummin is not supported for category dtype)r^z|(category type does not support cumprod operations|category dtype not supported|cumprod is not supported for category dtype)r_zz(category type does not support cumsum operations|category dtype not supported|cumsum is not supported for category dtype)r`zDunsupported operand type\(s\) for -: 'Categorical' and 'Categorical'rbrcSCannot setitem on a Categorical with a new category \(0\), set the categories firstrdrerfrgrhrirz2'Categorical' .* does not support reduction 'mean'2category dtype does not support aggregation 'mean'rjz4'Categorical' .* does not support reduction 'median'4category dtype does not support aggregation 'median'rkrlrmrnzDunsupported operand type\(s\) for /: 'Categorical' and 'Categorical'ro.category type does not support prod operationsrpNo matching signature foundrqrr1'Categorical' .* does not support reduction 'sem'1category dtype does not support aggregation 'sem'rsrtru0dtype category does not support reduction 'skew'.category type does not support skew operationsrv1'Categorical' .* does not support reduction 'std'1category dtype does not support aggregation 'std'rw-category type does not support sum operationsrx1'Categorical' .* does not support reduction 'var'1category dtype does not support aggregation 'var'rrr}r>)rr~rrrrrR) rLr r"rNusing_copy_on_writer<r+rOrMrJrKrrPs rtest_groupby_raises_categoryrs B "< 4D r B W : %r:. .. v zv zv v   L v v Jv  ) , : v  ) , : !v,  ) , ; -v8  ) , : 9vD   S EvL MvN  #  ' [v\ ]v^ *_v` *avb  cvd zevf   HHHH  gvx   HHJJ  yvJ zKvL *MvN :OvP   S QvX LMYvZ Y =>[v\  ]v^   HHGG  _vp qvr  svt   HHFD  uvF   HHGG  GvX  JKYvZ   HHGG  [vlmvJE3px)x{V78E3RtXFrc|}|j|}|r|d}d}tjtd5t |||dddy#1swYyxYw)NrTr'ctdrrrs rrz.test_groupby_raises_category_udf..func4rrrr?r)rLr r"r<r+rMrs r test_groupby_raises_category_udfr+sa B r B W. y(< =Crc |}|j|}|r|d}tjtdftjtdfi|\}}|rd} nd} t |||||d| y) NrTr'rrrrr rr) rLr r"rr<r+rMrJrKrPs rtest_groupby_raises_category_npr;s B r B W KL   @   JE336E3R"xPrc \|}tgdgdd|d<t||}|j||} |r| d} |dk(rt| drJy| xr*t d | j j D} |s5|d k7r0t|tr t|d tr |dd gk(r| rJd} |d k(rd } idddddddtdfdddddttfdfdttfdfdttfdfdttfdfdtdfddd |std!fndd"dd#| rtd$fndd%| rtd$fndd&did'dd(td)fd*td+fd,dd-dd.dd/tdfd0td1fd2td3fd4dd5td6jd7d8gfd9dd:dd;td6jdtd6jd?d@gfdAtdBfdCtd6jdDdEgf|\} } |d k(r |rdFndG} | dH}ndI}t| | || |||y)JNr8r%Tr9r)r observedr'rUc34K|]}|jywr)empty).0groups r z;test_groupby_raises_category_on_category..qs'T 'TsrGrr FrVrWrXrYrrZr[r\zz(cummax is not supported for category dtype|category dtype not supported|category type does not support cummax operations)r]zz(cummin is not supported for category dtype|category dtype not supported|category type does not support cummin operations)r^z|(cumprod is not supported for category dtype|category dtype not supported|category type does not support cumprod operations)r_zz(cumsum is not supported for category dtype|category dtype not supported|category type does not support cumsum operations)r`rarbrcrrdrez(empty group due to unobserved categoriesrfrgrhrirrjrrkrlrmrnrorrprrqrrrrrrsrtrurrrvrrrwrrxrrrrr}r>)rrr~rrXgroupsvalues isinstancer)r|rrrrrR)rLr r"rNrrr<r+rOrM empty_groupsrJrKrrPs r(test_groupby_raises_category_on_categoryrVs. B5'BsG #< 4D rH -B W : %r:. .. <TC'TAQAQAS'T$TL  ;  r4 r!uc " 3*   k d zd zd d   L d d Jd  ) , @ d  ) , @ !d,  ) , A -d8  ) , @ 9dD 67EdF GdH  #  ' UdV WdX  IJ ]d^  IJ cdd  edf zgdh PQidj 9TUkdl zmdn *odp :qdr y"<=sdt LMudv Y =>wdx  ydz   HHGG  {dL MdN  OdP   HHDF  Qdb   HHGG  cdt  JKudv   HHGG  wdHIdJE3Lx)x{V78E3RtXFrctdgdgdgd}d}tjt|5|j dd}dddt j td 5d dddy#1swY3xYw#1swYyxYw) Nrr r)rr r&z+DataFrame.groupby with axis=1 is deprecatedr?r)axisz'Cannot subset columns when using axis=1r )rrDrErCr~rHrIr)r+rKrMs r%test_subsetting_columns_axis_1_raisesrs !A3aS1 2B 7C # #M =% ZZ!Z $% z)R S 3%%sA6'B6A?B )r>)+r1rnumpyrrHpandasrrrrpandas._testing_testingrDpandas.tests.groupbyrfixturearraydictzipr(r r"r,r2r6r<rRmark parametrizerrrwrirrrrrrrrrrr rrrs    8  c C#,- Sq6 78*+ + ,f5P.QR   e}%&         6( >?oG@oGd 45 6  45*RVVRWW,=> Q?6 QF >?BP@BPJ 45 6  45*RVVRWW,=>Q?6Q,!CD E  >?LG@LG^ 45 6  45*RVVRWW,=>Q?6Q2 >?TG@TGnr