a
    Pfzc                     @   sp  d dl Zd dlZd dlZd dlmZmZmZmZm	Z	m
Z
 d dlmZ d dlmZmZ ejdddgejdg dd	d
 Zejde	eje
egdd Zejjejde	eje
e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dd Z d d! Z!d"d# Z"d$d% Z#d&d' Z$ejdg dd(d) Z%d*d+ Z&d,d- Z'd.d/ Z(ejd0e)de)d gd1d2 Z*d3d4 Z+d5d6 Z,d7d8 Z-d9d: Z.d;d< Z/d=d> Z0ejdg d?d@dA Z1ejdBej2dCgdDdE Z3ejdBej2dFgdGdH Z4ejdIdJgdJgfdJdJgdJgfdKdJgdKdJgfgdLdM Z5ejdNdOdddgfdOdPgddgfdOdQgddgfdRdSdTgddgfdRdQdPgddgfdUg dVddgfdRdPdSgdPdgfdRdSdQgddQgfdRdPdQgdPdQgfdRddQgddQgfg
dWdX Z6dYdZ Z7d[d\ Z8d]d^ Z9d_d` Z:ejdadbdcgejddddegdfdg Z;ejdBdhdigdjdk Z<ejdldmej2gdndo Z=ej>dpdqdr Z?dsdt Z@dudv ZAejdwg dVd dxggg dydxggg dzg d{gg dzg d|gd}d~gfgdd ZBejdPejCdPdQgdPdQgddPdQggejdQejCdPdQgdQdPgddejCdPdQgdQdPgdgdd ZDejdBej2dCgdd ZEdd ZFdS )    N)CategoricalIndex	DataFrameIndexIntervalIndex
MultiIndexSeries)is_float_dtypeis_unsigned_integer_dtypecaseg      ?Zxxxmethod)intersectionunion
differencesymmetric_differencec                 C   sH   d}t jt|d" t| |||d W d    n1 s:0    Y  d S )Nz!Input must be Index or array-likematchsort)pytestraises	TypeErrorgetattr)idxr
   r   r   msg r   _/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/tests/indexes/multi/test_setops.pytest_set_ops_error_cases   s    r   klassc                 C   s   | dd d }| d d }|t ur,||j}|j||d}|d u rL| }n|}t|| d}tjt|d" |jg d|d W d    n1 s0    Y  d S )N      r   .other must be a MultiIndex or a list of tuplesr      r      )	r   valuesr   sort_valuestmassert_index_equalr   r   r   )r   r   r   firstsecondZ	intersectexpectedr   r   r   r   test_intersection_base   s    

r,   c                 C   s   | d d d }| d d }|t ur,||j}|j||d}|d u rL| }n|}t|| d}tjt|d" |jg d|d W d    n1 s0    Y  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   r   r   r   test_union_base3   s    

r-   c                    s   | dd   | d d }| j  |d}|d u r6| }||sDJ t||  fddtjttfD }|D ]}| j ||d}t|| qnd}t	j
t|d" | j g d|d W d    n1 s0    Y  d S )N   r   c                    s   g | ]}| j qS r   r%   .0r   r*   r   r   
<listcomp>T       z(test_difference_base.<locals>.<listcomp>r!   r   r"   )r   r&   equalsr'   r(   nparrayr   listr   r   r   )r   r   answerresultcasesr
   r   r   r2   r   test_difference_baseH   s    r<   c                    s   | dd  }| d d  | ddg }|j  |d}|d u rB| }t||  fddtjttfD }|D ]}|j ||d}t|| qld}tj	t
|d" |j g d	|d W d    n1 s0    Y  d S )
Nr#   r   r   r   c                    s   g | ]}| j qS r   r/   r0   r2   r   r   r3   j   r4   z-test_symmetric_difference.<locals>.<listcomp>r!   r   r"   )r   r&   r'   r(   r6   r7   r   r8   r   r   r   )r   r   r)   r9   r:   r;   r
   r   r   r2   r   test_symmetric_difference^   s    r=   c                  C   sj   t jddgddggddgd} | | }|j| jks8J |  ddg}| |}|jd d gksfJ d S )NabABnames)r   from_productr   rC   copyrename)r   r:   idx2r   r   r   $test_multiindex_symmetric_differencet   s    

rH   c                 C   s    | j r
J | d d j sJ d S )Nr   )emptyr   r   r   r   
test_empty   s    
rK   c                 C   sv  | }|j | dd  |d}| d d j}|d u r8t|}tj|d| jd}t|tsXJ ||sfJ |j| jksvJ t	|| | j | |d}| d d }||sJ |j| jksJ | dd  j | |d}| d d }||sJ |j| jksJ | d d j | |d}| d d }||s,J |j| jks>J | dd  }ddg|_|j ||d}|jdksrJ | j | 
dd |d}t|dksJ |j |j|d}||d d sJ |j g |d}||sJ |j|jksJ |j d	g|d}tg d
}|j|_|j|jks,J d}tjt|d" |j g d|d W d    n1 sh0    Y  d S )Nr   r   )Z	sortorderrC   foobazNNr#   rM   one))barrQ   )rN   two)rM   rS   )quxrQ   )rT   rS   r!   r   )r#   r   r$   r.   r    )r   r%   sortedr   from_tuplesrC   
isinstancer5   r'   r(   Z	sortlevellenr   r   r   )r   r   r)   r:   valsr+   Zchunkletr   r   r   r   test_difference   sT    
rZ   c                  C   s0   t ddgddgg} | g }t||  d S )Nr#   r   r>   r?   r   rD   r   r'   r(   r   r:   r   r   r   test_difference_sort_special   s    
r]   c                  C   sJ   t ddgddgg} | jg dd}t ddgddgg}t|| d S Nr#   r   r>   r?   Tr   r[   )r   r:   r+   r   r   r   !test_difference_sort_special_true   s    r_   c                  C   s   t dtddgddgg} t dtddgdd	gg}d
}tjt|d | |}W d    n1 sn0    Y  t||  | j|dd}t||  d S )Nr#   2000r   r>   r?   r$   r.   cdz0sort order is undefined for incomparable objectsr   Fr   )	r   rD   pd	Timestampr'   assert_produces_warningRuntimeWarningr   r(   )r   otherr   r:   r   r   r   !test_difference_sort_incomparable   s    (rh   c                  C   s   t dtddgddgg} t dtddgdd	gg}d
}tjt|d | j|dd W d    n1 sr0    Y  d S )Nr#   r`   r   r>   r?   r$   r.   ra   rb   zH'values' is not ordered, please explicitly specify the categories order r   Tr   )r   rD   rc   rd   r   r   r   r   )r   rg   r   r   r   r   &test_difference_sort_incomparable_true   s
    ri   c                 C   s   | d d d d d }| dd  }|j ||d}|dv rNt| |   nt||  | j | |d}t||  | j | d d |d}t||  | j}| d d j |dd  |d}|d u rt| |   n|| sJ d S )Nr    r   r$   r   )NFr   r.   )r   r'   r(   r&   r%   r5   )r   r   piece1piece2Z	the_uniontuplesr:   r   r   r   
test_union   s    rm   c                 C   s   t g d}|| }d|v s"J d|v s.J |rltjtdd | | W d    q1 s`0    Y  nJd}tjt|d | |}W d    n1 s0    Y  ||rJ d S )N)r@   rA   CrP   rA   zCan only unionr   z'The values in the array are unorderable)	r   r   r   r   NotImplementedErrorr'   re   rf   r5   )r   Zusing_infer_stringrg   r:   r   Zresult2r   r   r   test_union_with_regular_index
  s    
*(rp   c           	      C   s   | d d d d d }| dd  }|j ||d}|dv rNt|| dd  nt| | dd  | j | |d}t||  | d d j | dd  |d}| d d }||sJ | j}|  |}|| sJ d S )Nr    r   r$   r   )NTr   r   )r   r'   r(   r&   r5   r%   )	r   r   rj   rk   Zthe_intrI   r+   rl   r:   r   r   r   test_intersection  s    
rq   c                 C   s   |   d}d g| j }t| |||d}t| || |d|}t|| t| ||d d |d}t| || d d |d|}t|| d S )Ncategoryr   r    )Zto_flat_indexastypenlevelsr   rF   r'   r(   )r   r   r   rg   Z	res_namesr:   r+   r   r   r   test_setop_with_categorical6  s     ru   c                 C   s   t tddd}| j||d}t| jg g| j d d}tj||dd | jt	|d d |d}t| jg g| j | j
d}tj||dd d	}tjt|d
$ | jt	||d W d    n1 s0    Y  d S )Nr$   rM   )namer   levelscodesrC   T)exactr   r!   r   )r   ranger   r   rx   rt   r'   r(   r6   ZasarrayrC   r   r   r   )r   r   rg   r:   r+   r   r   r   r   test_intersection_non_objectF  s    r|   c                  C   sF   t ddgddgg} t| j| dd|  t| j| d d|  d S Nr#   r   r>   r?   Fr   )r   rD   r'   r(   r   rJ   r   r   r   test_intersect_equal_sortX  s    r~   c                  C   sJ   t ddgddgg} t ddgddgg}| j| dd}t|| d S r^   )r   rD   r   r'   r(   )r   r+   r:   r   r   r   test_intersect_equal_sort_true_  s    r   slice_c                 C   s\   t ddgddgg}||  }t||| t||| t|j|dd| d S r}   )r   rD   r'   r(   r   )r   r   rg   r   r   r   test_union_sort_other_emptyf  s
    r   c                  C   sV   t ddgddgg} | d d }| j|dd}t ddgddgg}t|| d S r^   )r   rD   r   r'   r(   )r   rg   r:   r+   r   r   r    test_union_sort_other_empty_sortt  s
    r   c                  C   s   t dtdgddgg} tt" | | d d }W d    n1 sN0    Y  t||  | j| d d dd}t||  d S )Nr#   r`   r>   r?   Fr   )	r   rD   rc   rd   r'   re   rf   r   r(   r\   r   r   r   "test_union_sort_other_incomparable|  s    0r   c                  C   sh   t dtdgddgg} d}tjt|d& | j| d d dd W d    n1 sZ0    Y  d S )	Nr#   r`   r>   r?   z<'<' not supported between instances of 'Timestamp' and 'int'r   Tr   )r   rD   rc   rd   r   r   r   r   )r   r   r   r   r   'test_union_sort_other_incomparable_sort  s    r   c                  C   s`   t ddgddgg} | jd }d}tjt|d | | W d    n1 sR0    Y  d S )Nr>   r?   r#   r   z<Can only union MultiIndex with MultiIndex or Index of tuplesr   )r   rD   rx   r   r   ro   r   )mir   r   r   r   r   "test_union_non_object_dtype_raises  s
    
r   c                  C   sZ   t g g} t jddgddggddgd}| |}t ddgddgg}t|| d S )Nr#   r   r$   r.   r>   r?   rB   r   from_arraysr   r'   r(   )r   mi2r:   r+   r   r   r   %test_union_empty_self_different_names  s
    
r   c                  C   s`   t jddgddggddgd} td}| |}tj| |d	d
 || }tj| |d	d
 d S )Nr#   r   r$   r.   r>   r?   rB   r   F)Zcheck_names)r   r   rc   Z
RangeIndexr   r'   r(   )r   riZresult_leftZresult_rightr   r   r   &test_union_multiindex_empty_rangeindex  s    


r   )r   r   r   r   c                 C   s   t ddgddgg}t ddgddgg}tjtdd" t|| |dd W d    n1 sb0    Y  t|| |d	d d S )
Nr>   r?   r#   r   ra   zThe 'sort' keyword only takesr   r   T)r   rD   r   r   
ValueErrorr   )r   Zidx1rG   r   r   r   test_setops_sort_validation  s
    0r   vald   c                 C   s   t jtddg| dddggdd gd}t tdd|g| dg dg}||}t tdg| ddgg}t|| ||jdd}t jtg | dtg tjdgdd gd}t|| d S )	Nr#   r   dtyper>   rB   r#   r#   r$   F)Z	ascending)	r   r   r   r   r'   r(   r&   r6   int64any_numeric_ea_dtyper   midxmidx2r:   r+   r   r   r   test_difference_keep_ea_dtypes  s    
r   r    c                 C   s   t jtddg| dddggdd gd}t tdd|g| dg dg}||}t tdd|g| dg dg}t|| d S )Nr#   r   r   r>   rB   r   r"   )r   r   r   r   r'   r(   r   r   r   r   *test_symmetric_difference_keeping_ea_dtype  s    
r   )rl   
exp_tuplesZval1Ztest1Zval2Ztest2c                 C   sT   t j| ddgd}t jg dddgd}||}t j|ddgd}t|| d S )Nr)   r*   rB   )r   r   r   )r   rV   r   r'   r(   )rl   r   leftrightr:   r+   r   r   r   test_intersect_with_duplicates  s    
r   zdata, names, expectedr#   r>   r?   )r#   r   ra   rb   r"   )r>   r?   ra   c                 C   s<   t jg ddgd}t j| g|d}||}||ks8J d S )Nr>   r?   rB   )r   rV   Z_maybe_match_names)datarC   r+   r   r   r:   r   r   r   test_maybe_match_names  s    
r   c                  C   st   t jddgddggddgd} t jddgddggddgd}| |}t jddgddggd dgd}t|| d S )	Nr#   r   r$   r.   ra   r?   rB   r>   r   r   r   r'   r(   )mi1r   r:   r+   r   r   r   'test_intersection_equal_different_names  s
    
r   c                  C   sF   t jdgdggddgd} t dgdgg}| |}t|| d S )Nr#   r$   ra   r?   rB   r   )r   r   r:   r   r   r   !test_intersection_different_names  s    
r   c                 C   sb   t d| d| gg dg}t d| dgg dg}||}t d| gddgg}t|| d S )Nr$   r.   )r#   r   r.   r   r#   r   r.   r#   r   r   Znulls_fixturer   r   r:   r+   r   r   r   3test_intersection_with_missing_values_on_both_sides$  s
    
r   c                 C   sN   t d| gg}t d| dgg}||}t dd| gg}t|| d S )Nr#   r$   r   r   r   r   r   ,test_union_with_missing_values_on_both_sides-  s
    
r   r   Zfloat64ZFloat64r   Fc                 C   s   t tjdtjg| dddgg}t tjdtjdg| dg dg}|j||d}|d u rt tjddtjg| dg dg}n|}t|| d S )	N      ?r   r   r$   g      @)r   r$   r.   r   )r   r.   r$   )	r   r   rc   r7   r6   nanr   r'   r(   )r   r   r   r   r:   r+   r   r   r   test_union_nan_got_duplicated6  s    "$r   r.   r#   c                 C   s   t |dg| d}t ddg| d}tj|ddggdd gd}t|ddgg}||}|dkr~tt g d| dg dg}ntt ddg| dddgg}t|| d S )	Nr   r   r#   r>   rB   r.   r   )r#   r   r#   r   r   r   r   r'   r(   )r   r   arr1arr2r   r   r:   r+   r   r   r   test_union_keep_ea_dtypeF  s    
r   dupe_valr$   c                 C   s   t td| dg|dtd| dg|dg}t td| | g|dtd| | g|dg}||}t tdd| | g|dtdd| | g|dg}t|| d S )Nr#   r   r   )r   r   r   r   r'   r(   )r   r   r   r   r:   r+   r   r   r   (test_union_with_duplicates_keep_ea_dtypeZ  s"    
r   z3ignore:PeriodDtype\[B\] is deprecated:FutureWarningc                 C   s"  | j st| ttfr*tdt| j  |  j	
 }t|dgt| g}t|d g| dgt|d  g}||}| }t|| t|jd r|ddk  r||jd tj|jd g}n0t|jd r||jd t|jd g}||}t|| d S )NzNo duplicates in an empty r#   r   l            )rI   rW   r   r   r   skiptype__name__uniquer%   tolistr   r   rX   r   r&   r'   r(   r	   rx   Zget_level_valuesallZ
set_levelsrs   r6   r   r   float)indexrequestr%   r   r   r:   r+   r   r   r   test_union_duplicatess  s*    &

r   c                 C   s   t g d| d}t ddg| d}tj|g dgdd gd}tj|ddggdd gd}||}tjt g d	| dg d
gdd gd}t|| d S )N)r.   r#   r#   r   r#   r.   )r   r#   r#   r>   rB   r   )r#   r#   r.   )r#   r#   r   r   )Zany_real_numeric_dtyper   r   r   r   r:   r+   r   r   r   test_union_keep_dtype_precision  s    
r   c                 C   s   t dtjg| d}t dtjg| d}tj|ddggdd gd}t|ddgg}||}tt ddtjtjg| dg dg}t|| d S )Nr.   r   r#   r   r>   rB   )r#   r   r#   r   )r   rc   NAr   r   r   r'   r(   )r   r   r   r   r   r:   r+   r   r   r    test_union_keep_ea_dtype_with_na  s    
r   z'levels1, levels2, codes1, codes2, names )ra   rb   r?   )r   r#   r   )r#   r#   r#   )r   r   r   Zname1Zname2c                 C   s8   t | ||d}t |||d}||}|jdks4J d S )Nrw   r   )r   r   Z_lexsort_depth)Zlevels1Zlevels2Zcodes1Zcodes2rC   r   r   Zmi_intr   r   r   test_intersection_lexsort_depth  s    
r   )
categoriesT)r   orderedc           
      C   s   ddg}t | |d}t ||d}tj| |gddgd}t|t|ddg}t|t|}t|ddgt|}t|ddgt|ddg}	t|| t|| t|| t|	| d S )N12)xyr   r   rB   )r   r   r   Z
from_framer   r&   r'   r(   )
r>   r?   rg   Zdf1Zdf2r+   Zres1Zres2Zres3Zres4r   r   r   0test_intersection_with_non_lex_sorted_categories  s$    
r   c                 C   sz   t jtddg|dddggdd gd}t tdd| g|dg dg}||}t tdg|ddgg}t|| d S )Nr#   r   r   r>   rB   r   )r   r   r   r   r'   r(   )r   r   r   r   r:   r+   r   r   r    test_intersection_keep_ea_dtypes  s    
r   c               	   C   sz   t dtt d gddt d gddgd} t dtdd}t| |g}ttjtjfddgd	tjd
gi}t|| d S )Nr   stringr   )r   )
      )rO   r>   r?   r   g      $@r   g      4@)	r   r   r   rV   r   r6   r   r'   Zassert_frame_equal)Zseries1Zseries2r:   r+   r   r   r   .test_union_with_na_when_constructing_dataframe  s    "r   )Gnumpyr6   r   Zpandasrc   r   r   r   r   r   r   Zpandas._testingZ_testingr'   Zpandas.api.typesr   r	   markZparametrizer   r7   r8   r,   Zarm_slowr-   r<   r=   rH   rK   rZ   r]   r_   rh   ri   rm   rp   rq   ru   r|   r~   r   slicer   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   filterwarningsr   r   r   r   ZCategoricalr   r   r   r   r   r   r   <module>   s    
A

	






		



"

