U
    NZf"                     @   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ddddg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d d!d"gd"d gfgd#d$ Zd%d& Zd'd( Zejd)de	j
d*d+d,d-gd.efd/gd0d1fde	j
d*d,d+d-gd.efd/gd0d2fde	j
d*d,d3d+d-d4gd.efd/gd0d2fgd5d6 Zejd7d8d9gg gejd:d9d8gg gejd;d<d=d>gd?d@ ZejdAddBd ggddBdCd dDgggdEdF Zd2S )GTestIndexSetOpsmethodunionintersection
differencesymmetric_differencec              	   C   sZ   t ddg}t ddg}tjtdd t|||dd W 5 Q R X 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   O/tmp/pip-unpacked-wheel-nbcvw55c/pandas/tests/indexes/base_class/test_setops.pytest_setops_sort_validation   s
    z+TestIndexSetOps.test_setops_sort_validationc                 C   s  t dddg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      Zdtyper   )	r   objectr	   tmassert_index_equalZ_unionZassert_numpy_array_equalvaluesr   )r   idxresultexpectedr   r   r   !test_setops_preserve_object_dtype   s      z1TestIndexSetOps.test_setops_preserve_object_dtypec                 C   sZ   t ddddddg}|dd  }|d d }||}t ddddddg}t|| d S 	Nr   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   sP   t ddddddg}|dd  }|d d }|||j}t||sLtd S r*   )r   r   r%   r#   equalContentsAssertionError)r   r1   r-   r.   r/   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 5 Q R X t|| tt |j|d d d d}W 5 Q R X t|| |j|d d dd}t|| d S )Nr   2000r   F)r   pd	Timestampr#   Zassert_produces_warningRuntimeWarningr   r$   )r   r&   r'   r   r   r   "test_union_sort_other_incomparableL   s     z2TestIndexSetOps.test_union_sort_other_incomparablec              	   C   sF   t dtdg}tjtdd |j|d d dd W 5 Q R X d S )Nr   r5   z.*r   Tr   )r   r6   r7   r   r   	TypeErrorr   r   r&   r   r   r   'test_union_sort_other_incomparable_true^   s    z7TestIndexSetOps.test_union_sort_other_incomparable_truec                 C   s6   t dddg}t dddg}t|j|dd| d S )Nr   r   r   Tr   r   r#   r$   r	   )r   r&   Zsorted_r   r   r   !test_intersection_equal_sort_truec   s    z1TestIndexSetOps.test_intersection_equal_sort_truec                 C   sn   t ddddddg}|d d }|d d }|d krBt dddgnt dddg}|j||d	}t|| d S 
Nr   r   r   r   r   r   r+   r   r   r   r	   r#   r$   )r   r   r-   r.   r/   r(   r'   r   r   r   test_intersection_baseh   s    $z&TestIndexSetOps.test_intersection_basec                 C   sT   t ddddddg}|d d }|d d }|j||j|d	}t||sPtd S r?   )r   r	   r%   r#   r2   r3   )r   r1   r   r-   r.   r/   r'   r   r   r   %test_intersection_different_type_baser   s
    z5TestIndexSetOps.test_intersection_different_type_basec                 C   s4   t dddgddg}t ddg}t|| d S )Nr   r   r   r@   )r   r'   r(   r   r   r   test_intersection_nosort|   s    z(TestIndexSetOps.test_intersection_nosortc                 C   s>   t dddg}t|j|dd| t|j|d d| d S )Nr   r   r   Fr   r=   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sPtd S )	Ni  r   	      r    Zaar   r   )r   r   r"   r	   lenr3   )r   r   Zdt_datesi1i2r'   r   r   r   test_intersection_str_dates   s
    z+TestIndexSetOps.test_intersection_str_dateszindex2,expected_arrBDAc                 C   sJ   t ddddg}t |dd}|j||d}|d kr:| }t|| d S )NrM   rK   Cr"   r    r   )r   r	   Zsort_valuesr#   r$   )r   index2Zexpected_arrr   index1r(   r'   r   r   r   *test_intersection_non_monotonic_non_unique   s    z:TestIndexSetOps.test_intersection_non_monotonic_non_uniquec                 C   sj   t ddddddg}|d d }|dd  }|||}t dddg}|d krZt t|}t|| d S 	Nr   r   r   r   r   r      r   )r   r
   r   r#   r$   )r   r   r-   r.   r/   r'   r(   r   r   r   test_difference_base   s    z$TestIndexSetOps.test_difference_basec                 C   sX   t ddddddg}|d d }|dd  }||}t dddddg}t|| d S rR   )r   r   r#   r$   r,   r   r   r   test_symmetric_difference   s    
z)TestIndexSetOps.test_symmetric_differencezmethod,expected,sortr   rM   r   rM   r   rK   r   rK   numZletZa1r    FNr   rN   r   rN   c                 C   s   t tjddddgdtfdgd}t tjdddddd	gdtfdgd}t||||d
}|jdkshtt |}t|| d S )NrV   rW   rX   rY   rZ   r[   r    r\   r]   r   r   )	r   nparrayintr   ndimr3   r#   r$   )r   r   r(   r   rP   rO   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)rM   rK   N)NrK   N)rM   NNc                 C   s   t ||d}t ||d}|j||d}	t||}
|d krrt|dkrrt|dkrrt t|
|d}t|	| nt |
|d}t|	| d S )N)namer   r   )r   r   setrG   sortedr#   r$   r2   )r   rc   rd   Z
first_nameZsecond_nameZexpected_namer   r.   r/   r   valsr(   r   r   r   test_union_name_preservation   s    	 z,TestIndexSetOps.test_union_name_preservationzdiff_type, expectedr   r   rN   c                 C   sF   t ddddg}t ddddg}t|||}t |}t|| d S )Nr   r   rM   rK   r   rN   )r   r   r#   r$   )r   Z	diff_typer(   r   r   r'   r   r   r   test_difference_object_type   s
    z+TestIndexSetOps.test_difference_object_type)__name__
__module____qualname__r   markZparametrizer   r)   r0   r^   r_   r   listr4   r9   r<   r>   rA   rB   rC   rD   rJ   r   rQ   rT   rU   r`   rb   ri   rj   r   r   r   r   r      s~    







		&
	


	

	

r   )r   Znumpyr^   r   Zpandasr6   r   r   Zpandas._testingZ_testingr#   Zpandas.core.algorithmsr   r   r   r   r   r   <module>   s   