a
    IbKp                     @   st   d Z ddlZddlmZmZmZmZ ddlm	Z	m
Z
mZmZmZmZmZmZ ddlZG dd dZG dd dZdS )	z-Test functions for 1D array set operations.

    N)assert_array_equalassert_equalassert_raisesassert_raises_regex)ediff1dintersect1dsetxor1dunion1d	setdiff1duniquein1disinc                   @   s  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zej	
dejg dejddejdfejg dejdejg dejdddfejg dejdejejdfgdd Zej	
dejg dejdddejg dejdfejg dejdejdgejddejg dejdfejg dejdddejg dejdfejg dejdddejg dejdfgd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Z d8d9 Z!d:d; Z"d<d= Z#d>d? Z$dS )@
TestSetOpsc                 C   s   t g d}t g d}t g d}t||dd}t|| t g d}t g d}t g d}t||}t|| tg tg g  d S )N            r         r   r   )r   r   r   Tassume_unique)r   r   r   r   r   )r   r   r   r   r   r   r   )nparrayr   r   )selfabeccZed r    ]/var/www/html/barcode/barcode/lib/python3.9/site-packages/numpy/lib/tests/test_arraysetops.pytest_intersect1d   s    


zTestSetOps.test_intersect1dc                 C   sL   G dd d}| }t ||}t|| t g dg d}t|g d d S )Nc                   @   s   e Zd Zdd ZdS )z4TestSetOps.test_intersect1d_array_like.<locals>.Testc                 S   s
   t dS )Nr   )r   aranger   r    r    r!   	__array__%   s    z>TestSetOps.test_intersect1d_array_like.<locals>.Test.__array__N)__name__
__module____qualname__r%   r    r    r    r!   Test$   s   r)   r   r   r   )r   r   )r   r)   r   resr    r    r!   test_intersect1d_array_like"   s    

z&TestSetOps.test_intersect1d_array_likec                 C   s  t g d}t g d}t||ddd\}}}t g d}t|| t|| | t|| | t g d}t g d}t||dd\}}}t g d}t|| t|| | t|| | t g d	g d
g}t g dg dg}t||ddd\}}}t ||j}t ||j}	t g d}
t|
||  t|
||	  t g dg dg}t g dg dg}t||dd\}}}t ||j}t ||j}	t g d}
t|
||  t|
||	  d S )Nr   r   r   r   )r   r   r      T)r   return_indices)r   r   r   )r   r   r   r   r   r   r   )r      r   r   r   r   r   r   )r/   )r   r   r   r.   )r   r0   r      )r   r   r   r.   )
      r0   	   )r   r.   r   r0   )r   r   r   r.   r.   )r   r   r0   r   r   )r   r   r   r   )r2   r3   r0   r   )r   r   r0   )r   r   r   r   Zunravel_indexshape)r   r   r   r   i1i2eeZefZui1Zui2Zear    r    r!   test_intersect1d_indices.   s<    

z#TestSetOps.test_intersect1d_indicesc                 C   s   t g d}t g d}t g d}t||}t|| t g d}t g d}t g d}t||}t|| t g d}t g d}t g d}t||}t|| tg tg g  d S )	Nr   r   )r   r   r   r*   )r.   r   r   )r   r   r   r   r   r.   )r   r0   r   r   )r.   r   r   r0   )r   r   r   r   r   r   r   r   r   r    r    r!   test_setxor1dU   s     





zTestSetOps.test_setxor1dc                 C   s,  t g }t dg}t ddg}tg t| tdgt|dd tdgt|dd tddgt|ddd tg t| tdgt| tg dt|d	d
d tg dt|ddgd	dgd tdd
gt|d
d tg dt|d	dgd td	dgt|d	d tg dt|ddgd d S )Nr   r   r   )to_begin)to_end)r<   r=   )r   r   r4   r   r4   )r   r.   r   r   r0   r   r.   r0   )r   r   r0   )r   r.   r   )r   r   r   r   )r   Z	zero_elemZone_elemZtwo_elemr    r    r!   test_ediff1dm   s"    
zTestSetOps.test_ediff1dzary, prepend, append, expectedr*   dtypeNr=   )r   r   r   r<   )      ?g      @g      "@c                 C   sF   d |}tt| t|||d W d    n1 s80    Y  d S )Nz dtype of `{}` must be compatiblearyr=   r<   )formatr   	TypeErrorr   )r   rD   prependappendexpectedmsgr    r    r!   !test_ediff1d_forbidden_type_casts   s    
z,TestSetOps.test_ediff1d_forbidden_type_castszary,prepend,append,expectedi   i  )r   r   r   r   r   )r   r   r   r   )r   r   r   r   r   )r   r   r   rL   c                 C   s.   t j|||d}t|| |j|jks*J d S )NrC   )r   r   r   rA   )r   rD   rG   rH   rI   actualr    r    r!   test_ediff1d_scalar_handling   s    
z'TestSetOps.test_ediff1d_scalar_handlingc           	         s   dd }t j|tgdhd  fdd}t dg d}t g d	g d
g dg}||| ddg}d}||| t d}||| ||| ||| |d| ||d |dd g }||| ||| ||| d S )Nc                 S   s   t |  }| |v S N)r   asarrayflattentolist)r   r   r    r    r!   
_isin_slow   s    z(TestSetOps.test_isin.<locals>._isin_slowr   )ZotypesZexcludedc                    s"   t | |} | |}t|| d S rO   )r   r   )r   r   xyZ	isin_slowr    r!   assert_isin_equal   s    

z/TestSetOps.test_isin.<locals>.assert_isin_equal   r   r   r   )r2         )r   r   r   )      !   )r4   r0   )r   r.   )r4   r   r   r   r.   )r   Z	vectorizeboolr#   reshaper   )	r   rS   rW   r   r   r   dfrT   r    rV   r!   	test_isin   s(    










zTestSetOps.test_isinc                 C   s  dD ]}g d}g d| }t g d}t||dd}t|| d|d< t g d	}t||dd}t|| d
\|d< |d< t g d}t||dd}t|| t g d}g d| }g d}t||}t|| |g d|  }g d}t||}t|| t g d}t g d| }t g d}t||}t|| t g d}t g d| }t g d}t||}t|| t ddg}t ddg| }t ddg}t||}t|| qt dg}t dg}t dg}t||}t|| ttg g g  d S )Nr   r2   r   r   )TFTTTr   r0   r   )FFTT)r   r0   r   )TFTFr   r   r   r   r   r   r   r   r   r   r   r   r   r   rY   )FTFTTTTTTFTFFF)r   r   r   )TTTTTTTTTTTFTT)r   r   r   r   r   )r   r   r   r   r   r   )TFTTTr   r   Fr   r   r   r   )r   multr   r   r   r   r    r    r!   	test_in1d   sX    














zTestSetOps.test_in1dc                 C   sB   t g d}t ddg}t g d}t||}t|| d S )N)r   r   r   ra   er   ri   r   r   r   )TFTFFTFFrf   r:   r    r    r!   test_in1d_char_array+  s
    
zTestSetOps.test_in1d_char_arrayc                 C   sH   dD ]>}t g d}g d| }tt t||t||dd qdS )zTest in1d's invert parameterrd   re   rY   TinvertN)r   r   r   rl   r   )r   rg   r   r   r    r    r!   test_in1d_invert4  s    zTestSetOps.test_in1d_invertc                 C   s   t ddd}t dddd}t dddd}t g d}tt||dd	| tt||d
d	| tt||dd	| tt||d
d	| d S )Nr.   r   r   r4   ?   r[   )FFFTTTTr   F)r   r#   r`   r   r   r   )r   r   r   Zlong_br   r    r    r!   test_in1d_ravel=  s    zTestSetOps.test_in1d_ravelc                 C   s<   d g}t dgd }t dg}t ||}t|| d S Nr   r2   Frf   r   ar1ar2rI   resultr    r    r!   test_in1d_first_array_is_objectJ  s
    z*TestSetOps.test_in1d_first_array_is_objectc                 C   s:   d}t d gd }t dg}t ||}t|| d S rp   rf   rq   r    r    r!    test_in1d_second_array_is_objectQ  s
    z+TestSetOps.test_in1d_second_array_is_objectc                 C   s<   d g}t d gd }t dg}t ||}t|| d S )Nr2   Trf   rq   r    r    r!    test_in1d_both_arrays_are_objectX  s
    z+TestSetOps.test_in1d_both_arrays_are_objectc                 C   s`   t dtfdtfg}t jdg|d}t jdgd |d}t dg}t ||}t|| d S )NZfield1Zfield2)r   Nr@   r2   T)r   rA   intobjectr   r   r   )r   dtrr   rs   rI   rt   r    r    r!   +test_in1d_both_arrays_have_structured_dtype_  s    z6TestSetOps.test_in1d_both_arrays_have_structured_dtypec                 C   s`  t jddgtd}t jddgtd}t ddg}t ||}t|| t j||dd}t|t | t jg dtd}|d d }t jg dtd}|d d }t ddg}t ||}t|| t j||dd}t|t | t jg dtd}|d d }t jddgtd}t dd	g}t ||}t|| t j||dd}t|t | d S )
Nr   r   r@   Trk   )r|   )r   r   r   r>   )r|   r   r   r   F)r   r   ry   r   r   rl   rq   r    r    r!   'test_in1d_with_arrays_containing_tuplesi  s0    


z2TestSetOps.test_in1d_with_arrays_containing_tuplesc           	      C   s   t g d}t g d}t g d}t||}t|| t g dg dg}t g d}t g d}t||}t|| tg tg g  d S )N)r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   )r   r   r   )r   r   r   r   r   )r   r   r   r   r   r   )r   r   r	   r   )	r   r   r   r   r   rT   rU   Zezzr    r    r!   test_union1d  s    



zTestSetOps.test_union1dc                 C   s   t g d}t g d}t ddg}t||}t|| t d}t d}t ddg}t||}t|| tg tg g  t dt j}tt|g jt j d S )	N)r.   r   r   r   r   r   r   r   r   r.   r         rZ   r    )r   r   r
   r   r#   Zuint32r   rA   r:   r    r    r!   test_setdiff1d  s    





zTestSetOps.test_setdiff1dc                 C   sF   t g d}t g d}t ddg}t||dd}t|| d S )N)r   r   r   )r   r   r   r   r   Tr   )r   r   r
   r   )r   r   r   rI   rM   r    r    r!   test_setdiff1d_unique  s
    z TestSetOps.test_setdiff1d_uniquec                 C   s8   t g d}t g d}tt||t dg d S )N)r   r   r   )r   r   sr   )r   r   r   r
   )r   r   r   r    r    r!   test_setdiff1d_char_array  s    z$TestSetOps.test_setdiff1d_char_arrayc                 C   sR   t g d}t g d}t||}t||}t||}t||}t|| d S )N)r   r   r   r   r0   )r4   r0   r   r   r   r   r   )r   r   r   r   r	   r
   r   )r   r   r   Zc1Zaux1Zaux2c2r    r    r!   test_manyways  s    



zTestSetOps.test_manyways)%r&   r'   r(   r"   r,   r9   r;   r?   pytestmarkparametrizer   r   int64nanfloat32int8rK   int16float64int32rN   rc   rh   rj   rm   ro   ru   rv   rw   r{   r~   r   r   r   r   r   r    r    r    r!   r      s~   '

)<		
!r   c                   @   sn   e Zd Zdd Zdd Zdd Zdd Zej	d	d
dgdd Z
dd Zdd Zdd Zdd Zdd ZdS )
TestUniquec                 C   sd  dd }g dd }g d}g d}g dd }t g dd}g }|t jd	  |t jd
  |d |d |D ].}t ||}	t ||}
||	|
|||| q|d}t t||}	||	d d < t t||}
||
d d < ||	|
|||| ddg}t tt	|||}	t tt	|||}
||	|
|||| g d}	t
t |	ddg g d}g d}g d}t|}t
|| t|dd\}}t
|| t
|| t d}d|d< t j|dd\}}t
|t d g }t j|ddd }t j|ddd }t j|ddddd  \}}t|jt j t|jt j t|jt j t|jt j dt jdt jg}ddt jg}g d}g d }g d!}tt || tt j|dd||f tt j|dd||f tt j|dd"||f d#t jd$td%t jtdt jg}d$d#td%t jg}g d&}g d'}g d(}tt || tt j|dd||f tt j|dd||f tt j|dd"||f t d)}t d*|t d+|g}t d+t d*|g}g d}g d }g d!}tt || tt j|dd||f tt j|dd||f tt j|dd"||f t d)}t dd,|t dd-|g}t dd-t dd,|g}g d}g d }g d!}tt || tt j|dd||f tt j|dd||f tt j|dd"||f t jgd. }t jg}d/g}g d0}d.g}tt || tt j|dd||f tt j|dd||f tt j|dd"||f d S )1Nc                 S   s  d}| d|}t| }t||| | d|}t| ddd\}}	t||| t|	|| | d|}t| ddd\}}	t||| t|	|| | d|}t| ddd\}}	t||| t|	|| | d|}t| ddd\}}
}t||| t|
|| t||| | d	|}t| ddd\}}
}t||| t|
|| t||| | d
|}t| ddd\}}
}t||| t|
|| t||| | d|}t| ddd\}}
}}t||| t|
|| t||| t||| d S )Nzcheck {0} failed for type {1}valuesreturn_indexTFreturn_inversereturn_countszreturn_index and return_inversezreturn_index and return_countsz return_inverse and return_countsz.return_index, return_inverse and return_counts)rE   r   r   )r   r   r6   r7   r   rz   Zbase_msgrJ   vjZj1Zj2Zj3r    r    r!   	check_all  sN    z,TestUnique.test_unique_1d.<locals>.check_all)r   r   r   r   r   r   r   r2   )r   r   r   r   )r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   r   
AllIntegerAllFloatdatetime64[D]timedelta64[D]O) i)      ?              ?      r   r   r   )r   r   r   r}   r*   )r   r   r   r   r   r   T)r   r   r   .)r   r   )r   r   g       @rB   )r   r   r   )r   r   r   r   )r   r   r   )r   y       @      y      ?      ?        )r   r   r   )r   r   r   r   r   )r   r   r   natz
2020-12-26z
2020-12-24Dhr   r   )r   r   r   r   )r   multiplyextend	typecodesrH   r   emptylenlistzipr   r   Z	chararrayzerosr   rA   Zintpr   complexZ
datetime64Ztimedelta64)r   r   r   r   r6   r7   r   typesrz   ZaaZbbunqinvZa1Za2Za2_invZa1_idxZa3_idxZa3_invZuaZua_idxZua_invZua_cntr   Zall_nansr    r    r!   test_unique_1d  s    0





 

zTestUnique.test_unique_1dc                 C   s\   t t| jt t t| jdtfdtfg t tjttddd t tjttddd d S )Nr   r   r2   r   axis)	r   rF   _run_axis_testsry   rx   r   Z	AxisErrorr   r#   r$   r    r    r!   test_unique_axis_errorsp  s    z"TestUnique.test_unique_axis_errorsc                 C   sZ   d}g dg dg}t |}tt|ddt|dd| tt|ddt|dd| d S )NzUnique failed on list of listsr   r   r   r   r   r   )r   rP   r   r   )r   rJ   inpZinp_arrr    r    r!   test_unique_axis_listx  s
    
z TestUnique.test_unique_axis_listc                 C   s  g }| tjd  | tjd  |d |d |dtfdtfg |dtfdtfg |D ]}| | qhd}tjdtjd		d
d
t}tjddgddggtd	}tt|dd|| d}tddgddgddgddgg}tddgg}tt|dd|| d S )Nr   r   r   r   r   r   z&Non-bitwise-equal booleans test failedr2   r@   r>   r   FTr   r   z"Negative zero equality test failedg       r   )r   r   r   rH   rx   floatr   r#   uint8r`   viewr_   r   r   r   )r   r   rA   rJ   datart   r    r    r!   test_unique_axis  s"    

"zTestUnique.test_unique_axisr   r   r>   c                 C   s,   t g d}t||d}t|g d d S )N)r   r   r   r   r   r   r   r   r   r-   r   r   r   r   )r   r   rT   uniqr    r    r!   test_unique_1d_with_axis  s    z#TestUnique.test_unique_1d_with_axisc           
      C   sV  t jdt jd}t|ddddd\}}}}t|j|j t|t jdd t|t dg t|t ddg t|t dg t|d	dddd\}}}}t|j|j t|t jdd t|t g  t|t g  t|t g  d
}t j|d}tt	|D ]H}t
|}	|| dkr,d|	|< nd	|	|< tt||dt j|	d qd S )N)r   r   )r5   rA   r   Tr   r   r   r   )r   r   )r5   r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   rA   r   r   ranger   r   )
r   Zsingle_zeror   idxr   cntr5   Zmultiple_zerosr   Zexpected_shaper    r    r!   test_unique_axis_zeros  s6    

z!TestUnique.test_unique_axis_zerosc                 C   sh   t jg ddd}t j|d}t |}t j|ddd\}}}d}t|j|j| t|j|j| d S )N)@   r   r   r   r   rn   rn   r   r   r   r   r   r   rn   r   r   r@   r   T)r   r   z6Unique returned different results when asked for index)r   r   maZmasked_equalr   r   r   mask)r   rT   rU   r   Zv2r   r   rJ   r    r    r!   test_unique_masked  s    

zTestUnique.test_unique_maskedc                 C   sD   d}dD ]6}t dgdgg|}t j|dd}t||||  qd S )Nz*sort order incorrect for integer type '%s'Zbhilqr>   r   r   r   )r   fmtrz   r   r   r    r    r!    test_unique_sort_order_with_axis  s
    z+TestUnique.test_unique_sort_order_with_axisc           
      C   s  t g dg dg dg dg|}d}t ddg}tt|||| d}t g dg dg}tt|dd||| d}t g d	g d
g d	g d
g}tt|dd||| d}t ddgddggddgddggg|}t j|ddgdd}tt|dd|| t|ddddd\}}}}	d}t|| || d}t|| | d}t|	t ddg| t|ddddd\}}}}	d}t|d d |f | d}t|d d |f | d}t|	t g d| d S )N)r   r   r   r   )r   r   r   r   z&Unique with 1d array and axis=0 failedr   r   z&Unique with 2d array and axis=0 failedr   z&Unique with 2d array and axis=1 failed)r   r   r   r   z&Unique with 3d array and axis=2 failedr   Tr   z-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)r   r   r   )r   r   Zastyper   r   Ztake)
r   rA   r   rJ   rt   Zdata3dr   r   r   r   r    r    r!   r     s\    
"
zTestUnique._run_axis_testsc                 C   sj   t ddt jt jt jg}t |}t j|dd}t|t dt jg t|t dt jt jt jg d S )Nr   F)Z	equal_nan)r   r   r   r   r   )r   r   r   Znot_unqr    r    r!   test_unique_nanequals  s
    
z TestUnique.test_unique_nanequalsN)r&   r'   r(   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r    r    r!   r     s    *
$	,r   )__doc__numpyr   Znumpy.testingr   r   r   r   Znumpy.lib.arraysetopsr   r   r   r	   r
   r   r   r   r   r   r   r    r    r    r!   <module>   s   (   :