o
    թZh                     @   s  d dl Z d dlZd dlZd dlm  mZ d dlZ	d dlm
Z
mZmZmZmZmZmZmZmZmZ d dlmZ d=ddZG dd dZd>ddZdd Zdd Zdd Zd?d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g d$fd%d&gg d'fd(d)gg d*fed+ed,ged+ed,ed,gfgd-d. Z#ej d/g d0d1d2 Z$d3d4 Z%ej d5d6g d7fd8g d7fd	g d7fd9g d:fgd;d< Z&dS )@    N)
Categorical	DataFrameIndex
MultiIndexSeries	Timestampbdate_rangeconcatmergeoption_context   2   c                 C   sf   t t| }tt|||  }t||k r(tt ||d |t|   }tjd| |S )N   )	listrangenpZasarraytilelenrandomdefault_rngshuffle)ngroupsnZunique_groupsZarr r   [/var/www/html/lang_env/lib/python3.10/site-packages/pandas/tests/reshape/merge/test_join.pyget_test_data   s   "r   c                
   @   s  e Zd Zejdd Zejdd Zej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ejdeddg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d0d1 Zd2d3 Zd4d5 Z d6d7 Z!d8d9 Z"d:d; Z#d<d= Z$d>d? Z%d@dA Z&dBdC Z'dDdE Z(ejddejdeddgdFdG Z)dHdI Z*dJdK Z+dLdM Z,dNdO Z-dPdQ Z.dRdS Z/dTdU Z0dVdW Z1dXdY Z2dZd[ Z3d#S )\TestJoinc                 C   sF   t t t tjddtjddd}||d dk }|S )Nr   r   )key1key2Zdata1Zdata2r      r   r   r   r   r   standard_normal)selfdfr   r   r   r#   %   s   
zTestJoin.dfc                 C   s,   t tddtdddtjdddS )N
   )r      )r   r   r   )r   r   valuer    )r"   r   r   r   df24   s   
zTestJoin.df2c                 C   s`   g dg dg dt dddd}t|tg dtd	d
}t|d |d d|d d
}||fS )N)              ?g       @g      @g      @)r(   r)   r(   r)   r(   )Zfoo1Zfoo2Zfoo3Zfoo4Zfoo5z1/1/2009   )periodsABCD)abcdedtypeindexr-   r0   )MergedAMergedDr/   )r   r   r   object)r"   datatargetsourcer   r   r   target_source>   s   
zTestJoin.target_sourcec                 C   sF   t ||dd}t|||dgdd t ||}t|||ddgdd d S )Nr   onlefthowr   r
   _check_joinr"   r#   r'   Zjoined_key2Zjoined_bothr   r   r   test_left_outer_joinO   s   
zTestJoin.test_left_outer_joinc                 C   L   t ||ddd}t|||dgdd t ||dd}t|||ddgdd d S )Nr   rightrB   rE   rD   r   rF   rH   r   r   r   test_right_outer_joinV      zTestJoin.test_right_outer_joinc                 C   rJ   )Nr   outerrL   rD   r   rF   rH   r   r   r   test_full_outer_join]   rN   zTestJoin.test_full_outer_joinc                 C   rJ   )Nr   innerrL   rD   r   rF   rH   r   r   r   test_inner_joind   rN   zTestJoin.test_inner_joinc                 C   s,   t ||ddd}d|v sJ d|v sJ d S )Nr   z.fooz.bar)rB   suffixeskey1.foozkey1.barr
   r"   r#   r'   joinedr   r   r   test_handle_overlapk   s   zTestJoin.test_handle_overlapc                 C   s.   t ||dddd}d|v sJ d|v sJ d S )Nr   r   rS   )left_onright_onrT   rU   zkey2.barrV   rW   r   r   r   !test_handle_overlap_arbitrary_keyq   s   z*TestJoin.test_handle_overlap_arbitrary_keyinfer_stringFTZpyarrow)Zmarksc                 C   s  |\}}|j |dd}tj|d |d dd tj|d |d dd td	g d
i}tdg dig dd}|j |d	d}tg d
g dd}	t||	 tdgdgdggg d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 sJ t|d d sJ tjt	dd |j |dd W d    n1 sw   Y  |
 }d}tjt|d |j |dd W d    d S 1 sw   Y  d S )Nr/   rA   r:   r-   F)Zcheck_namesr;   r0   keyr1   r1   r2   r2   r3   r&   r   r   r   r1   r2   r3   r8   )r   r   r   r   r   r^   r&   r   r      oner9   columnsfoobartwothreer3   z^'E'$matchEzyYou are trying to merge on float64 and object|string columns for key 'A'. If you wish to proceed you should use pd.concat)jointmassert_series_equalr   assert_frame_equalr   isnanpytestraisesKeyErrorcopy
ValueError)r"   r@   r]   r>   r?   mergedr#   r'   rX   expectedZdf_aZdf_bZdf_cZsource_copymsgr   r   r   test_join_on|   s6    "zTestJoin.test_join_onc                 C   s   t tjdjddgddtjddd}t tjdjddgddtjdddttdd	d
ggd}d}t	j
t|d t||ddd W d    d S 1 sZw   Y  d S )Nr   mfrc   sizer1   r2   r$   r*   r-   r.   r8   Flen\(left_on\) must equal the number of levels in the index of "right"rk   r1   TrZ   right_indexr   r   r   r   choicer!   r   from_productr   rs   rt   rw   r
   r"   r#   r'   rz   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djddgddtjdddttdt	dgd}t tjdjddgd	dtjdd	d}d
}t
jt|d t||ddd W d    d S 1 sZw   Y  d S )Nr   r|   r}   rc   r~   r   abcr8   r$   zFlen\(right_on\) must equal the number of levels in the index of "left"rk   r2   T)r[   
left_index)r   r   r   r   r   r!   r   from_arraysr   r   rs   rt   rw   r
   r   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djddgddtjddd}t tjdjddgddtjdddttdd	d
ggd}d}t	j
t|d t||dddgd W d    d S 1 s\w   Y  d S )Nr   r|   r}   rc   r~   r   r$   r*   r-   r.   r8   z)len\(right_on\) must equal len\(left_on\)rk   r1   r2   )r[   rZ   r   r   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   s   t dddgi}dt| d}tjt|d t||ddd W d    n1 s*w   Y  tjt|d t||ddd W d    d S 1 sJw   Y  d S )Nr1   r   z.Can only merge Series or DataFrame objects, a z was passedrk   )rZ   r[   )r   typers   rt   	TypeErrorr
   )r"   r   r#   rz   r   r   r   )test_join_on_fails_with_wrong_object_type   s   "z2TestJoin.test_join_on_fails_with_wrong_object_typec                 C   sZ   |\}}|j |dd}|jddid}|g d }|d}|j ||d}t|| d S )Nr/   rA   key_0rf   )r   r-   r.   r0   r:   r;   )rn   renamepopro   rq   )r"   r@   r>   r?   ry   join_colresultr   r   r   test_join_on_pass_vector   s   
z!TestJoin.test_join_on_pass_vectorc                 C   s   |\}}|j |g dd}|D ]}||v sJ ||   s"J q|j |g ddd}t|j|j t|dks>J d S )Nr/   rA   rQ   rL   r   )rn   reindexisnaallro   assert_index_equalrf   r   )r"   r@   r>   r?   rx   colZmerged2r   r   r   test_join_with_len0   s   zTestJoin.test_join_with_len0c                 C   s   t dg d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 )Nr^   )r1   r1   r4   r2   r2   r3   r&   r   r   r1   r2   r8   rQ   rL   rA   F)Zcheck_dtype)r   rn   notnaro   rp   r   r9   r"   r#   r'   rX   ry   r   r   r   test_join_on_inner  s   zTestJoin.test_join_on_innerc                 C   sV   t dg di}t dg dig dd}|j|dgd}|j|dd}t|| d S )Nr^   r_   r&   r`   ra   r8   rA   r   rn   ro   rq   r   r   r   r   test_join_on_singlekey_list  s
   z$TestJoin.test_join_on_singlekey_listc                 C   s>   |\}}|j |d dd}|j |dg dd}t|| d S )Nr:   r/   rA   rn   ro   rq   )r"   r@   r>   r?   r   ry   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 )	Nr1   r   r   r2   r9   namerA   r   r8   )r   r   rn   r9   ro   rq   )r"   r#   Zdsr   ry   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 )Nr$   r8   Tboolrg   stringr*      r   intr)   floatrD   )r   r   arangern   _join_by_handro   rq   )r"   	join_typedf1r'   rX   ry   r   r   r   test_join_index_mixed&  s   zTestJoin.test_join_index_mixedc                 C   s   t dddddtdg dd}|d jtjksJ |d	 jtjks%J t dddddtd
ddg dd}|j|ddd}g d}|d d |_|dd  |_t||}t	
|| d S )Nr)   r   rg   Tr,   r$   re   r.   r0   r   Z_oneZ_twolsuffixrsuffix)ZA_oneZB_oneZC_oneZD_oneZA_twoZB_twoZC_twoZD_twor%   )r   r   r   r7   int64Zbool_rn   rf   r   ro   rq   )r"   r   r'   rX   Zexpected_columnsry   r   r   r   test_join_index_mixed_overlap8  s$   

z&TestJoin.test_join_index_mixed_overlapc                 C   s(   t  }|jt dgdgdgddd d S )Nrc   r   r-   re   rO   rD   )r   rn   )r"   xr   r   r   test_join_empty_bugX  s   "zTestJoin.test_join_empty_bugc                 C   sp   t tjddddgd}ttjdd}||d< t tjddd	gd}|| || d S )
Nr   )   r   r1   r2   r   r   r3   )r   r   q)r   r   r   r   r!   r   rn   )r"   r1   r3   r4   r   r   r   test_join_unconsolidated]  s   
z!TestJoin.test_join_unconsolidatedc                 C   sx  t jg dg dgddgd}t jg dg dgddgd}ttjdd|d	gd
}ttjdd|dgd
}|jdd}|jdd}|j|dd}t	|j
t	|j
}||||}|j|j_t|| |jj|jksyJ |jdd}|jdd}|j|ddjdd}t	|j
t	|j
}||||}|j|j_t|| |jj|jksJ d S )N)r1   r1   r1   r2   r2   r2   )r   r   rc   r   r   rc   firstsecondnames)r2   r2   r2   r3   r3   r3   r      zvar X)r=   r9   rf   zvar Yr   )levelrO   rD   r   )r   r   r   r   r   r   r!   
sort_indexrn   r   valuesunionr   r   r9   ro   rq   )r"   Zindex1index2r   r'   rX   Zex_indexry   r   r   r   test_join_multiindexj  sD   

zTestJoin.test_join_multiindexc           
      C   s  g d}g d}t jdt|}t|||d}|}tt jdd|g d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{J t	
|| d S )N)
rh   rh   rh   rg   rg   bazr   quxr   Zsnap)
ri   rd   rj   rd   ri   rd   ri   ri   rj   rd   r   )r   r   r=   )r$   rc   )Zj_oneZj_twoZj_threere   r   r   rQ   rL   r   r   F)rZ   r[   rE   sortT)r[   r   rE   r   r   Zaxis)r   r   r   r!   r   r   rn   r
   reset_indexro   rq   Zreindex_likeZdropr9   Zis_monotonic_increasing)
r"   Z%lexsorted_two_level_string_multiindexr   r   r=   r9   Zto_joinrX   ry   Z	expected2r   r   r   test_join_inner_multiindex  sP   		z#TestJoin.test_join_inner_multiindexc                 C   s   t ddgg dd}|dgdddgi}t dd	gg d
d}|jddd tjtjjdd t	||ddd W d    d S 1 sEw   Y  d S )N)r   r   rc   )r%   r*   r   ra   r   r1   r2   meansum)   r$   r   r1   r2   r4   T)Zinplacez-Not allowed to merge between different levelsrk   r   r   )
r   groupbyZagg	set_indexrs   rt   pderrors
MergeErrorr
   )r"   r#   Znew_dfZother_dfr   r   r   #test_join_hierarchical_mixed_raises  s   "z,TestJoin.test_join_hierarchical_mixed_raisesc           
      C   s  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s/J |jd dks8J |jd d	ksAJ tjd	d
dd
d}tjdd
d}tjdd
d	}t |||d}t |||d}t tjdd
d	dgd}|j|ddd}|jd dksJ |jd dksJ |jd d	ksJ |jd d	ksJ |j|ddd}	t||	 d S )Nr   )r$   r   r1   r2   rf   r7   )r$   r   r3   float64float32r   r*   d   r   ra   mdr   Tr   )r   r   r   r   r!   r   r   rn   Zdtypesintegersastyper
   ro   rq   )
r"   r1   r2   rX   r3   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 g dg dg dd}t g dg dg dd}t g dg dg d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 g dg dtjddtjd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   r$      ra   r   r      r       )r1   r2   r5   r1   r2   rO   rD   rL   r   )r   r   r   )r$   r   r   )r   r   r   )r   r   i,  )r   r   i  rQ   )rg   rh   rg   rh   rg   rh   rg   rg   )rd   rd   ri   rj   ri   ri   rd   rj   r   r,   TESTr   rC   rK   )r   r   rn   r
   r   rf   r1   r   r2   ro   rq   locr   r   r   r!   r   repeatr   )r"   r   r'   df3Zidf1Zidf2Zidf3r   Zdf_partially_mergedry   r#   r   rQ   rO   rC   rK   r   r   r   test_join_many_non_unique_index  sT   
"z(TestJoin.test_join_many_non_unique_indexc                 C   s   t d|U tg dg dd}tdg dig dd}|j|d	d
d}tg dg dg ddg dd}t|| |j|d	dd}tj|jttdd
d W d    d S 1 s]w   Y  d S )Nzfuture.infer_string)rg   rh   r   rg   r   r   rc   r%   rb   value2ra   )rh   r   rg   r8   r^   T)rB   r   )rh   r   rg   rg   )r   rc   r   r%   )r1   r2   r3   r3   )r^   r&   r   )r   r   r   rc   Fr%   )exact)	r   r   rn   ro   rq   r   r9   r   r   )r"   r]   rC   rK   rX   ry   r   r   r   test_join_sort7  s"   "zTestJoin.test_join_sortc                 C   s   t dg dig dd}t dg dig dd}||}t g dd	tjd
dtjgdg dd}t|| t dg dig dd}t dg dig dd}||}t g dd	d
d
tjgdg dd}t|| d S )Nr1   r   )r   r   rc   r1   r8   r2   )r*   r   r   r   )r   rc   rc   r%   )r   r   rc   rc   r%   r*   r   r   r   )r   r   rc   rc   r1   )r   r   r   r1   )r   rn   r   nanro   rq   )r"   r   r'   r   ry   r   Zdf4r   r   r    test_join_mixed_non_unique_indexP  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)r+   freqZpnumre   rQ   Z_df2)rE   r   r6   r   r   Zpnum_df2rf   r9   )r   Zperiod_ranger   r   r   r   r	   rn   r   r   r   r   r   reshaper   r9   ro   rq   )r"   r9   r#   r'   r   ry   r   r   r   !test_join_non_unique_period_indexc  s   $z*TestJoin.test_join_non_unique_period_indexc                 C   s   t tjddg dd}|ddd |ddd	 |d}td
}t	j
t|d |  W d    n1 s=w   Y  |jdd}| }|j|dd d S )Nr   )r   r   )r1   r2   r3   r4   r5   r}   r   r   idr*   dtrg   z&agg function failed [how->mean,dtype->rk   T)Znumeric_only_rightr   )r   r   r   r   r!   insertr   reescapers   rt   r   r   countrn   )r"   r#   groupedrz   ZmnZcnr   r   r    test_mixed_type_join_with_suffixp  s   


z)TestJoin.test_mixed_type_join_with_suffixc                 C   sv  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    d S 1 sw   Y  d S )Nr   )r$   r   Zabcdefr   r1   r2   r3   r4   r5   r}   r   r   	   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   )df_listr   r  Z	reindexedry   r   r  r   _check_diff_index  s   z2TestJoin.test_join_many.<locals>._check_diff_indexrO   rD   rQ   r   z?Joining multiple DataFrames only supported for joining on indexrk   rA   )r   r   r   r   r!   r   rn   ro   rq   r9   rs   rt   rw   )r"   r#   r
  rX   r  rz   r   r   r   test_join_many  s$   ":"zTestJoin.test_join_manyc                 C   s   t tjddg d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   rg   rh   r%   r^   r-   r.   r/   r0   )	r   r   r   r   r!   r   rn   ro   rq   )r"   r#   r   r'   r   r   r   r   r   test_join_many_mixed  s   zTestJoin.test_join_many_mixedc           	      C   sb  t ttjddg ddttjd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jtjjdd |j|ddd W d    d S 1 sw   Y  d S )Nr   )r$   r%   )r-   r-   r.   r.   r   r   r$   r   r~   r-   r/   r   r   Z_2r   )r%   r   r   yTr   rO   )r   r   rE   z0Passing 'suffixes' which cause duplicate columnsrk   )r	   r   r   r   r   r!   r   r   rn   rf   ro   rq   r
   rs   rt   r   r   r   )	r"   r#   ry   r   wr   r  zZdtar   r   r   test_join_dups  sJ   
"zTestJoin.test_join_dupsc           	      C   sF  t jtdtdddggg d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g d}t	
|| d}tjt|d |j|d|d W d    n1 szw   Y  tjt|d |j|ddg|d W d    d S 1 sw   Y  d S )Nr   xyr   r   )r   r  numr   v1   r8   v2c                 S   s   g | ]}d | qS )r   r   )r  ir   r   r   r	        z5TestJoin.test_join_multi_to_multi.<locals>.<listcomp>r   rL   r   rk   )r   r   r   r   r   rn   r   r
   r   ro   rq   rs   rt   rw   )	r"   r   Z	leftindexrC   Z
rightindexrK   r   ry   rz   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tj	g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  rA   r   Ztuvr  )r   r   Z
date_ranger   rn   r   rv   r   r   r   ro   rq   )r"   r   r'   r   ry   r   r   r   #test_join_on_tz_aware_datetimeindex  s$   	z,TestJoin.test_join_on_tz_aware_datetimeindexc                 C   s   t g dg dg dg dgg dd}t|d d|d< t g d	g d
gg dddgd}t|d 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g dd}|d d|d< t|| d S )N)
2012-08-02Lr$   )r   Jr   )
2013-04-06r!  r   )r#  r"     )r   r  r1   r   r   zM8[ns])r   r"  r   )r#  r!  r   )r   r  r  r   r%   r   r  rA   z2012-08-02 00:00:00r"  r   r   z2013-04-06 00:00:00r!  r   )r   r  r  r1   re   )	r   r   to_datetimer   rn   r   r   ro   rq   )r"   ZdfaZdfbr   ry   r   r   r   test_join_datetime_string  s2   	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 )Nr1   r2   
categoriesc1r8   c2)r)  r*  )r   ZCategoricalIndexreversedr   rn   ro   rq   )r"   ZixZid1Zid2r   r'   r   ry   r   r   r    test_join_with_categorical_index,  s   
z)TestJoin.test_join_with_categorical_index)4__name__
__module____qualname__rs   Zfixturer#   r'   r@   rI   rM   rP   rR   rY   r\   markparametrizeparamtdZ
skip_if_nor{   r   r   r   r   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   r   #   sf    

	

&


 +>!6
-r   rC   _x_yc                 C   s2  |D ]}||    sJ q| |}||}	||D ]x\}
}t|| j|}t||j|}z||
}W n& ty] } z|dv rLtd|
 d|t|| j| W Y d }~n
d }~ww t	|| z|	|
}W n& ty } z|dv rtd|
 d|t||j| W Y d }~qd }~ww t	|| qd S )N)rC   rQ   zkey z! should not have been in the join)rK   rQ   )
r   r   r   _restrict_to_columnsrf   Z	get_groupru   AssertionError_assert_all_na_assert_same_contents)rC   rK   r   r   rE   r   r   r3   Zleft_groupedZright_groupedZ	group_keygroupZl_joinedZr_joinedZlgrouperrZrgroupr   r   r   rG   <  sD   




rG   c                    sR    fdd| j D }| jd d |f } | jfddd} | jd d  f } | S )Nc                    s(   g | ]}| v s| d  v r|qS ) replace)r  r3   rf   suffixr   r   r	  b  s    "z(_restrict_to_columns.<locals>.<listcomp>c                    s   |   dS )Nr=  r>  )r   )rA  r   r   <lambda>j  s    z&_restrict_to_columns.<locals>.<lambda>r   )rf   r   r   )r;  rf   rA  foundr   r@  r   r7  a  s   r7  c                    sd   d}|  | j}| | j}dd |D  t t|ks#J t fdd|D s0J d S )Niy)c                 S   s   h | ]}t |qS r   tupler  rowr   r   r   	<setcomp>x  r  z(_assert_same_contents.<locals>.<setcomp>c                 3   s    | ]	}t | v V  qd S NrD  rF  rowsr   r   	<genexpr>z  s    z(_assert_same_contents.<locals>.<genexpr>)ZfillnaZdrop_duplicatesr   r   r   )
join_chunkr?   ZNA_SENTINELZjvaluesZsvaluesr   rJ  r   r:  r  s   r:  c                 C   s,   |D ]}||v r	q| |    sJ qd S rI  )r   r   )rM  Zsource_columnsr   r3   r   r   r   r9  }  s
   r9  c           	      C   sZ   | j j|j |d}| |}||}| j|j}| D ]\}}|||< q|j|dS )NrD   r   )r9   rn   r   rf   appenditems)	r1   r2   rE   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 )Nr5   r*   )r   r   r%   r   r   r=   r9   r}   r   )r   rc   )r2   r3   rQ   rD   )r5   r}   )r   r   r%   rc   )r1   r2   r4   r3   r8   r   r   from_tuplesrn   ro   rq   )rC   rK   r   ry   r   r   r   .test_join_inner_multiindex_deterministic_order  s   rS  )	input_coloutput_colsr2   r1   a_xZa_yc                 C   sb   t dddgi}t | ddgi}|j|dddd}t |d	 g d
|d g di}t|| d S )Nr1   r   rc   r%   crossr5  r6  )rE   r   r   r   )r   r   rc   rc   )rc   r%   rc   r%   r   )rT  rU  rC   rK   r   ry   r   r   r   test_join_cross  s
    rX  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}| dkr;t dgdgdtjdgddgdd}nt dgdgdtjdgddgdd}t|| d S )Nr3   rc   )r   r   r   r   rP  r4   r%   )r   )r2   rD   rK   )r3   r4   )r   r   r2   r1   r8   rQ  )r   rC   rK   r   ry   r   r   r   test_join_multiindex_one_level  s   rY  zcategories, valuesYX)rZ  r[  r[  r   r   )r   r   r         @      ?)r\  r]  r]  z
2020-12-31z
2019-12-31c                 C   s   t ddgt| | dddgdddg}t g dt|| dg d	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-   r-   r.   )rc   r%   r*   _leftr   r   rc   r%   )r   r   Z
value_leftZvalue_rightr   r   r   rn   ro   rq   )r(  r   rC   rK   r   ry   r   r   r   1test_join_multiindex_not_alphabetical_categorical  s6   





r`  zleft_empty, how, exp)
)FrC   rC   )FrK   empty)FrQ   ra  )FrO   rC   )FrW  ra  )TrC   ra  )TrK   rK   )TrQ   ra  )TrO   rK   )TrW  ra  c                 C   s  t ddgddgdddd}t dgd	gd
ddd}| r&|d}n|d}|j||d}|dkrLt ddgddgtjtjgd}|d}n+|dkrbt tjgdgd	gd}|d}n|dkrwt ddgdd}|dkrw|d}|dkr| }t	|| d S )Nr   r   rc   r%   )r-   r.   r   r6   r-   r*   )r-   r/   r   rD   rC   )r-   r.   r/   rK   )r.   r-   r/   ra  r.   r/   r   rW  rO   )
r   r   headrn   r   r   Zrename_axisr   ro   rq   )Z
left_emptyrE   exprC   rK   r   ry   r   r   r   test_join_empty  s&    
 
rd  c                  C   s   t  } t dgd}t ddgd}| | }t dgd}t|| || }t g dd}t|| | | }t ddgd}t|| d S )Ntestr   rg   rh   r   )rf  rg   re  )r   ro   rq   )r   r'   r   r   ry   r   r   r   $test_join_empty_uncomparable_columns  s   rg  zhow, valuesrQ   r`   rO   rK   r   r   r   c                 C   s   t tg dtg dg ddddg}t tg dtg dg ddddg}t t|t|||dddg}|j|| d}t|| d S )	Nr`   ra   r1   r2   rh  r   )r1   r2   r3   r4   rD   r_  )rE   r   r   r'   ry   r   r   r   r   3test_join_multiindex_categorical_output_index_dtype(  s6   






	ri  )r   r   )rC   r5  r6  )rC   )'r   numpyr   rs   Zpandas.util._test_decoratorsutilZ_test_decoratorsr3  Zpandasr   r   r   r   r   r   r   r   r	   r
   r   Zpandas._testingZ_testingro   r   r   rG   r7  r:  r9  r   rS  r0  r1  rX  rY  r`  rd  rg  ri  r   r   r   r   <module>   sh    0
      
%

	





	