U
    sVc                     @   sl  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
mZmZ d dlmZ d dlmZmZmZ G dd dZd6d	d
Zdd Zdd Zdd Zd7ddZdd Zejddddgfdddgfgdd Zdd Zejddd gdd d gfd!d"gd!d"d"gfd#d$gd#d$d$gfe
d%e
d&ge
d%e
d&e
d&gfgd'd( Zejd)d*d+d,d-d.d/d0d1d2d3g
d4d5 Z dS )8    N)Categorical	DataFrameIndex
MultiIndexSeries	Timestampconcatmerge)NGROUPSNget_test_datac                
   @   s\  e Z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dddeddg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/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Z d9d: Z!d;d< Z"d=d> Z#d?d@ Z$dAdB Z%dCdD Z&dEdF Z'dGdH Z(dIdJ Z)dKdL Z*dMdN Z+dOdP Z,dQdR Z-dS )STestJoinc                 C   s   t t t tjttjtd| _| j| jd dk | _t ttd dttd td dtjtd d| _t	
 \}}t ||d	| _t |d
 |d d|d d	| _d S )N)key1key2Zdata1Zdata2r         )n   )Zngroupsr   )r   r   valueindexAD)MergedAMergedDC)r   r   nprandomrandnr   dfr
   df2tmZgetMixedTypeDicttargetsource)selfr   data r&   H/tmp/pip-unpacked-wheel-xj8nt62q/pandas/tests/reshape/merge/test_join.pysetup_method   s(    


 zTestJoin.setup_methodc                 C   sV   t | j| jdd}t| j| j|dgdd t | j| j}t| j| j|ddgdd d S )Nr   onlefthowr   r	   r   r    _check_joinr$   Zjoined_key2Zjoined_bothr&   r&   r'   test_left_outer_join6   s    zTestJoin.test_left_outer_joinc                 C   s\   t | j| jddd}t| j| j|dgdd t | j| jdd}t| j| j|ddgdd d S )Nr   rightr*   r-   r,   r   r.   r0   r&   r&   r'   test_right_outer_join=   s    zTestJoin.test_right_outer_joinc                 C   s\   t | j| jddd}t| j| j|dgdd t | j| jdd}t| j| j|ddgdd d S )Nr   outerr3   r,   r   r.   r0   r&   r&   r'   test_full_outer_joinD   s    zTestJoin.test_full_outer_joinc                 C   s\   t | j| jddd}t| j| j|dgdd t | j| jdd}t| j| j|ddgdd d S )Nr   innerr3   r,   r   r.   r0   r&   r&   r'   test_inner_joinK   s    zTestJoin.test_inner_joinc                 C   s0   t | j| jddd}d|ks td|ks,td S )Nr   z.fooz.bar)r*   suffixeskey1.foozkey1.barr	   r   r    AssertionErrorr$   joinedr&   r&   r'   test_handle_overlapR   s    zTestJoin.test_handle_overlapc                 C   s2   t | j| jdddd}d|ks"td|ks.td S )Nr   r   r9   )left_onright_onr:   r;   zkey2.barr<   r>   r&   r&   r'   !test_handle_overlap_arbitrary_keyX   s    z*TestJoin.test_handle_overlap_arbitrary_keyc              	   C   s  | j }| j}|j|dd}tj|d |d dd tj|d |d dd td	d
d
dddgi}tddddgid
ddgd}|j|d	d}td
d
dddgdddddgd}t|| tdgdgdggd
ddgdgd}tdgdggddgdgd}	tdgdggddgdgd}
|j|	dd}|j|
dd}t|d d sFt	t|d d s^t	t
jtdd |j|dd W 5 Q R X | }d|d< d}t
jt|d |j|dd W 5 Q R X d S )Nr   r)   r   r   F)Zcheck_namesr   r   keyabcr   r   r   r   r   rD   r      oner   columnsfoobartwothreez^'E'$matchEzfYou are trying to merge on float64 and object columns. If you wish to proceed you should use pd.concat)r"   r#   joinr!   assert_series_equalr   assert_frame_equalr   isnanr=   pytestraisesKeyErrorcopy
ValueError)r$   r"   r#   mergedr   r    r?   expectedZdf_aZdf_bZdf_cZsource_copymsgr&   r&   r'   test_join_onc   s6    "zTestJoin.test_join_onc              	   C   s   t tjjddgddtjdd}t tjjddgddtjddtddd}d	}tjt	|d
 t
||ddd W 5 Q R X d S )NmfrI   sizerE   rF   
   r   r   Flen\(left_on\) must equal the number of levels in the index of "right"rQ   rE   TrA   right_indexr   r   r   choicer   r!   ZmakeCustomIndexrX   rY   r\   r	   r$   r   r    r_   r&   r&   r'   -test_join_on_fails_with_different_right_index   s      
z6TestJoin.test_join_on_fails_with_different_right_indexc              	   C   s   t tjjddgddtjddtddd}t tjjddgddtjdd}d	}tjt	|d
 t
||ddd W 5 Q R X d S )Nra   rb   rI   rc   re   r   r   rf   zFlen\(right_on\) must equal the number of levels in the index of "left"rQ   rF   T)rB   
left_indexrj   rl   r&   r&   r'   ,test_join_on_fails_with_different_left_index   s     
 z5TestJoin.test_join_on_fails_with_different_left_indexc              	   C   s   t tjjddgddtjdd}t tjjddgddtjddtddd}d	}tjt	|d
 t
||dddgd W 5 Q R X d S )Nra   rb   rI   rc   re   rf   r   r   z)len\(right_on\) must equal len\(left_on\)rQ   rE   rF   )rB   rA   rj   rl   r&   r&   r'   /test_join_on_fails_with_different_column_counts   s      
z8TestJoin.test_join_on_fails_with_different_column_counts
wrong_typer   strNr   r   c              	   C   sx   t dddgi}dt| d}tjt|d t||ddd W 5 Q R X tjt|d t||ddd W 5 Q R X d S )NrE   r   z.Can only merge Series or DataFrame objects, a z was passedrQ   )rA   rB   )r   typerX   rY   	TypeErrorr	   )r$   rq   r   r_   r&   r&   r'   )test_join_on_fails_with_wrong_object_type   s    z2TestJoin.test_join_on_fails_with_wrong_object_typec                 C   sF   | j j| jdd}|d= | j d}| j j| j|d}t|| d S )Nr   r)   )r"   rT   r#   popr!   rV   )r$   r^   join_colresultr&   r&   r'   test_join_on_pass_vector   s
    z!TestJoin.test_join_on_pass_vectorc                 C   s   | j j| jg dd}| jD ]$}||ks.t||   stq| j j| jg ddd}t|j	|j	 t
|dks~td S )Nr   r)   r7   r3   r   )r"   rT   r#   reindexr=   isnaallr!   assert_index_equalrL   len)r$   r]   colZmerged2r&   r&   r'   test_join_with_len0   s    
zTestJoin.test_join_with_len0c                 C   s   t dddddddgi}t dddgiddgd	}|j|dd
d}|j|dd}||d   }t|d |d  tj|d |d dd t|j|j d S )NrD   rE   drF   rG   r   r   r   r   r7   r3   r)   F)Zcheck_dtype)r   rT   notnar!   rU   r}   r   r$   r   r    r?   r^   r&   r&   r'   test_join_on_inner   s    zTestJoin.test_join_on_innerc                 C   s`   t ddddddgi}t ddddgidddgd	}|j|dgd
}|j|dd
}t|| d S )NrD   rE   rF   rG   r   r   r   r   r   r)   r   rT   r!   rV   r   r&   r&   r'   test_join_on_singlekey_list   s
    z$TestJoin.test_join_on_singlekey_listc                 C   s>   | j j| jd dd}| j j| jdg dd}t|| d S )Nr   r   r)   )r"   rT   r#   r!   rV   )r$   rx   r^   r&   r&   r'   test_join_on_series   s    zTestJoin.test_join_on_seriesc                 C   s\   t dddgi}tdgdgdd}|j|dd}t ddgddgd|jd}t|| d S )	NrE   r   r   rF   r   namer)   re   r   )r   r   rT   r   r!   rV   )r$   r   Zdsrx   r^   r&   r&   r'   test_join_on_series_buglet   s
    z#TestJoin.test_join_on_series_bugletc                 C   s   t tdd}d|d< d|d< t tddd}d	|d
< d|d< |j||d}t|||d}t|| |j||d}t|||d}t|| d S )Nrf   r   TboolrM   stringr      r   int      ?floatr,   )r   r   arangerT   _join_by_handr!   rV   )r$   	join_typedf1r    r?   r^   r&   r&   r'   test_join_index_mixed   s    zTestJoin.test_join_index_mixedc                 C   s   t dddddtdddd	d
gd}|d jtjks:t|d
 jtjksNtt dddddtdddddd	d
gd}|j|ddd}ddddddddg}|d d |_|dd  |_t	||}t
|| d S )Nr   r   rM   Tr   Br   r   rf   r   r   r   r   rK   r   Z_oneZ_twolsuffixrsuffixZA_oneZB_oneZC_oneZD_oneZA_twoZB_twoZC_twoZD_two   )r   r   r   dtypeint64r=   Zbool_rT   rL   r   r!   rV   )r$   r   r    r?   Zexpected_columnsr^   r&   r&   r'   test_join_index_mixed_overlap  s4    



z&TestJoin.test_join_index_mixed_overlapc                 C   s(   t  }|jt dgdgdgddd d S )NrI   r   r   rK   r5   r,   )r   rT   )r$   xr&   r&   r'   test_join_empty_bug(  s    zTestJoin.test_join_empty_bugc                 C   sb   t tjddddgd}ttjd}||d< t tjdddgd}|| || d S )	N   r   rE   rF   rL   rG   r   q)r   r   r   r   r   rT   )r$   rE   rG   r   r&   r&   r'   test_join_unconsolidated-  s    
z!TestJoin.test_join_unconsolidatedc                 C   s  t jddddddgddddddggddgd}t jdddd	d	d	gddddddggddgd}ttjd
|dgd}ttjd
|dgd}|jdd}|jdd}|j|dd}t|j	
t|j	}||||}|j|j_t|| |jj|jkst|jdd}|jdd}|j|ddjdd}t|j	
t|j	}||||}|j|j_t|| |jj|jkstd S )NrE   rF   r   r   rI   firstsecondnamesrG      zvar X)r%   r   rL   zvar Yr   )levelr5   r,   )r   Zfrom_arraysr   r   r   r   
sort_indexrT   r   valuesunionrz   r   r   r!   rV   r=   )r$   Zindex1index2r   r    r?   Zex_indexr^   r&   r&   r'   test_join_multiindex8  s4    

zTestJoin.test_join_multiindexc           
   
   C   s   ddddddddddg
}ddddddddddg
}t jt|}t|||d	}|}tt jd
d|dddgd}|j|ddgdd}t|| ddgddgddd}t||ddgdddd}	t	||	
| t||ddgdddd}	|jddgdd}|j|_|jjstt	|| d S )NrN   rM   bazZquxZsnaprO   rJ   rP   )r   r   r%   rf   rI   Zj_oneZj_twoZj_threerK   r   r   r7   r3   r   r   F)rA   rB   r-   sortT)rB   rn   r-   r   r   Zaxis)r   r   r   r~   r   rT   r	   reset_indexr!   rV   Zreindex_likeZdropr   Zis_monotonic_increasingr=   )
r$   Z%lexsorted_two_level_string_multiindexr   r   r%   r   Zto_joinr?   r^   Z	expected2r&   r&   r'   test_join_inner_multiindex[  sd      		z#TestJoin.test_join_inner_multiindexc              	   C   s   t ddgdddgd}|dgdtjtjgi}t ddgdddgd}|jdd	d
 d}tjt	|d t
||d	d	d}W 5 Q R X d|kstd|kstd S )N)r   r   rI   )r   r   r   rE   rF   rG   r   )   rf   r   r   T)Zinplacez.merging between different levels is deprecatedrQ   rn   ri   )rF   mean)r   groupbyZaggr   r   sum	set_indexr!   assert_produces_warningFutureWarningr	   r=   )r$   r   Znew_dfZother_dfr_   rx   r&   r&   r'   test_join_hierarchical_mixed  s    z%TestJoin.test_join_hierarchical_mixedc           
      C   sp  t tjddddgtjd}t tjdddgtjd}||}|jd dksVt|jd dksht|jd d	kszttj	d
dd
d}tjd
d}tjd
d	}t |||d}t |||d}t tjd
d	dgd}|j|ddd}|jd dkst|jd dks(t|jd d	ks<t|jd d	ksPt|j|ddd}	t||	 d S )Nrf   r   rE   rF   )rL   r   r   rG   float64float32r   r   d   r   rE   rF   rG   Zmdr   Trh   )r   r   r   r   r   r   rT   Zdtypesr=   randintastyper	   r!   rV   )
r$   rE   rF   r?   rG   r   ZxpdfsrsZxpr&   r&   r'   test_join_float64_float32  s&    
z"TestJoin.test_join_float64_float32c              
   C   s  t ddgddgddgd}t ddgddgddgd}t ddgddgd	d
gd}|ddg}|ddg}|ddg}|j||gdd}t||ddgdd}t||ddgdd}	| }|	|j }	|	jd|	d< |	jd|	d< t	
||	 t dddgdddgdddgd}t dddgdddgdddgd}t dddgdddgd	d
dgd}|ddg}|ddg}|ddg}|j||gdd}t||ddgdd}t||ddgdd}	| }t	
||	jd d |jf  t ddddddddgddddddddgtjdtjdd}
tttddttdddd}|
j|dd}|
j|dd}|
j|dd}|
j|d d}t	
|| t	
|| t	
|| d S )!Nr   rf      r   r   r      rE   rF   r   i  i  )rE   rF   erE   rF   r5   r,   r3   r   r   i,  i  r7   rM   rN   rJ   rO   rP      r   ZTESTr   r+   r2   )r   r   rT   r	   r   rL   rE   r   rF   r!   rV   locr   r   r   r   repeatr   )r$   r   r    df3Zidf1Zidf2Zidf3rx   Zdf_partially_mergedr^   r   r   r7   r5   r+   r2   r&   r&   r'   test_join_many_non_unique_index  sX    
"""

  z(TestJoin.test_join_many_non_unique_indexc                 C   s   t ddddgddddgd}t d	d
ddgidddgd}|j|ddd}t ddddgddddgd
dddgdddddgd}t|| |j|ddd}tj|jttddd d S )NrM   rN   r   r   r   rI   r   rH   value2rE   rF   rG   r   rD   T)r*   r   )rD   r   r   r   F)exact)r   rT   r!   rV   r}   r   r   range)r$   r+   r2   r?   r^   r&   r&   r'   test_join_sort  s    



zTestJoin.test_join_sortc                 C   s  t dddddgiddddgd}t ddd	d
dgiddddgd}||}t dddddgdtjd	d
tjgddddddgd}t|| t dddddgiddddgd}t ddd	d
dgiddddgd}||}t ddddgdd	d	tjgdddddgd}t|| d S )NrE   r   r   rI   r   r   rF   r   r   r   r   re   )r   rT   r   nanr!   rV   )r$   r   r    rx   r^   r   Zdf4r&   r&   r'    test_join_mixed_non_unique_index  s       
   
 
z)TestJoin.test_join_mixed_non_unique_indexc                 C   s   t jdddd}tttt||dgd}t||g}|j|ddd	}tt	tj
dtjd
ddddddg| jd}t|| d S )Nz
2016-01-01   M)periodsfreqZpnumrK   r7   Z_df2)r-   r   r   r   r   Zpnum_df2rL   r   )pdZperiod_ranger   listr   r~   r   rT   r   Ztiler   r   r   reshaper   r   r!   rV   )r$   r   r   r    rx   r^   r&   r&   r'   !test_join_non_unique_period_index  s    $z*TestJoin.test_join_non_unique_period_indexc              	   C   s   t tjddddddddgd	}|d
dd
 |ddd |d}d}tjt|d |	 }W 5 Q R X |
 }|j|dd d S )Nr   r   rE   rF   rG   r   r   rb   r   r   idr   dtrM   z!The default value of numeric_onlyrQ   _rightr   )r   r   r   r   insertr   r!   r   r   r   countrT   )r$   r   Zgroupedr_   mnZcnr&   r&   r'    test_mixed_type_join_with_suffix%  s    "
z)TestJoin.test_mixed_type_join_with_suffixc              	   C   s\  t tjddtdd}|ddg |ddg |d	d
g g}|d |dd  }t|| |ddg d d |ddg dd  |d	d
g dd g}dd }|d j|dd  dd}||||j |d |dd  }||||d j |d j|dd  dd}||||jdd  d}t	j
t|d  |d j|dd  dd W 5 Q R X d S )Nrf   r   Zabcdefr   rE   rF   rG   r   r   rb   r   r   r   	   c                    s8    fdd| D }|d  |dd  }t|| d S )Nc                    s   g | ]}|  qS r&   )rz   ).0r   	exp_indexr&   r'   
<listcomp>>  s     zFTestJoin.test_join_many.<locals>._check_diff_index.<locals>.<listcomp>r   r   )rT   r!   rV   )df_listrx   r   Z	reindexedr^   r&   r   r'   _check_diff_index=  s    z2TestJoin.test_join_many.<locals>._check_diff_indexr5   r,   r7   r   z?Joining multiple DataFrames only supported for joining on indexrQ   r)   )r   r   r   r   r   rT   r!   rV   r   rX   rY   r\   )r$   r   r   r?   r   r_   r&   r&   r'   test_join_many4  s    ":zTestJoin.test_join_manyc                 C   s   t tjddddddgd}dd	gd |d
< |jd d ddgf }|jd d ddgf }|jd d d
gf }|||g}t|| d S )Nr   r   r   r   r   r   r   rM   rN   rD   )r   r   r   r   r   rT   r!   rV   )r$   r   r   r    r   rx   r&   r&   r'   test_join_many_mixedP  s    zTestJoin.test_join_many_mixedc           	   	   C   sd  t ttjddddddgdttjjdddddd	dd
gdgdd}t ||gdd}|j|dd}|j|_t	
|| ttjdd	ddgd}ttjdd	ddgd}ttjdd	ddgd}ttjdd	ddgd}|j|dddj|dddd}t	t |j|ddd}W 5 Q R X t ||||gdd}ddddddddg|_t	
|| d S )Nrf   r   r   r   r   r   r   rc   r   r   r   r   Z_2r   r   yTr   r5   )rn   ri   r-   Zx_xZy_xZx_yZy_y)r   r   r   r   r   r   r   rT   rL   r!   rV   r	   r   r   )	r$   r   r^   rx   wr   r   zZdtar&   r&   r'   test_join_dupsZ  s8     
   zTestJoin.test_join_dupsc           	   	   C   s   t jtdtdddggdddgd}tdtdi|d	}t jtdtdgddgd}td
dd tddD i|d	}|j|ddg|d}| j| ddg|ddddg}t	
|| d}tjt|d |j|d|d W 5 Q R X tjt|d |j|ddg|d W 5 Q R X d S )NabcZxyr   r   numr   Zv1   r   Zv2c                 S   s   g | ]}d | qS )r   r&   )r   ir&   r&   r'   r     s     z5TestJoin.test_join_multi_to_multi.<locals>.<listcomp>r   r3   rg   rQ   )r   Zfrom_productr   r   r   rT   r   r	   r   r!   rV   rX   rY   r\   )	r$   r   Z	leftindexr+   Z
rightindexr2   rx   r^   r_   r&   r&   r'   test_join_multi_to_multi{  s2         z!TestJoin.test_join_multi_to_multic                 C   s   t tjddddtdd}t tjddddtdd	}|j|d
d
d}| }ttj	gd td t
d|d< t|| d S )Nz
2018-01-01r   zAmerica/Chicago)startr   tzZabcde)datevalsz
2018-01-03Ztuvwx)r   vals_2r   r)   r   Ztuvr   r   )r   r   Z
date_ranger   rT   r   r[   r   r   r   objectr!   rV   )r$   r   r    rx   r^   r&   r&   r'   #test_join_on_tz_aware_datetimeindex  s,      	   z,TestJoin.test_join_on_tz_aware_datetimeindexc                 C   s   t dddgdddgdddgdddggd	d
dgd}t|d	 |d	< t dddgdddggd	d
dgddgd}t|d	 |d	< |j|d	d
gd	d
gd}t tddddgtddddggddgd	d
ddgd}t|| d S )Nz
2012-08-02Lrf   Jr   z
2013-04-06r      r   r   rE   r   r   r   r   r   r   r)   z2012-08-02 00:00:00z2013-04-06 00:00:00rK   )r   r   Zto_datetimerT   r   r   r!   rV   )r$   ZdfaZdfbrx   r^   r&   r&   r'   test_join_datetime_string  s0    	
z"TestJoin.test_join_datetime_stringc                 C   s   ddg}t j||d}t jt|t|d}td|i|d}tdt|i|d}||}tddgddgdt jddgddgdd}t|| d S )NrE   rF   
categoriesc1r   c2)r	  r
  )r   ZCategoricalIndexreversedr   rT   r!   rV   )r$   ixZid1Zid2r   r    rx   r^   r&   r&   r'    test_join_with_categorical_index  s    
z)TestJoin.test_join_with_categorical_index).__name__
__module____qualname__r(   r1   r4   r6   r8   r@   rC   r`   rm   ro   rp   rX   markparametrizer   arrayru   ry   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  r&   r&   r&   r'   r      sN   (

 #<6
!r   r+   _x_yc                 C   sF  |D ]}||    stq| |}||}	|t|dkrF|n|d D ]\}
}t|| j|}t||j|}z||
}W nJ tk
r } z,|dkrtd|
 d|t	|| j| W 5 d }~X Y nX t
|| z|	|
}W nN tk
r4 } z.|dkrtd|
 d|t	||j| W 5 d }~X Y qPX t
|| qPd S )Nr   r   )r+   r7   zkey z! should not have been in the join)r2   r7   )r   r|   r=   r   r~   _restrict_to_columnsrL   Z	get_grouprZ   _assert_all_na_assert_same_contents)r+   r2   rx   rw   r-   r   r   rG   Zleft_groupedZright_groupedZ	group_keygroupZl_joinedZr_joinedZlgrouperrZrgroupr&   r&   r'   r/     s>    


 


 r/   c                    sR    fdd| j D }| jd d |f } | jfddd} | jd d  f } | S )Nc                    s(   g | ] }| ks | d  kr|qS ) replace)r   rG   rL   suffixr&   r'   r     s      z(_restrict_to_columns.<locals>.<listcomp>c                    s   |   dS )Nr  r  )r   )r  r&   r'   <lambda>      z&_restrict_to_columns.<locals>.<lambda>r   )rL   r   rename)r  rL   r  foundr&   r  r'   r    s    r  c                    sd   d}|  | j}| | j}dd |D  t t|ksFtt fdd|D s`td S )Niy)c                 S   s   h | ]}t |qS r&   tupler   rowr&   r&   r'   	<setcomp>  s     z(_assert_same_contents.<locals>.<setcomp>c                 3   s   | ]}t | kV  qd S Nr$  r&  Zrowsr&   r'   	<genexpr>  s     z(_assert_same_contents.<locals>.<genexpr>)ZfillnaZdrop_duplicatesr   r~   r=   r|   )
join_chunkr#   ZNA_SENTINELZjvaluesZsvaluesr&   r*  r'   r    s    r  c                 C   s,   |D ]"}||krq| |    stqd S r)  )r{   r|   r=   )r,  Zsource_columnsrw   rG   r&   r&   r'   r    s    r  c           	      C   sZ   | j j|j |d}| |}||}| j|j}| D ]\}}|||< q<|j|dS )Nr,   r   )r   rT   rz   rL   appenditems)	rE   rF   r-   Z
join_indexZa_reZb_reZresult_columnsr   r   r&   r&   r'   r   &  s    


r   c                  C   sx   t dditjdgddd} t dditjd	gd
dd}| j|dd}t dgdgdtjdgddd}t|| d S )Nr   r   )r   r   r   r   r   r%   r   rb   r   )r   rI   )rF   rG   r7   r,   )r   rb   )r   r   r   rI   )rF   rE   r   rG   r   r   r   from_tuplesrT   r!   rV   )r+   r2   rx   r^   r&   r&   r'   .test_join_inner_multiindex_deterministic_order3  s     r2  )	input_coloutput_colsrF   rE   Za_xZa_yc                 C   sj   t dddgi}t | ddgi}|j|dddd}t |d	 ddddg|d ddddgi}t|| d S )
NrE   r   rI   r   crossr  r  )r-   r   r   r   r   )r3  r4  r+   r2   rx   r^   r&   r&   r'   test_join_crossD  s
    (r6  c                 C   s|   t dditjdgddd}t dditjd	gd
dd}|j|| d}t dgdgdtjdgddgdd}t|| d S )NrG   rI   )r   r   re   r   r/  r   r   )r   )rF   r,   )rG   r   )r   r   rF   rE   r   r0  )r   r+   r2   rx   r^   r&   r&   r'   test_join_multiindex_one_levelP  s     r7  zcategories, valuesYXr   r   g      @g      ?z
2020-12-31z
2019-12-31c                 C   s   t ddgt| | dddgdddg}t dddgt|| dd	d
dgdddg}|j|ddd}t ddgt| | dddgd	d
gdddg}t|| d S )Nr   r  r   r   )r   r   r   r   r   r   rI   r   r   _leftr   r   )r   r   Z
value_leftZvalue_right)r   r   r   rT   r!   rV   )r  r   r+   r2   rx   r^   r&   r&   r'   1test_join_multiindex_not_alphabetical_categorical^  s6    


r;  zleft_empty, how, exp)Fr+   r+   )Fr2   empty)Fr7   r<  )Fr5   r+   )Fr5  r<  )Tr+   r<  )Tr2   r2   )Tr7   r<  )Tr5   r2   )Tr5  r<  c                 C   s  t ddgddgdddd}t dgd	gd
ddd}| rL|d}n
|d}|j||d}|dkrt ddgddgtjtjgd}|d}n\|dkrt tjgdgd	gd}|d}n0|dkrt tg ddgdd}|dkr|d}t	|| d S )Nr   r   rI   r   )r   r   r   r   r   r   )r   r   r   r,   r+   )r   r   r   r2   )r   r   r   r<  r   r   )r   rL   r   r5  )
r   r   headrT   r   r   r   Zrename_axisr!   rV   )Z
left_emptyr-   expr+   r2   rx   r^   r&   r&   r'   test_join_empty  s"     
 
r?  )r+   r  r  )r+   )!Znumpyr   rX   Zpandasr   r   r   r   r   r   r   r   r	   Zpandas._testingZ_testingr!   Z%pandas.tests.reshape.merge.test_merger
   r   r   r   r/   r  r  r  r   r2  r  r  r6  r7  r;  r?  r&   r&   r&   r'   <module>   sb   (
     I
(
 
	
