o 6a o@stdZddlZddlmZmZmZmZddlm Z m Z m Z m Z m Z mZmZmZddlZGdddZGdddZdS) z-Test functions for 1D array set operations. N)assert_array_equal assert_equal assert_raisesassert_raises_regex)ediff1d intersect1dsetxor1dunion1d setdiff1duniquein1disinc @seZdZddZddZddZddZd d Zej d e j gd e j d de jdfe j gd e j d e j gde jd ddfe j gde jd e je jdfgddZej de j gd e jd dde j gde jd fe j gd e jd e j dge jd de j gde jd fe j gd e jd dde j gde jd fe j gd e j d dde j gde j d fgd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Z d8d9Z!d:d;Z"dd?Z$dS)@ TestSetOpscCstgd}tgd}tgd}t||dd}t||tgd}tgd}tgd}t||}t||tgtggdS)Nrrr)rrrT assume_unique)rrrrr)rrrrrrr)nparrayrr)selfabeccedr!B/usr/lib/python3/dist-packages/numpy/lib/tests/test_arraysetops.pytest_intersect1ds   zTestSetOps.test_intersect1dcCsLGddd}|}t||}t||tgdgd}t|gddS)Nc@seZdZddZdS)z4TestSetOps.test_intersect1d_array_like..TestcSs tdS)Nr)rarangerr!r!r" __array__%s z>TestSetOps.test_intersect1d_array_like..Test.__array__N)__name__ __module__ __qualname__r&r!r!r!r"Test$s r*rrr)rr)rr*rresr!r!r"test_intersect1d_array_like"s   z&TestSetOps.test_intersect1d_array_likec Cstgd}tgd}t||ddd\}}}tgd}t||t|||t|||tgd}tgd}t||dd\}}}tgd}t||t|||t|||tgd gd g}tgd gd g}t||ddd\}}}t||j}t||j} tgd } t| ||t| || tgdgdg}tgdgdg}t||dd\}}}t||j}t||j} tgd} t| ||t| || dS)Nrrrr)rrrT)rreturn_indices)rrr)rrrrrrr)rrrrrrr)r0)rrrr/)rr1r)rrrr/) r1 )rr/rr1)rrrr/r/)rrr1rr)rrrr)r3r4r1r)rrr1)rrrr unravel_indexshape) rrrri1i2eeefui1ui2ear!r!r"test_intersect1d_indices.s<  z#TestSetOps.test_intersect1d_indicescCstgd}tgd}tgd}t||}t||tgd}tgd}tgd}t||}t||tgd}tgd}tgd}t||}t||tgtggdS) Nrr)rrrr+)r/rr)rrrrrr/)rr1rr)r/rrr1)rrrrrrrrrr!r!r" test_setxor1dUs       zTestSetOps.test_setxor1dcCs,tg}tdg}tddg}tgt|tdgt|ddtdgt|ddtddgt|dddtgt|tdgt|tgdt|d d dtgd t|d d gd dgdtdd gt|d dtgdt|d dgdtd dgt|d dtgdt|d d gddS)Nrrr)to_begin)to_end)rBrC)rrr5rr5)rr/rrr1rr/r1)rrr1)rr/r)rrrr)r zero_elemone_elemtwo_elemr!r!r" test_ediff1dms"  zTestSetOps.test_ediff1dzary, prepend, append, expectedr+dtypeNrC)rrrrB)?g@g"@cCsHd|}tt|t|||dWddS1swYdS)Nz dtype of `{}` must be compatiblearyrCrB)formatr TypeErrorr)rrMprependappendexpectedmsgr!r!r"!test_ediff1d_forbidden_type_castss  "z,TestSetOps.test_ediff1d_forbidden_type_castszary,prepend,append,expectedii)rrrrr)rrrr)rrrrr)rrrrUcCs.tj|||d}t|||j|jksJdS)NrL)rrrrJ)rrMrPrQrRactualr!r!r"test_ediff1d_scalar_handlings  z'TestSetOps.test_ediff1d_scalar_handlingc sdd}tj|tgdhdfdd}tdgd}tgd gd gd g}|||d d g}d}|||td}||||||||||d|||d|ddg}|||||||||dS)NcSst|}||vSN)rasarrayflattentolist)rrr!r!r" _isin_slowsz(TestSetOps.test_isin.._isin_slowr)otypesexcludedcs"t||}||}t||dSrX)r r)rrxy isin_slowr!r"assert_isin_equals  z/TestSetOps.test_isin..assert_isin_equalrrr)r3)rrr) !)r5r1)rr/)r5rrrr/)r vectorizeboolr$reshaper) rr\rcrrrdfr_r!rar" test_isins(            zTestSetOps.test_isincCsdD]}gd}gd|}tgd}t||dd}t||d|d<tgd }t||dd}t||d \|d<|d <tgd }t||dd}t||tgd }gd|}gd}t||}t|||gd|}gd}t||}t||tgd}tgd|}tgd}t||}t||tgd}tgd|}tgd}t||}t||tddg}tddg|}tddg}t||}t||qtdg}tdg}tdg}t||}t||ttgggdS)Nrr3rr)TFTTTrr1r)FFTT)rr1r)TFTFrrrrrrrrrrrrrrre)FTFTTTTTTFTFFF)rrr)TTTTTTTTTTTFTT)rrrrr)rrrrrr)TFTTTrrFrrr r)rmultrrrrr!r!r" test_in1dsX                    zTestSetOps.test_in1dcCsBtgd}tddg}tgd}t||}t||dS)N)rrrrnerrvrrr)TFTFFTFFrsr@r!r!r"test_in1d_char_array+s  zTestSetOps.test_in1d_char_arraycCsHdD]}tgd}gd|}ttt||t||ddqdS)zTest in1d's invert parameterrqrrreTinvertN)rrrryr )rrtrrr!r!r"test_in1d_invert4s  "zTestSetOps.test_in1d_invertcCstddd}tdddd}tdddd}tgd}tt||dd |tt||d d |tt||dd |tt||d d |dS) Nr/rrr5?rg)FFFTTTTrF)rr$rmrrr )rrrlong_brr!r!r"test_in1d_ravel=szTestSetOps.test_in1d_ravelcCs<dg}tdgd}tdg}t||}t||dSNrr3Frsrar1ar2rRresultr!r!r"test_in1d_first_array_is_objectJ   z*TestSetOps.test_in1d_first_array_is_objectcCs:d}tdgd}tdg}t||}t||dSr~rsrr!r!r" test_in1d_second_array_is_objectQs   z+TestSetOps.test_in1d_second_array_is_objectcCs<dg}tdgd}tdg}t||}t||dS)Nr3Trsrr!r!r" test_in1d_both_arrays_are_objectXrz+TestSetOps.test_in1d_both_arrays_are_objectcCs`tdtfdtfg}tjdg|d}tjdgd|d}tdg}t||}t||dS)Nfield1field2)rNrIr3T)rrJintobjectrr r)rdtrrrRrr!r!r"+test_in1d_both_arrays_have_structured_dtype_s   z6TestSetOps.test_in1d_both_arrays_have_structured_dtypecCs`tjddgtd}tjddgtd}tddg}t||}t||tj||dd}t|t|tjgdtd}|dd}tjgdtd}|dd}tddg}t||}t||tj||dd}t|t|tjgdtd}|dd}tjddgtd}tdd g}t||}t||tj||dd}t|t|dS) NrrrITrx)r)rrrrD)rrrrF)rrrr rryrr!r!r"'test_in1d_with_arrays_containing_tuplesis0         z2TestSetOps.test_in1d_with_arrays_containing_tuplesc Cstgd}tgd}tgd}t||}t||tgdgdg}tgd}tgd}t||}t||tgtggdS)N)rrrrrrrrrrrr)rrrrrr)rrr)rrr)rrrrr)rrrrrr)rrr r) rrrrrr_r`ezzr!r!r" test_union1ds    zTestSetOps.test_union1dcCstgd}tgd}tddg}t||}t||td}td}tddg}t||}t||tgtggtdtj}tt|gjtjdS) N)r/rrrrrrrrr/rrfr!)rrr rr$uint32rrJr@r!r!r"test_setdiff1ds      zTestSetOps.test_setdiff1dcCsFtgd}tgd}tddg}t||dd}t||dS)N)rrr)rrrrrTr)rrr r)rrrrRrVr!r!r"test_setdiff1d_uniques z TestSetOps.test_setdiff1d_uniquecCs8tgd}tgd}tt||tdgdS)N)rrr)rrsr)rrrr )rrrr!r!r"test_setdiff1d_char_arraysz$TestSetOps.test_setdiff1d_char_arraycCsRtgd}tgd}t||}t||}t||}t||}t||dS)N)rrrrr1)r5r1rrrrr)rrrrr r r)rrrc1aux1aux2c2r!r!r" test_manywayss    zTestSetOps.test_manyways)%r'r(r)r#r-r?rArHpytestmark parametrizerrint64nanfloat32int8rTint16float64int32rWrprurwrzr}rrrrrrrrrrr!r!r!r"rs '   )<    ! rc@sfeZdZddZddZddZddZej d d d gd d Z ddZ ddZ ddZ ddZdS) TestUniquecCsddd}gdd}gd}gd}gdd}tgdd}g}|tjd |tjd |d |d |D]}t||} t||} || | ||||q>d }tt||} || dd<tt||} || dd<|| | ||||ddg}ttt |||} ttt |||} || | ||||gd} t t | ddggd}gd} gd} t |} t | | t |dd\}}t || t || t d}d|d<tj |dd\}}t |t dg}tj |ddd}tj |ddd}tj |ddddd\}}t|jtjt|jtjt|jtjt|jtjdtjdtjg}ddtjg}gd}gd }gd!}tt ||ttj |dd||fttj |dd||fttj |dd"||fd#tjd$td%tjtdtjg}d$d#td%tjg}gd&}gd'}gd(}tt ||ttj |dd||fttj |dd||fttj |dd"||ftd)}td*|td+|g}td+td*|g}gd}gd }gd!}tt ||ttj |dd||fttj |dd||fttj |dd"||ftd)}tdd,|tdd-|g}tdd-tdd,|g}gd}gd }gd!}tt ||ttj |dd||fttj |dd||fttj |dd"||ftjgd.}tjg}d/g}gd0}d.g}tt ||ttj |dd||fttj |dd||fttj |dd"||fdS)1Nc Ssd}|d|}t|}t||||d|}t|ddd\}} t|||t| |||d|}t|ddd\}} t|||t| |||d|}t|ddd\}} t|||t| |||d|}t|ddd\}} } t|||t| ||t| |||d |}t|ddd\}} } t|||t| ||t| |||d |}t|ddd\}} } t|||t| ||t| |||d |}t|ddd\}} } } t|||t| ||t| ||t| ||dS) Nzcheck {0} failed for type {1}values return_indexTFreturn_inverse return_countszreturn_index and return_inversezreturn_index and return_countsz return_inverse and return_countsz.return_index, return_inverse and return_counts)rNr r) rrr8r9rrbase_msgrSvjj1j2j3r!r!r" check_allsN                          z,TestUnique.test_unique_1d..check_all)rrrrrrrr3)rrrr)rrrr)rrrrrrr)rrrr AllIntegerAllFloat datetime64[D]timedelta64[D]O)i)??rrr)rrrrr+)rrrrrrT)rrr.)rr)rrg@rK)rrr)rrrr)rrr)ry@y??)rrr)rrrrr)rrrnatz 2020-12-26z 2020-12-24Dhrr)rrrr)rmultiplyextend typecodesrQremptylenlistziprr chararrayzerosrrJintprcomplex datetime64 timedelta64)rrrrr8r9rtypesraabbunqinva1a2a2_inva1_idxa3_idxa3_invuaua_idxua_invua_cntrall_nansr!r!r"test_unique_1ds 0                zTestUnique.test_unique_1dcCs\tt|jttt|jdtfdtfgttjttdddttjttddddS)Nrrr3raxis) rrO_run_axis_testsrrr AxisErrorr r$r%r!r!r"test_unique_axis_errorsps z"TestUnique.test_unique_axis_errorscCsZd}gdgdg}t|}tt|ddt|dd|tt|ddt|dd|dS)NzUnique failed on list of listsrrrrrr)rrYrr )rrSinpinp_arrr!r!r"test_unique_axis_listxs   z TestUnique.test_unique_axis_listcCsg}|tjd|tjd|d|d|dtfdtfg|dtfdtfg|D]}||q4d}tjdtjd  d d  t }tj d d gd d ggt d }t t|dd||d}t ddgddgddgddgg}t ddgg}t t|dd||dS)Nrrrrrrz&Non-bitwise-equal booleans test failedr3rIrDrFTrrz"Negative zero equality test failedgr)rrrrQrfloatrr$uint8rmviewrlrrr )rrrJrSdatarr!r!r"test_unique_axiss"   "zTestUnique.test_unique_axisrrrDcCs,tgd}t||d}t|gddS)N)rrrrrrrrrr.rrr r)rrr_uniqr!r!r"test_unique_1d_with_axiss z#TestUnique.test_unique_1d_with_axisc CsRtjdtjd}t|ddddd\}}}}t|j|jt|tjddt|tdgt|tddgt|tdgt|d dddd\}}}}t|j|jt|tjddt|tgt|tgt|tgd }tj|d}tt |D]"}t |} ||dkrd| |<nd | |<tt||d tj| dqdS) N)rr)r7rJrTrrrr)rr)r7rr)rrrrrrrr) rrrr rrJrrrangerr) r single_zeroridxrcntr7multiple_zerosrexpected_shaper!r!r"test_unique_axis_zeross8     z!TestUnique.test_unique_axis_zeroscCshtjgddd}tj|d}t|}tj|ddd\}}}d}t|j|j|t|j|j|dS)N)@rrrrr{r{rrrrrrr{rrrIrT)rrz6Unique returned different results when asked for index)rrma masked_equalr rrmask)rr_r`rv2rrrSr!r!r"test_unique_maskeds  zTestUnique.test_unique_maskedcCsDd}dD]}tdgdgg|}tj|dd}t||||qdS)Nz*sort order incorrect for integer type '%s'bhilqrDrrr)rfmtrrrr!r!r" test_unique_sort_order_with_axiss z+TestUnique.test_unique_sort_order_with_axisc Cstgdgdgdgdg|}d}tddg}tt||||d}tgdgdg}tt|dd|||d}tgd gd gd gd g}tt|dd|||d }tddgddggddgddggg|}tj|ddgd d}tt|d d||t|dd d d d\}}}} d}t||||d}t|||d}t| td d g|t|dd d d d\}}}} d}t|dd|f|d}t|dd|f|d}t| tgd|dS)N)rrrr)rrrrz&Unique with 1d array and axis=0 failedrrz&Unique with 2d array and axis=0 failedrz&Unique with 2d array and axis=1 failed)rrrrz&Unique with 3d array and axis=2 failedrTrz-Unique's return_index=True failed with axis=0z/Unique's return_inverse=True failed with axis=0z.Unique's return_counts=True failed with axis=0z-Unique's return_index=True failed with axis=1z/Unique's return_inverse=True failed with axis=1z.Unique's return_counts=True failed with axis=1)rrr)rrastyperr take) rrJrrSrdata3drrrrr!r!r"rs\ " zTestUnique._run_axis_testsN)r'r(r)rrrrrrrrrrrrr!r!r!r"rs* $ r)__doc__numpyr numpy.testingrrrrnumpy.lib.arraysetopsrrrr r r r r rrrr!r!r!r"s(: