B
    `y                 @   s   d dl Zd dlmZ d dlZd dlm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mZ ejZG dd dZdddZdd Zdd Zdd ZdddZdS )    N)randn)join)	DataFrameIndex
MultiIndexSeriesconcatmerge)NGROUPSNget_test_datac            
   @   sl  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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/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-dSdT Z.dUdV Z/d S )W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randomr   r   dfr
   df2tmZgetMixedTypeDicttargetsource)selfmethodr   data r%   S/home/dcms/DCMS/lib/python3.7/site-packages/pandas/tests/reshape/merge/test_join.pysetup_method   s    
zTestJoin.setup_methodc       
      C   s  t dddddddddddgtjd}t dddddddgtjd}d}t|||\}}|jdd	}|jdd	}t ddddddddddddd
d
ddddddg}t ddddddddddddddddddddg}	||}d||dk< ||	}d||	dk< tj||dd tj||dd d S )Nr   r   r      )dtype   r   	mergesort)kind         	   
   F)check_dtype)	a_r   int64libjoinleft_outer_joinargsorttaker   assert_numpy_array_equal)
r"   leftright	max_grouplsrsexp_lsexp_rsexp_liexp_rir%   r%   r&   test_cython_left_outer_join.   s    $00

z$TestJoin.test_cython_left_outer_joinc       
      C   s  t dddddddddddgtjd}t dddddddgtjd}d}t|||\}}|jdd	}|jdd	}t ddddddddddddd
ddd
dddg}t ddddddddddddddddddd
g}	||}d||dk< ||	}d||	dk< tj||dd tj||dd d S )Nr   r   r   r(   )r)   r*   r   r+   )r,   r-   r.   r/   r2   F)r3   )	r4   r   r5   r6   r7   r8   r9   r   r:   )
r"   r;   r<   r=   r?   r>   r@   rA   rB   rC   r%   r%   r&   test_cython_right_outer_joinD   sB    $.

z%TestJoin.test_cython_right_outer_joinc       
      C   s  t dddddddddddgtjd}t ddddddddgtjd}d}t|||\}}|jdd	}|jdd	}t ddddddddddddd
d
ddddg}t ddddddddddddddddddg}	||}d||dk< ||	}d||	dk< tj||dd tj||dd d S )Nr   r   r   r(   )r)   r*   r   r+   )r,   r-   r.   r/   r2   F)r3   )	r4   r   r5   r6   Z
inner_joinr8   r9   r   r:   )
r"   r;   r<   r=   r>   r?   r@   rA   rB   rC   r%   r%   r&   test_cython_inner_joinr   s    $,,

zTestJoin.test_cython_inner_joinc             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   )onr;   )howr   )r	   r   r   _check_join)r"   joined_key2joined_bothr%   r%   r&   test_left_outer_join   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   r<   )rG   rH   )rH   r   )r	   r   r   rI   )r"   rJ   rK   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   outer)rG   rH   )rH   r   )r	   r   r   rI   )r"   rJ   rK   r%   r%   r&   test_full_outer_join   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   inner)rG   rH   )rH   r   )r	   r   r   rI   )r"   rJ   rK   r%   r%   r&   test_inner_join   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)rG   suffixeszkey1.foozkey1.bar)r	   r   r   AssertionError)r"   joinedr%   r%   r&   test_handle_overlap   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   )z.fooz.bar)left_onright_onrR   zkey1.foozkey2.bar)r	   r   r   rS   )r"   rT   r%   r%   r&   !test_handle_overlap_arbitrary_key   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 d Q R X | }d|d< d}t
jt|d |j|dd W d Q R X d S )Nr   )rG   r   r   F)Zcheck_namesr   r   keyabcr   r   r   r   )r   )rY   r   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!   r   r   assert_series_equalr   assert_frame_equalr   isnanrS   pytestraisesKeyErrorcopy
ValueError)r"   r    r!   mergedr   r   rT   expectedZdf_aZdf_bZdf_cZsource_copymsgr%   r%   r&   test_join_on   s2     "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 d Q R X d S )Nmfr(   )size)rZ   r[   r1   r   )r   zFlen\(left_on\) must equal the number of levels in the index of "right")rc   rZ   T)rV   right_index)r   r   r   choicer   r   makeCustomIndexrh   ri   rl   r	   )r"   r   r   ro   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 d Q R X d S )Nrq   rr   r(   )rs   )rZ   r[   r   )r   r1   zFlen\(right_on\) must equal the number of levels in the index of "left")rc   r[   T)rW   
left_index)r   r   r   ru   r   r   rv   rh   ri   rl   r	   )r"   r   r   ro   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 d Q R X d S )Nrq   rr   r(   )rs   )rZ   r[   r1   r   )r   z)len\(right_on\) must equal len\(left_on\))rc   rZ   r[   )rW   rV   )r   r   r   ru   r   r   rv   rh   ri   rl   r	   )r"   r   r   ro   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 d Q R X tjt|d t||ddd W d Q R X d S )NrZ   r   z.Can only merge Series or DataFrame objects, a z was passed)rc   )rV   rW   )r   typerh   ri   	TypeErrorr	   )r"   r{   r   ro   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   )rG   )r    r   r!   popr   rf   )r"   rn   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}x.| jD ]$}||ks0t||   s tq W | j j| jg ddd}t|j	|j	 t
|dkstd S )Nr   )rG   rP   )rG   rH   r   )r    r   r!   reindexrS   isnaallr   assert_index_equalr^   len)r"   rm   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 )NrY   rZ   dr[   r\   r   r   r   )r   rP   )rG   rH   )rG   F)r3   )r   r   notnar   re   r   r   )r"   r   r   rT   rn   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 )NrY   rZ   r[   r\   r   r   r   r   )r   )rG   )r   r   r   rf   )r"   r   r   rT   rn   r%   r%   r&   test_join_on_singlekey_list1  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   )rG   )r    r   r!   r   rf   )r"   r   rn   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 )	NrZ   r   r   r[   )r   name)rG   )rZ   r[   )r   )r   r   r   r   r   rf   )r"   r   Zdsr   rn   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 )Nr1   )r   Tboolr_   stringr      r   intg      ?float)rH   )r   r   aranger   _join_by_handr   rf   )r"   	join_typedf1r   rT   rn   r%   r%   r&   test_join_index_mixedH  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 )Ng      ?r   r_   T)r   Br   r   r1   r   r   r   r   )r   r^   r   Z_oneZ_two)lsuffixrsuffixZA_oneZB_oneZC_oneZD_oneZA_twoZB_twoZC_twoZD_twor*   )r   r   r   r)   r5   rS   Zbool_r   r^   r   r   rf   )r"   r   r   rT   Zexpected_columnsrn   r%   r%   r&   test_join_index_mixed_overlapZ  s.    
z&TestJoin.test_join_index_mixed_overlapc             C   s(   t  }|jt dgdgdgddd d S )Nr(   r   r   )r   r^   rN   )rH   )r   r   )r"   xr%   r%   r&   test_join_empty_bugz  s    zTestJoin.test_join_empty_bugc             C   sV   t tddddgd}ttd}||d< t tdddgd}|| || d S )	N   r   rZ   r[   )r^   r\   r   q)r   r   r   r   )r"   rZ   r\   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 )NrZ   r[   r   r   r(   firstsecond)namesr\   r-   zvar X)r$   r   r^   zvar Yr   )levelrN   )rH   )r   Zfrom_arraysr   r   r   r   
sort_indexr   r   valuesunionr   r   r   r   rf   rS   )r"   Zindex1index2r   r   rT   Zex_indexrn   r%   r%   r&   test_join_multiindex  s0    

zTestJoin.test_join_multiindexc       	      C   sl  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ddddgdddggd
d
d
dddddddg
d
ddd
dddd
ddg
gddg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 )Nr`   r_   bazZquxZsnapra   r]   rb   )r   r   r$   r   r   r   r(   r   r   )levelscodesr   r1   Zj_oneZj_twoZj_three)r   r^   r   r   rP   )rG   rH   F)rV   rW   rH   sortT)rW   rx   rH   r   )axis)r   r   r   r   r   r   r   r	   reset_indexr   rf   Zreindex_likeZdropr   Zis_monotonicrS   )	r"   r   r   r$   r   Zto_joinrT   rn   Z	expected2r%   r%   r&   test_join_inner_multiindex  s\    .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
 tt	 t
||d	d	d}W d Q R X d|kstd|kstd S )N)r   r   r(   )r*   r   r-   rZ   r[   r\   )r^   )r.   r1   r-   r   T)Zinplace)rx   rt   )r[   mean)r   groupbyZaggr   r   sum	set_indexr   Zassert_produces_warningUserWarningr	   rS   )r"   r   Znew_dfZother_dfr   r%   r%   r&   test_join_hierarchical_mixed  s    z%TestJoin.test_join_hierarchical_mixedc       
      C   sh  t tddddgtjd}t tdddgtjd}||}|jd dksNt|jd dks`t|jd d	ksrt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s4t|jd d	ksHt|j|ddd}	t||	 d S )Nr1   r   rZ   r[   )r^   r)   r   r\   float64float32r   r   d   r5   )rZ   r[   r\   Zmd)r^   T)rV   rt   )r   r   r   r   r   r   ZdtypesrS   r   randintastyper	   r   rf   )
r"   rZ   r[   rT   r\   r   Zxpdfsr?   Z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   r1      )rZ   r[   r\   r   r      )rZ   r[   r   i  i  )rZ   r[   erZ   r[   rN   )rH   )rG   rH   r5   r   i,  i  rP   r_   r`   r]   ra   rb   r/   )r   r   r   r   ZTEST)r   r   r;   r<   )r   r   r   r	   r   r^   rZ   r   r[   r   rf   locr   r   r   r   repeatr   )r"   r   r   df3Zidf1Zidf2Zidf3r   Zdf_partially_mergedrn   r   r   rP   rN   r;   r<   r%   r%   r&   test_join_many_non_unique_index  sN    
"""
(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ttt	d d S )Nr_   r`   r   r   r   r(   r*   )rY   r   value2rZ   r[   r\   )r   rY   T)rG   r   )rY   r   r   r   F)
r   r   r   rf   r   r   pdr   listrange)r"   r;   r<   rT   rn   r%   r%   r&   test_join_sortG  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 )NrZ   r   r   r(   r*   )r   r[   r   r-   r.   r/   )rZ   r[   )r   r   r   nanr   rf   )r"   r   r   r   rn   r   Zdf4r%   r%   r&    test_join_mixed_non_unique_indexZ  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pnum)r   r^   rP   Z_df2)rH   r   )r)   r   r2   r   Zpnum_df2)r^   r   )r   Zperiod_ranger   r   r   r   r   r   r   Ztiler   r5   r   reshaper   r   r   rf   )r"   r   r   r   r   rn   r%   r%   r&   !test_join_non_unique_period_indexm  s    $z*TestJoin.test_join_non_unique_period_indexc             C   sj   t tjddddddddgd	}|d
dd
 |ddd |d}| }| }|j|dd d S )Nr   r-   rZ   r[   r\   r   r   rr   )r^   r   idr   dtr_   Z_right)r   )	r   r   r   r   insertr   r   countr   )r"   r   ZgroupedmnZcnr%   r%   r&    test_mixed_type_join_with_suffixz  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 d Q R X d S )Nr1   r-   Zabcdef)r^   rZ   r[   r\   r   r   rr   r   r   r   r0   c                s8    fdd| D }|d  |dd  }t|| d S )Nc                s   g | ]}|  qS r%   )r   ).0r   )	exp_indexr%   r&   
<listcomp>  s    zFTestJoin.test_join_many.<locals>._check_diff_index.<locals>.<listcomp>r   r   )r   r   rf   )df_listr   r   Z	reindexedrn   r%   )r   r&   _check_diff_index  s    z2TestJoin.test_join_many.<locals>._check_diff_indexrN   )rH   rP   r/   z?Joining multiple DataFrames only supported for joining on index)rc   )rG   )r   r   r   r   r   r   r   rf   r   rh   ri   rl   )r"   r   r   rT   r   ro   r%   r%   r&   test_join_many  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^   r_   r`   rY   )r   r   r   r   r   r   r   rf   )r"   r   r   r   r   r   r%   r%   r&   test_join_many_mixed  s    zTestJoin.test_join_many_mixedc       	      C   sN  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}|j|ddd}t ||||gdd}ddddddddg|_t	
|| d S )Nr1   r*   r   r   )r^   r   r   )rs   r   r   r   )r   Z_2)r   r   yT)rx   rt   rN   )rx   rt   rH   Zx_xZy_xZx_yZy_y)r   r   r   r   r   r   r   r   r^   r   rf   r	   )	r"   r   rn   r   wr   r   zZdtar%   r%   r&   test_join_dups  s&    $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 d Q R X tjt|d |j|ddg|d W d Q R X d S )NabcZxyr   r   num)r   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.   )rG   rH   zFlen\(left_on\) must equal the number of levels in the index of "right")rc   )r   Zfrom_productr   r   r   r   r   r	   r   r   rf   rh   ri   rl   )	r"   r   Z	leftindexr;   Z
rightindexr<   r   rn   ro   r%   r%   r&   test_join_multi_to_multi  s     " 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 j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   )rG   r   Ztuv)r)   r   )r   r   Z
date_ranger   r   r   rk   r   r   r   objectr   rf   )r"   r   r   r   rn   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Lr1   Jr   z
2013-04-06r      r   r   rZ   )r^   r   r   r   r*   )r^   r   )rG   z2012-08-02 00:00:00z2013-04-06 00:00:00)r   r^   )r   r   to_datetimer   r   	Timestampr   rf   )r"   ZdfaZdfbr   rn   r%   r%   r&   test_join_datetime_string   s&    
z"TestJoin.test_join_datetime_string)0__name__
__module____qualname__r'   rD   rE   rF   rL   rM   rO   rQ   rU   rX   rp   rw   ry   rz   rh   markZparametrizer   arrayr   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      sP   .((
 #@6
 r   r;   _x_yc             C   s:  x |D ]}||    stqW | |}||}	x||D ]\}
}t|| j|}t||j|}y||
}W nJ tk
r } z,|dkrtd|
 d|t|| j| W d d }~X Y nX t	|| y|	|
}W nN tk
r& } z.|dkrtd|
 d|t||j| W d d }~X Y qBX t	|| qBW d S )N)r;   rP   zkey z! should not have been in the join)r<   rP   )
r   r   rS   r   _restrict_to_columnsr^   Z	get_grouprj   _assert_all_na_assert_same_contents)r;   r<   r   r   rH   r   r   r\   Zleft_groupedZright_groupedZ	group_keygroupZl_joinedZr_joinedZlgrouperrZrgroupr%   r%   r&   rI     s2    


 

 rI   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   r\   )r^   suffixr%   r&   r   F  s    z(_restrict_to_columns.<locals>.<listcomp>c                s   |   dS )Nr  )r  )r   )r  r%   r&   <lambda>M      z&_restrict_to_columns.<locals>.<lambda>)r^   )r^   r   rename)r  r^   r  foundr%   )r^   r  r&   r  D  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 )N)r  )r   r  )rowsr%   r&   	<genexpr>]  s    z(_assert_same_contents.<locals>.<genexpr>)ZfillnaZdrop_duplicatesr   r   rS   r   )
join_chunkr!   ZNA_SENTINELZjvaluesZsvaluesr%   )r  r&   r  U  s    r  c             C   s0   x*|D ]"}||krq| |    stqW d S )N)r   r   rS   )r  Zsource_columnsr   r\   r%   r%   r&   r  `  s    
r  c       	      C   s^   | j j|j |d}| |}||}| j|j}x| D ]\}}|||< q>W |j|dS )N)rH   )r^   )r   r   r   r^   appenditems)	rZ   r[   rH   Z
join_indexZa_reZb_reZresult_columnsr   r   r%   r%   r&   r   g  s    

r   )r;   r   r   )r;   )numpyr   Znumpy.randomr   rh   Zpandas._libsr   r6   Zpandasr   r   r   r   r   r   r	   Zpandas._testingZ_testingr   Z%pandas.tests.reshape.merge.test_merger
   r   r   r   r4   r   rI   r  r  r  r   r%   r%   r%   r&   <module>   s(          
&