gL ivhddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ddl ZddlmZddlmZGddZy) N)Dtype) is_bool_dtype) NumpyEADtype)na_value_for_dtype)nargsortc HeZdZUdZdZdZejjdddgdZ dZ d Z d Z d Z ejjd d dgdZdZdZdZdZejjdddgdZejjdddgdZejjdddddddej,fddej,fd d!gd"Zd#Zejjd$d%ej2gd&ej4d'(fd)ej2gd*ej4d'(fgd+Zejjd,ddgd-Zejjd,ddgd.Zejjd,ddgd/Zejjd0gd1d2Zejjd3e jBd4gejjdd5e jDgd6Z#d7Z$d8Z%d9Z&d:Z'd;Z(d<Z)e*d=Z+e,e-d><d?Z.d@Z/dAZ0ejjdBddgejjdCdDgdEfdFgdGfdHgdIfgdJZ1dKZ2ejjdLdMdDgdNZ3ejjdCdOdPdPggdPdMdPggdFdFdMggdMdPdFggdQdPdPgggdRZ4ejjdLgdSdTZ5dUZ6dVZ7dWZ8dXZ9dYZ:dZZ;d[Zd`fdPie>dafdMdHgie>dbfdHdcddie?defgdfZ@dgZAdhZBdiZCdjZDejjd3e j2e jBe jgdkZFdlZGy )mBaseMethodsTestsz%Various Series and DataFrame methods.cddlm}|jd|d}|jtj k(sJ|j |j k(sJy)Nr)_default_hash_keyzutf-8F)encodinghash_key categorize)pandas.core.util.hashingr _hash_pandas_objectdtypenpuint64shape)selfdatar ress i/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pandas/tests/extension/base/methods.pytest_hash_pandas_objectz(BaseMethodsTests.test_hash_pandas_objectsR ?&&'8U' yyBII%%%yyDJJ&&&ct|ds!tjdt|t j |j }|jd}|jdusJy)N value_countsz$value_counts is not implemented for dropnaT) hasattrpytestskiptypeinspect signaturer parametersdefault)rrsigkwargs r test_value_counts_default_dropnaz1BaseMethodsTests.test_value_counts_default_dropna sZt^, KK>tDzlK L 1 12x(}}$$$rrTFc8|dd}|r||j}n|}tj|j|j }tj|j|j }t j ||y)N )r)isnapdSeriesr sort_indextmassert_series_equal)rall_datarotherresultexpecteds rtest_value_countsz"BaseMethodsTests.test_value_counts(sCR= hmmo-.EE8$111@KKM99U#000?JJL vx0rc|ddj}tj||j}t j ||j }|jdj}t|tjs$/yyS[!CK/v||,HyyFLL|LH#$s6{?HVaZ djj".. 1djj6I6IRVV6Sy1H TZZB /9 < JJ A  '89H  +ruu 4y1H vx0rctjd|i}|jd}tjddg}t j ||y)NAcolumnsaxisrr9)r, DataFramecountr-r/r0)r data_missingdfr3r4s r test_countzBaseMethodsTests.test_countSsG \\3 - .y)99aV$ vx0rc`tj|}|j}d}||k(sJy)Nr9)r,r-rW)rrXrOr3r4s rtest_series_countz"BaseMethodsTests.test_series_countYs.ii %!!!rctj|jt}t |tjsJyN)r,r-applyidrDrrr3s rtest_apply_simple_seriesz)BaseMethodsTests.test_apply_simple_series`s.4&&r*&")),,,r na_actionNignorecx|jd|}|j}tj||y)Nc|Sr^xs rz+BaseMethodsTests.test_map..fsAr)rc)mapto_numpyr/assert_numpy_array_equal)rrXrcr3r4s rtest_mapzBaseMethodsTests.test_mapds5!!+!C((* ##FH5rctj|j}tjtjgdtj }t j||yNrr9r7)r,r-argsortrrCintpr/r0)rdata_for_sortingr3r4s r test_argsortzBaseMethodsTests.test_argsortjsG+,44699RXXirww?@ vx0rc|j}tjgdtj}t j ||yrp)rsrrCrtr/rm)rdata_missing_for_sortingr3r4s rtest_argsort_missing_arrayz+BaseMethodsTests.test_argsort_missing_arrayps4)11388IRWW5 ##FH5rcNd}tjt|5tj|j }dddtjt jgdt j}tj|y#1swYZxYw)Nz;The behavior of Series.argsort in the presence of NA valuesmatch)r9rr7) r/assert_produces_warning FutureWarningr,r-rsrrCrtr0)rrxmsgr3r4s rtest_argsort_missingz%BaseMethodsTests.test_argsort_missingvsuK  ' ' S A CYY78@@BF C99RXXj@A vx0 C Cs $BB$cf|jj}d}d}|rd}d}|j|k(sJ|jdk(sJ|j gd}|j|k(sJ|jdk(sJ|jdk(sJ|jdk(sJy)Nr9rrr)rrrrr9r9rr)r _is_booleanargmaxargmintake)rrurxrHis_bool exp_argmaxexp_argmax_repeatedrs rtest_argmin_argmaxz#BaseMethodsTests.test_argmin_argmax}s"((44  J"#  &&(J666&&(A--- $$%78{{} 3333{{}!!!(..0A555'..0A555rmethodrrcd}tjt|5t|dd|dddy#1swYyxYw)Nattempt to getr{r)rraises ValueErrorrK)rrrerr_msgs rtest_argmin_argmax_empty_arrayz/BaseMethodsTests.test_argmin_argmax_empty_arraysA# ]]:W 5 ( %GD!Hf % ' ( ( (s <Acd}t|j||g|j}tjt |5t ||dddy#1swYyxYw)Nrr7r{)r!_from_sequencerrrrrK)rrrrHrdata_nas rtest_argmin_argmax_all_naz*BaseMethodsTests.test_argmin_argmax_all_nas]#t*++Xx,@ +S ]]:W 5 ' $GGV $ & ' ' 's A!!A*zop_name, skipna, expected)idxmaxTr)idxminTrr)rTr)rTrrrr)rFr})rFr}czd}d}|jdr |dk(rt}|jdr tj|r t}d|}t j |}t j||5t|||}dddt j|y#1swY xYw)Nz$The behavior of Series.argmax/argminargr}idxzThe behavior of Series.r{skipna) startswithrrisnanr,r-r/r~rKassert_almost_equal) rrxop_namerr4warnrrOr3s rtest_argreduce_seriesz&BaseMethodsTests.test_argreduce_seriess"4   e $R D   e $(); D+G95Cii01  ' 'C 8 :*WS'*&9F : vx0 : :s >B11B:c|}tjtd5|jddddtjtd5|j ddddy#1swY@xYw#1swYyxYw)Nr?r{Fr)rrNotImplementedErrorrr)rrxrs r+test_argmax_argmin_no_skipna_notimplementedzs!rc"|jSr^)rBrhs rrjzBaseMethodsTests.s !((*rc||j|d|dg|j}||}t|dk(sJt|t |sJ|d|dk(sJy)Nrr7r9)rrrFrDr!)rrrrrr3s r test_uniquezBaseMethodsTests.test_uniquesu,,d1gtAw-?tzz,RS  #6{a&$t*---ayJqM)))rctj|d\}}|jj}|r;t j gdtj }|jddg}n:t j gdtj }|jgd}tj||tj||y) NTuse_na_sentinel)rrr}r}r9r9rrr7r)rrr}r}r9r9rrr)rr) r, factorizerrrrCrtrr/rmassert_extension_array_equal)rdata_for_groupingcodesuniquesrexpected_codesexpected_uniquess rtest_factorizezBaseMethodsTests.test_factorizes&7Nw#))55 XX&@PN055q!f= XX&@PN055i@  ##E>: ''1ABrcHtj|d\}}|jd\}}tj||tj||t |t tj |k(sJ|j|jk(sJy)NTr)r,rr/rmrrFrBr)rrcodes_1 uniques_1codes_2 uniques_2s rtest_factorize_equivalencez+BaseMethodsTests.test_factorize_equivalence!s\\*;TR.888N ##GW5 '' 9=9~RYYy%9!::::"3"9"9999rc.tj|dd\}}tjgtj}t |j g|ddj}tj||tj||y)Nrr7) r,rrrCrtr!rrr/rmr)rrrrrrs rtest_factorize_emptyz%BaseMethodsTests.test_factorize_empty*ssd2Ah/w"BGG4:44RtBQx~~4N ##E>: ''1ABrc|jddg}tjd|i}|j}|jd}|j |}||jd<t j||y)Nr9rR)rr)rr,rVcopyrfillnar/r)rrXrrYdf_orig filled_valr3s rtest_fillna_copy_framez'BaseMethodsTests.test_fillna_copy_frame2slA' \\3* %'')WWT] :&& D b'*rc|jddg}tj|d}|j}|d}|j |}||j d<t j||y)Nr9F)rr)rr,r-rrrr/r0)rrXrrOser_origrr3s rtest_fillna_copy_seriesz(BaseMethodsTests.test_fillna_copy_series>seA'ii%(88:V J'# A sH-rcd}tjt|5|j|j dgdddy#1swYyxYw)Nz!Length of 'value' does not match.r{r9)rrrrr)rrXrs rtest_fillna_length_mismatchz,BaseMethodsTests.test_fillna_length_mismatchIsE1 ]]:S 1 8    1 11# 6 7 8 8 8s "A  Abool_combine_le_expected_dtypec |d\}}tj|}tj|}|j|d}tjtjt t |t |Dcgc] \}}||k c}}|j } tj|| |jd} |j| d}tjtjt |Dcgc]}|| k c}|j } tj|| ycc}}wcc}w)Nrrc ||kSr^rgx1x2s rrjz2BaseMethodsTests.test_combine_le..Ws rRxrr7rc ||kSr^rgrs rrjz2BaseMethodsTests.test_combine_le..as br) r,r-combinerCziplistrr/r0r) r data_repeated orig_data1 orig_data2s1s2r3abr4vals rtest_combine_lez BaseMethodsTests.test_combine_leQs"/q!1 J YYz " YYz "B 7899 HH&)$z*:D.}s b2grc ||zSr^rgrs rrjz3BaseMethodsTests.test_combine_add..s rBwrrc ||zSr^rgrs rrjz3BaseMethodsTests.test_combine_add..s Rr)r,r-rerrstaterrr TypeErrorrrrr/r0r) rrrrrrrrr4r3rs rtest_combine_addz!BaseMethodsTests.test_combine_addjsg!.q!1 J YYz " YYz " (+ 99---0j1A4 CS-TU6AqQU B 67 vx0ggajC!7899  % %Z8H&I1q3w&I J  vx0%V    y) 7 256 7  7   'JsYE >wGFyy299aS1W37==gFGaH++GZZ(F,,G!rcj|jd}|d|dk7sJ|d|d<|d|dk7sJy)Nrr9rras rtest_shift_0_periodsz%BaseMethodsTests.test_shift_0_periodssHAAw$q'!!!q'QayF1I%%%rrr9c|dd}t|jrtj}ntj} |||tj|}|j|}tj|||j|}tj||tj|dgdzd}|j|}|dk(rt j"ddddg}n#dddt j"t j"g}tj||d}tj$||y#t $r%t jt|dY.wxYw)Nrz does not support diffg?rr9r)rroperatorxorsub Exceptionrr r!r,r-diffrr/r0rVrrIr) rrropsr3r4rYrs r test_diffzBaseMethodsTests.test_diffs)BQx  $BB ? tTN IIdO99Rdjj&9:; vx0 \\C5195 6! a<Aq!$AAq"&&"&&)A< ?s E*E54E5r}rc|dd}|j|}|j|d}tj||y)NrrTr rrr/r)rrrrrr3r4s rtest_shift_non_empty_arrayz+BaseMethodsTests.test_shift_non_empty_arrays? bqg&;;w4;8 ''9r)r$r}rr9rc`|dd}|j|}|}tj||y)Nr)rr/r)rrremptyr3r4s rtest_shift_empty_arrayz'BaseMethodsTests.test_shift_empty_arrays2RaW% ''9rcf|jd}||usJ|ddjd}||usJy)Nrrrrras rtest_shift_zero_copiesz'BaseMethodsTests.test_shift_zero_copiess?AT!!!bq"T!!!rc|dd}|d}|jd|}|jgd}tj|||jd|}|jgd}tj||y)Nrrr9) fill_value)rrr9rrr )rrrrrr&)rrrr.r3r4s rtest_shift_fill_valuez&BaseMethodsTests.test_shift_fill_valuesv2Ah!W 1499\* ''92*599\* ''9rcztjtd5t|dddy#1swYyxYw)Nzunhashable typer{)rrrhashrrs rtest_not_hashablez"BaseMethodsTests.test_not_hashables- ]]9,= >  J   s 1:ctj|}|r|j}tjj |}tjj |}t j ||yr^)r,r-rutilhash_pandas_objectr/ assert_equal)rras_framerrs rtest_hash_pandas_object_worksz.BaseMethodsTests.test_hash_pandas_object_workssSyy ==?D GG & &t , GG & &t , 1rc|jjr|j||S|\}}}|jgd}|rt j |}|j |dk(sJ|j |ddk(sJ|j |dk(sJ|j |ddk(sJ|j |dk(sJ|j |ddk(sJ|j |jddg}tjddgtj}tj||tjgd } |j || dk(sJy) Nrqrrightsider9rrrr7rsorter) rr_test_searchsorted_bool_dtypesrr,r- searchsortedrrCrtr/rm) rru as_seriesrcrrr3r4r?s rtest_searchsortedz"BaseMethodsTests.test_searchsortedsh  ! ! - -667GS S"1a##I. ))C.C"a'''0A555"a'''0A555"a'''0A555!!#((Aq6"2388QF"''2 ##FH5)$,,Qv,>!CCCrc|j}tjddg|}|\}}t|j ||g}|rtj |}|j |dk(sJ|j |ddk(sJ|j |dk(sJ|j |ddk(sJ|j |jddg}tjddgtj}tj||tjddg} |j || dk(sJy) NTFr7rr;r<r9rrr>) rr,rCr!rr-rArrrtr/rm) rrurBrrrrr3r4r?s rr@z/BaseMethodsTests._test_searchsorted_bool_dtypess<!&&88T5M?1#$33QF; ))C.C"a'''0A555"a'''0A555!!#((Aq6"2388QF"''2 ##FH51a&!,,Qv,>!CCCrc|d|dk7sJt|}|dd\}}tj|j||||g|j}|j }t jgd} |r$|jd}| jdd} |j| } tj|j||||g|j} |r| jd} tj| | |j| d tj|| |j }|r|jd}t jgd } |j||||g|j} |r.tjd| i} tjd| i} |j| | } tj|j||||g|j} |r| jd} tj| | |j| | d tj|| y) Nrr9rrr7rrr r}T)inplace)TFTT)r!r,r-rrrrrCrreshapewherer/r7maskrV) rrrHr8clsrrorigrOcondr3r4r2s rtest_where_seriesz"BaseMethodsTests.test_where_series3sAw$q'!!!4jBQx1yy++Q1aL +KLiikxx23 ,,C,(C<<A&D499   1h9  L  ((c(2H ) $% X&iik ,,C,(Cxx12""Aq!QC C>C CCct|}tjt5|j |dz|ddddtjt5|j | dz |ddddtjt 5|j d|ddddy#1swY|xYw#1swYMxYw#1swYyxYw)Nr9rg?)rFrr IndexErrorrdr)rrubs rtest_insert_invalid_locz(BaseMethodsTests.test_insert_invalid_locs Y ]]: & ) KKQQ ( )]]: & * KKaa ) *]]9 % & KKT!W % & &  ) ) * * & &s#B9CC9CCCct|j|dgt|z|j}t|j|gt|z|j}t j ||d}t j ||d}t j ||d}|j |dusJ|j |jdusJ|j |dusJ|j |dusJ|ddj |dddusJ|ddj |dddusJ|j ddusJ|dgj |ddusJy)Nrr7F) transposeTrrr)r!rrFrr/ box_expectedequalsr)rrrHrBrdata2rs r test_equalszBaseMethodsTests.test_equalssxT ))47)c$i*?tzz)Rt*++XJT,B$**+UtSE:se<//'3%@ {{4 D((({{499;'4///{{5!U***{{7#u,,,BQxtBQx(E111BQxtBQx(D000{{4 E)))QCyQ(E111rcvtj|jtj|sJyr^)r,r-rsr2s r&test_equals_same_data_different_objectz7BaseMethodsTests.test_equals_same_data_different_objects&yy%%biio666r)H__name__ __module__ __qualname____doc__rr(rmark parametrizer5rPrZr\rbrnrvryrrrrrrIrrrCrrrrrrr,r-rBrrrrrrrrrr__annotations__rrrrrr#r'r*r,r/r3r9rDr@rNrWrrr^rbrgrkrorVrurwrgrrr r s/ '% [[Xe}5 16 11<1 "- [[[4*:;6<6 1 6 162 [[X(';<(=(  [[X(';<'=' [[#     ubff % ubff % ! !  1 1 & [[ XRXXixrxx/?@ A hbhhy0@A B 66  [[[4-8 19 1 [[[4-8 19 1 [[[4-8090 [[V%=> 6? 6 [[URYY $<= [[X(* C:C + .8 )5V(<<121@1 [[WtUm4 [[  1o"6 * [[%  Z 0 Z ,VRW -  7 3  //::" - & [[URXXryy",,$GH2I287rr )r"rnumpyrrpandas._typingrpandas.core.dtypes.commonrpandas.core.dtypes.dtypesrpandas.core.dtypes.missingrpandasr,pandas._testing_testingr/pandas.core.sortingrr rgrrrs2 329(~ 7~ 7r