U
    `»{j�  ã                   @   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&   úc/var/www/html/bwave/python/venv/lib/python3.8/site-packages/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�sŒt‚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s’t‚d|ksžt‚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   Ú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   Úgroupedr_   Z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Þ   Ú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$   Z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r®t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'  ©Ú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    þ ÿþr4  )Ú	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…   )r5  r6  r+   r2   rx   r^   r&   r&   r'   Útest_join_crossD  s
    (r8  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§   r1  r�   r›   )r   )rF   r,   )rG   r�   )r   r   rF   rE   r   r2  )r“   r+   r2   rx   r^   r&   r&   r'   Útest_join_multiindex_one_levelP  s     ÿþr9  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+   )Fr7  r>  )Tr+   r>  )Tr2   r2   )Tr7   r>  )Tr5   r2   )Tr7  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r˜t ddgddgtjtjgdœƒ}| d¡}n\|dkrÄt tjgdgd	gdœƒ}| d¡}n0|dkrôt 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œ   r7  )
r   rº   ÚheadrT   r   rÕ   r   Zrename_axisr!   rV   )Z
left_emptyr-   Úexpr+   r2   rx   r^   r&   r&   r'   Útest_join_empty‡  s"     
 
rA  )r+   r  r  )r+   )!Ú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’   r4  r  r  r8  r9  r=  rA  r&   r&   r&   r'   Ú<module>   sb   (
     I
(
 ÿ
	þüþ
öþ