a
    Pft#                     @   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 ed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)Zarr1Zarr2 r   d/var/www/ai-form-bot/venv/lib/python3.9/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 sN0    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
    0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      Zdtyper!   r   )	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   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_base>   s    
zTestIndexSetOps.test_union_baseklassc                 C   sF   t g d}|dd  }|d d }|||j}t||sBJ d S )Nr-   r"   r.   )r   r   r(   r
   )r   r4   r0   r1   r2   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 sD0    Y  t|| tt& |j|d d d d}W d    n1 s0    Y  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_incomparableS   s    04z2TestIndexSetOps.test_union_sort_other_incomparablec                 C   sZ   t dtdg}tjtdd& |j|d d dd W d    n1 sL0    Y  d S )Nr!   r6   z.*r   Tr   )r   r7   r8   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)   Z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 r8t 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_baseo   s     z&TestIndexSetOps.test_intersection_basec                 C   sJ   t g d}|d d }|d d }|j||j|d}t||sFJ d S )Nr-   r.   r"   r   )r   r   r(   r
   )r   r4   r   r0   r1   r2   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   rB   )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   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sPJ d S )	Ni  r   	      r#   Zaar   r   )r   r   r%   r   len)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)rM   rN   ArO   c                 C   sB   t g d}t |}|j||d}|d u r2| }t|| d S )N)rO   rM   rO   Cr   )r   r   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   s`   t g d}|d d }|dd  }|||}t g d}|d u rPt t|}t|| d S )Nr-      r"   rA   )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-   rU   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!   rO   r   rO   r!   rM   r   rM   numZletZS1r#   F)rY   r[   rZ   r\   Nr   )rY   r[   r!   rP   rZ   r\   r   rP   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 )NrX   r]   r^   r#   )rY   rZ   r[   r\   r_   r`   r   r!   )r   nparrayintr   ndimr&   r'   )r   r   r+   r   rS   rR   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))rO   rM   N)NrM   N)rO   NNc                 C   s   t ||d}t ||d}|j||d}	t||}
|d u rrt|dkrrt|dkrrt t|
|d}t|	| n t |
|d}t|	 |  d S )N)namer   r   )r   r   setrI   sortedr&   r'   rQ   )r   rf   rg   Z
first_nameZsecond_nameZ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   rM   rP   c                 C   s>   t g d}t g d}t|||}t |}t|| d S )N)r   r!   rO   rM   )r   r   rO   rP   )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,   r3   ra   rb   r   listr5   r:   r=   r@   rC   rD   rE   rF   rL   r   rT   rV   rW   rc   re   rl   rm   r   r   r   r	   r      s|   






		$
	

	
	

r   )r   numpyra   r   Zpandasr7   r   r   Zpandas._testingZ_testingr&   Zpandas.core.algorithmsr   boolr
   r   r   r   r   r	   <module>   s   