o
    ҷh"                     @   s^   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 G dd dZdS )    )datetimeN)IndexSeries)	safe_sortc                
   @   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idx2 r   ^/var/www/html/venv/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_setops.py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*   r+   r   r   r   test_union_base7   s   
zTestIndexSetOps.test_union_baseklassc                 C   sH   t g d}|dd  }|d d }|||j}t||s"J d S )Nr-   r   r.   )r   r   r(   r$   equalContents)r   r4   r0   r1   r2   r*   r   r   r   test_union_different_type_baseA   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_incomparableL   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   r7   z.*r   Tr   )r   r8   r9   r   r   	TypeErrorr   r   r)   r   r   r   'test_union_sort_other_incomparable_true^   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_truec   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 )Nr-   r.   r   )r   r   r   r   r   r   r   r   r	   r$   r%   )r   r   r0   r1   r2   r+   r*   r   r   r   test_intersection_baseh   s    z&TestIndexSetOps.test_intersection_basec                 C   sL   t g d}|d d }|d d }|j||j|d}t||s$J d S )Nr-   r.   r   r   )r   r	   r(   r$   r5   )r   r4   r   r0   r1   r2   r*   r   r   r   %test_intersection_different_type_baser   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   rE   )r   r*   r+   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 )Nr@   Fr   rA   r>   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)rR   rS   ArT   c                 C   sF   t g d}t |dd}|j||d}|d u r| }t|| d S )N)rT   rR   rT   Cr#   r    r   )r   r	   sort_valuesr$   r%   )r   index2expected_arrr   index1r+   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 )Nr-      r   rD   )r   r
   r   r$   r%   )r   r   r0   r1   r2   r*   r+   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 )Nr-   r[   r   )r   r   r   r   r   )r   r   r$   r%   r/   r   r   r   test_symmetric_difference   s   
z)TestIndexSetOps.test_symmetric_differencezmethod,expected,sortr	   r   rT   r   rT   r   rR   r   rR   numletS1r    F)r_   ra   r`   rb   Nr   )r_   ra   r   rU   r`   rb   r   rU   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 )Nr^   rc   rd   r    )r_   r`   ra   rb   rg   rh   r   r   )r   nparrayintr   ndimr$   r%   )r   r   r+   r   rY   rW   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))rT   rR   N)NrR   N)rT   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   setrM   sortedr$   r%   r5   )r   rn   ro   
first_namesecond_nameexpected_namer   r1   r2   r   valsr+   r   r   r   test_union_name_preservation   s   	 z,TestIndexSetOps.test_union_name_preservationzdiff_type, expectedr
   r   r   )r   r   rR   rU   c                 C   s>   t g d}t g d}t|||}t |}t|| d S )N)r   r   rT   rR   )r   r   rT   rU   )r   r   r$   r%   )r   	diff_typer+   r   r   r*   r   r   r   test_difference_object_type   s
   z+TestIndexSetOps.test_difference_object_type)__name__
__module____qualname__r   markparametrizer   r,   r3   ri   rj   r   listr6   r<   r?   rC   rF   rG   rH   rI   rQ   r   rZ   r\   r]   rk   rm   rw   ry   r   r   r   r   r      s~    






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