o
    ŀgt#                     @   sl   d dl m Z  d dlZd dlZd dlZd dlmZmZ d dlm	Z
 d dlmZ defddZG dd	 d	ZdS )
    )datetimeN)IndexSeries)	safe_sortreturnc                 C   s   t | t |kS )zO
    Checks if the set of unique elements of arr1 and arr2 are equivalent.
    )	frozenset)arr1arr2 r
   _/var/www/html/myenv/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_setops.pyequal_contents   s   r   c                
   @   s  e Zd Zejdg ddd Zdd Zdd Zejd	e	j
eegd
d Zdd Zdd Zdd Zdd Zejd	e	j
eegdd Zdd Zdd Zdd Zejdeddgdgfeg dd dgfgd!d" Zd#d$ Zd%d& Zejd'd(e	j
g d)d*efd+gd,d-fd(e	j
g d.d*efd+gd,d/fd0e	j
g d1d*efd+gd,d/fgd2d3 Zejd4d5d6gg gejd7d6d5gg gejd8g d9d:d; Zejd<d=d>dggd?g d@ggdAdB Zd/S )CTestIndexSetOpsmethod)unionintersection
differencesymmetric_differencec                 C   sn   t ddg}t ddg}tjtdd t|||dd W d    n1 s'w   Y  t|||dd d S )	NabczThe 'sort' keyword only takesmatch   sortT)r   pytestraises
ValueErrorgetattr)selfr   idx1idx2r
   r
   r   test_setops_sort_validation   s   z+TestIndexSetOps.test_setops_sort_validationc                 C   s
  t g dtd}||dd  }|dd  }t|| ||dd  d d d }t|| |j|dd  d d}|}t||j |j|dd  d d}t|| |j|dd  d d d d d}t||j |j|dd  d d d d d}t|| d S )N)   r      dtyper#   r   )	r   objectr   tmassert_index_equal_unionassert_numpy_array_equalvaluesr   )r   idxresultexpectedr
   r
   r   !test_setops_preserve_object_dtype$   s     z1TestIndexSetOps.test_setops_preserve_object_dtypec                 C   sJ   t g d}|dd  }|d d }||}t g d}t|| d S )Nr   r   r#   r   r   r   r$      )r   r#   r   r   r   r   )r   r   r)   r*   r   indexfirstsecondr/   r0   r
   r
   r   test_union_base>   s   
zTestIndexSetOps.test_union_baseklassc                 C   sF   t g d}|dd  }|d d }|||j}t||s!J d S )Nr2   r$   r3   )r   r   r-   r   )r   r9   r5   r6   r7   r/   r
   r
   r   test_union_different_type_baseH   s
   z.TestIndexSetOps.test_union_different_type_basec                 C   s   t dtdg}tt ||d d }W d    n1 s"w   Y  t|| tt |j|d d d d}W d    n1 sHw   Y  t|| |j|d d dd}t|| d S )Nr#   2000r   F)r   pd	Timestampr)   assert_produces_warningRuntimeWarningr   r*   )r   r.   r/   r
   r
   r   "test_union_sort_other_incomparableS   s   z2TestIndexSetOps.test_union_sort_other_incomparablec                 C   s\   t dtdg}tjtdd |j|d d dd W d    d S 1 s'w   Y  d S )Nr#   r;   z.*r   Tr   )r   r<   r=   r   r   	TypeErrorr   r   r.   r
   r
   r   'test_union_sort_other_incomparable_truee   s   "z7TestIndexSetOps.test_union_sort_other_incomparable_truec                 C   s2   t g d}t g d}t|j|dd| d S )Nr   r   r   )r   r   r   Tr   r   r)   r*   r   )r   r.   sorted_r
   r
   r   !test_intersection_equal_sort_truej   s   z1TestIndexSetOps.test_intersection_equal_sort_truec                 C   sb   t g d}|d d }|d d }|d u rt g dnt g d}|j||d}t|| d S )Nr2   r3   r$   )r   r#   r   r   r   r#   r   r   r   r)   r*   )r   r   r5   r6   r7   r0   r/   r
   r
   r   test_intersection_baseo   s    z&TestIndexSetOps.test_intersection_basec                 C   sJ   t g d}|d d }|d d }|j||j|d}t||s#J d S )Nr2   r3   r$   r   )r   r   r-   r   )r   r9   r   r5   r6   r7   r/   r
   r
   r   %test_intersection_different_type_basey   s
   z5TestIndexSetOps.test_intersection_different_type_basec                 C   s2   t g dddg}t ddg}t|| d S )N)r   r   r   r   r   rI   )r   r/   r0   r
   r
   r   test_intersection_nosort   s   z(TestIndexSetOps.test_intersection_nosortc                 C   s<   t g d}t|j|dd| t|j|d d| d S )NrD   Fr   rE   rB   r
   r
   r   test_intersection_equal_sort   s   z,TestIndexSetOps.test_intersection_equal_sortc                 C   sT   t dddt dddg}t|td}tdgtd}|j||d}t|dks(J d S )	Ni  r   	      r%   aar   r   )r   r   r(   r   len)r   r   dt_datesi1i2r/   r
   r
   r   test_intersection_str_dates   s
   z+TestIndexSetOps.test_intersection_str_dateszindex2,expected_arrBD)rV   rW   ArX   c                 C   sB   t g d}t |}|j||d}|d u r| }t|| d S )N)rX   rV   rX   Cr   )r   r   sort_valuesr)   r*   )r   index2expected_arrr   index1r0   r/   r
   r
   r   *test_intersection_non_monotonic_non_unique   s   z:TestIndexSetOps.test_intersection_non_monotonic_non_uniquec                 C   s`   t g d}|d d }|dd  }|||}t g d}|d u r(t t|}t|| d S )Nr2      r$   rH   )r   r   r   r)   r*   )r   r   r5   r6   r7   r/   r0   r
   r
   r   test_difference_base   s   z$TestIndexSetOps.test_difference_basec                 C   sJ   t g d}|d d }|dd  }||}t g d}t|| d S )Nr2   r_   r$   )r   r#   r   r   r   )r   r   r)   r*   r4   r
   r
   r   test_symmetric_difference   s   
z)TestIndexSetOps.test_symmetric_differencezmethod,expected,sortr   r#   rX   r   rX   r#   rV   r   rV   numletS1r%   F)rc   re   rd   rf   Nr   )rc   re   r#   rY   rd   rf   r   rY   c                 C   st   t tjg ddtfdgd}t tjg ddtfdgd}t||||d}|jdks.J t |}t|| d S )Nrb   rg   rh   r%   )rc   rd   re   rf   rk   rl   r   r#   )r   nparrayintr   ndimr)   r*   )r   r   r0   r   r]   r[   r/   r
   r
   r   test_tuple_union_bug   s    

z$TestIndexSetOps.test_tuple_union_bug
first_listr   r   second_listz&first_name, second_name, expected_name))rX   rV   N)NrV   N)rX   NNc                 C   s   t ||d}t ||d}|j||d}	t||}
|d u r:t|dkr:t|dkr:t t|
|d}t|	| d S t |
|d}t|	 |  d S )N)namer   r   )r   r   setrQ   sortedr)   r*   rZ   )r   rr   rs   
first_namesecond_nameexpected_namer   r6   r7   r   valsr0   r
   r
   r   test_union_name_preservation   s   	 z,TestIndexSetOps.test_union_name_preservationzdiff_type, expectedr   r#   r   )r#   r   rV   rY   c                 C   s>   t g d}t g d}t|||}t |}t|| d S )N)r   r#   rX   rV   )r   r   rX   rY   )r   r   r)   r*   )r   	diff_typer0   r    r!   r/   r
   r
   r   test_difference_object_type   s
   z+TestIndexSetOps.test_difference_object_type)__name__
__module____qualname__r   markparametrizer"   r1   r8   rm   rn   r   listr:   r@   rC   rG   rJ   rK   rL   rM   rU   r   r^   r`   ra   ro   rq   r{   r}   r
   r
   r
   r   r      s~    






		$
	

	
	

r   )r   numpyrm   r   pandasr<   r   r   pandas._testing_testingr)   pandas.core.algorithmsr   boolr   r   r
   r
   r
   r   <module>   s    