U
    ÎZj=  ã                   @   sž  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	 d dl
mZ d dlmZ ejeddgddgddgddggdd gd	�eddgddgddgddggddgd	�eddgddgddgddggd
d
gd	�eddgddgddgddggdd gd	�eddgddgddgddggddgd	�eddgddgddgddggd
dgd	�eddgddgddgddggddgd	�eddgddgddgddggd dgd	�eddgddgddgddggddgd	�g	d�dd„ ƒZejdd„ ƒZejdd„ ƒZdd„ Zdd„ Zej dddg¡d d!„ ƒZej d"ddg¡d#d$„ ƒZej d%ed&ƒ¡d'd(„ ƒZd)d*„ Zd+d,„ Zd-d.„ Zej d/d0d1„ d2d1„ g¡d3d4„ ƒZej d/d5d1„ d6d1„ g¡d7d8„ ƒZG d9d:„ d:ƒZ dS );é    N)Ú	DataFrameÚIndexÚ
MultiIndexÚSeriesÚ
date_range)Ú	safe_sorté   é   é   é   é   ©ÚcolumnsÚCç      ð?g        ç       @g      @g      @g       @ÚX)Úparamsc                 C   s   | j S )zPairwise frames test_pairwise)Úparam)Úrequest© r   úd/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/pandas/tests/window/test_pairwise.pyÚpairwise_frames   s    r   c                   C   s(   t ddgddgddgddggddgd�S )z'Pairwise target frame for test_pairwiser   r	   r
   r   r   r   r   ©r   r   r   r   r   Úpairwise_target_frame#   s    r   c                   C   s2   t dddgdddgdddgdddggdddgd	�S )
z&Pairwise other frame for test_pairwiseNr
   r   é   r   ÚYÚZr   r   r   r   r   r   r   Úpairwise_other_frame)   s    "þr   c              	   C   s\   | }|t j t|ƒ¡ }|jddd� |¡}t |d t  |dd … |dd … ¡d ¡ d S )Né2   é   ©ÚwindowZmin_periodséÿÿÿÿéÎÿÿÿ©r   r
   )ÚnpÚrandomÚrandnÚlenÚrollingÚcovÚtmÚassert_almost_equal)ÚseriesÚAÚBÚresultr   r   r   Útest_rolling_cov2   s    r2   c              	   C   s¶   | }|t j t|ƒ¡ }|jddd� |¡}t |d t  |dd … |dd … ¡d ¡ t 	¡ }t 	¡ }t j
|d d…< t j
|d d…< |jt|ƒd	d� |¡}t |d | |¡¡ d S )
Nr   r    r!   r#   r$   r%   r   é
   r
   )r&   r'   r(   r)   r*   Úcorrr,   r-   ZcorrcoefZmakeTimeSeriesÚnan)r.   r/   r0   r1   ÚaÚbr   r   r   Útest_rolling_corr:   s    ,r8   Úfuncr+   r4   c                 C   sn   t |jddd�| ƒƒ }|jtd ƒdfdf }|j d¡|_t |d jddd�| ƒ|d ƒ}tj||dd� d S )Nr3   r   r!   r
   F©Zcheck_names)Úgetattrr*   ÚlocÚsliceÚindexZ	droplevelr,   Úassert_series_equal)r9   Úframer1   Úexpectedr   r   r   Útest_rolling_pairwise_cov_corrK   s
     rB   Úmethodc                    sÀ   ˆ d ‰t ˆjdd�ˆƒˆ ƒ}t ˆ jdd�ˆƒˆƒ}ˆ  ‡‡fdd„¡}t ||¡ t ||¡ ˆ  ¡ ‰tjjˆj	Ž ˆj
d d …< t ˆ jdd�ˆƒˆƒ}t‡ ‡‡fdd„ˆ D ƒƒ}t ||¡ d S )Nr
   r3   ©r"   c                    s   t ˆjdd�ˆ ƒ| ƒS )Nr3   rD   ©r;   r*   ©Úx)rC   r.   r   r   Ú<lambda>Z   ó    z(test_flex_binary_frame.<locals>.<lambda>c                    s,   i | ]$}|t ˆ | jd d�ˆƒˆ| ƒ“qS )r3   rD   rE   )Ú.0Úk)r@   Úframe2rC   r   r   Ú
<dictcomp>d   s      z*test_flex_binary_frame.<locals>.<dictcomp>)r;   r*   Úapplyr,   Úassert_frame_equalÚcopyr&   r'   r(   ÚshapeÚvaluesr   )rC   r@   ÚresZres2ÚexpZres3r   )r@   rL   rC   r.   r   Útest_flex_binary_frameT   s    ÿrU   r"   é   c                 C   s@   t t d¡ƒ}t t d¡ƒ}|j| d�j|d� ¡  ¡ s<t‚d S )Né   rD   )Úother)	r   r&   ZzerosÚaranger*   r4   ZisnaÚallÚAssertionError)r"   ÚsrX   r   r   r   Ú$test_rolling_corr_with_zero_variancei   s    r]   c               
   C   s¬   t t ddgddgddgddgd	d
gddgg¡ƒ} | d jddd� | d ¡}tdd„ |D ƒƒsdt‚t tj dd¡ƒ} | d jddd� | d ¡}tdd„ |D ƒƒs¨t‚d S )Ng†F$ÈÙë?g)—Òé¯Ç?g‰ËT5ÿ—ä?g´?«'NÉÓ?gFr�1�í?g+ÿ”	C-à?gR	²±`?gÕ1:b%§?g9T!X4!ë?gXÀÊÂS_Õ?gS®= é?g\–+“Ltä?r   r   T)Úcenterr
   c                 s   s"   | ]}t  t  |¡¡d kV  qdS ©r
   N©r&   ÚabsZ
nan_to_num©rJ   rG   r   r   r   Ú	<genexpr>‚   s     z#test_corr_sanity.<locals>.<genexpr>é   r   c                 s   s"   | ]}t  t  |¡¡d kV  qdS r_   r`   rb   r   r   r   rc   †   s     )	r   r&   Úarrayr*   r4   rZ   r[   r'   Zrand)ÚdfrS   r   r   r   Útest_corr_sanityr   s     úÿÿrg   c                  C   s–   t dddgdddgd�} t ddgddgd�}| jddd� |¡}t d d dgƒ}t ||¡ t dd dgdddgd�}| jddd� |¡}t ||¡ d S )Nr
   r   r   r   ©r>   r!   r   )r   r*   r+   r,   r?   ©Ús1Ús2r1   rA   Zs2ar   r   r   Útest_rolling_cov_diff_length‰   s    rl   c                  C   s–   t dddgdddgd�} t ddgddgd�}| jddd� |¡}t d d dgƒ}t ||¡ t dd dgdddgd�}| jddd� |¡}t ||¡ d S )Nr
   r   r   r   rh   r!   r   )r   r*   r4   r,   r?   ri   r   r   r   Útest_rolling_corr_diff_length–   s    rm   Úfc                 C   s   | j ddd�j| dd�S ©Nr3   r   r!   T©Úpairwise©r*   r+   rF   r   r   r   rH   ¦   rI   rH   c                 C   s   | j ddd�j| dd�S ro   ©r*   r4   rF   r   r   r   rH   §   rI   c                 C   s†   t ddgddgddgddggtdd	gd
d�ttdƒdd�d�}t tdd	gd
d�tj|j|jgdd
gd�dd�}| |ƒ}t ||¡ d S )Nr
   r   r   r   é	   r#   r   r/   r0   Úfoo©Únamer	   Úbar©r   r>   ©ÚnamesÚfloat64)r   r>   Údtype)	r   r   Úranger   Úfrom_productr>   r   r,   rO   )rn   rf   Zdf_expectedZ	df_resultr   r   r   Ú2test_rolling_functions_window_non_shrinkage_binary£   s    
ýýr€   c                 C   s   | j ddd�j| dd�S ro   rr   rF   r   r   r   rH   ¾   rI   c                 C   s   | j ddd�j| dd�S ro   rs   rF   r   r   r   rH   ¿   rI   c                 C   s®   t ƒ }t tdgdd�tg dd�d�}|d  d¡|d< t t |j|jg¡tg ƒd�}t tj|j|jgddgd�tdgdd�dd	�}| |ƒ}t ||¡ | |ƒ}t ||¡ d S )
Nr6   ru   rv   rx   ry   r|   ©r>   r   rz   )r>   r   r}   )	r   r   Zastyper   r   r>   r   r,   rO   )rn   Zdf1Zdf2Zdf1_expectedZdf2_expectedZ
df1_resultZ
df2_resultr   r   r   Ú*test_moment_functions_zero_length_pairwise»   s     	 ÿýr‚   c                
   @   sh  e Zd Zej ddd„ dd„ g¡dd„ ƒZej ddd„ dd„ d	d„ d
d„ dd„ dd„ g¡dd„ ƒZej ddd„ dd„ dd„ dd„ dd„ dd„ g¡dd„ ƒZej ddd„ dd„ dd„ dd„ dd„ dd„ g¡dd„ ƒZ	ej ddd„ d d„ d!d„ d"d„ d#d„ d$d„ g¡d%d&„ ƒZ
ej dd'd„ d(d„ d)d„ d*d„ d+d„ d,d„ g¡d-d.„ ƒZd/d0„ Zd1d2„ Zd3d4„ Zd5S )6ÚTestPairwisern   c                 C   s   |   ¡ S ©N)r+   rF   r   r   r   rH   Û   rI   zTestPairwise.<lambda>c                 C   s   |   ¡ S r„   )r4   rF   r   r   r   rH   Û   rI   c                 C   sX   ||ƒ}t  |j|j¡ t  |j|j¡ ||ƒ}| ¡ j}| ¡ j}t j||dd� d S ©NF©Zcheck_dtype©r,   Úassert_index_equalr>   r   ÚdropnarR   Úassert_numpy_array_equal©Úselfr   r   rn   r1   rA   r   r   r   Útest_no_flexÛ   s    

zTestPairwise.test_no_flexc                 C   s   |   ¡ jdd�S ©NTrp   ©Ú	expandingr+   rF   r   r   r   rH   î   rI   c                 C   s   |   ¡ jdd�S rŽ   ©r�   r4   rF   r   r   r   rH   ï   rI   c                 C   s   | j dd�jdd�S ©Nr   rD   Trp   rr   rF   r   r   r   rH   ð   rI   c                 C   s   | j dd�jdd�S r’   rs   rF   r   r   r   rH   ñ   rI   c                 C   s   | j dd�jdd�S ©Nr   ©ÚcomTrp   ©Úewmr+   rF   r   r   r   rH   ò   rI   c                 C   s   | j dd�jdd�S r“   ©r—   r4   rF   r   r   r   rH   ó   rI   c                 C   s„   ||ƒ}t j|jjd |jdd� t  t|jjd ƒt|j ¡ ƒ¡ t  |j|j¡ ||ƒ}| ¡ j	}| ¡ j	}t j||dd� d S ©Nr   Fr:   r
   r†   ©
r,   rˆ   r>   ZlevelsrŠ   r   r   Úuniquer‰   rR   r‹   r   r   r   Útest_pairwise_with_selfë   s    
  ÿþ

z$TestPairwise.test_pairwise_with_selfc                 C   s   |   ¡ jdd�S ©NFrp   r�   rF   r   r   r   rH     rI   c                 C   s   |   ¡ jdd�S r�   r‘   rF   r   r   r   rH     rI   c                 C   s   | j dd�jdd�S ©Nr   rD   Frp   rr   rF   r   r   r   rH     rI   c                 C   s   | j dd�jdd�S rž   rs   rF   r   r   r   rH     rI   c                 C   s   | j dd�jdd�S ©Nr   r”   Frp   r–   rF   r   r   r   rH     rI   c                 C   s   | j dd�jdd�S rŸ   r˜   rF   r   r   r   rH     rI   c                 C   sX   ||ƒ}t  |j|j¡ t  |j|j¡ ||ƒ}| ¡ j}| ¡ j}t j||dd� d S r…   r‡   r‹   r   r   r   Útest_no_pairwise_with_self  s    

z'TestPairwise.test_no_pairwise_with_selfc                 C   s   |   ¡ j|dd�S rŽ   r�   ©rG   Úyr   r   r   rH   (  rI   c                 C   s   |   ¡ j|dd�S rŽ   r‘   r¡   r   r   r   rH   )  rI   c                 C   s   | j dd�j|dd�S r’   rr   r¡   r   r   r   rH   *  rI   c                 C   s   | j dd�j|dd�S r’   rs   r¡   r   r   r   rH   +  rI   c                 C   s   | j dd�j|dd�S r“   r–   r¡   r   r   r   rH   ,  rI   c                 C   s   | j dd�j|dd�S r“   r˜   r¡   r   r   r   rH   -  rI   c                 C   sx   |||ƒ}t j|jjd |jdd� t  t|jjd ƒt|j ¡ ƒ¡ |||ƒ}| ¡ j	}| ¡ j	}t j||dd� d S r™   rš   )rŒ   r   r   r   rn   r1   rA   r   r   r   Útest_pairwise_with_other%  s    

  ÿþ


z%TestPairwise.test_pairwise_with_otherc                 C   s   |   ¡ j|dd�S r�   r�   r¡   r   r   r   rH   H  rI   c                 C   s   |   ¡ j|dd�S r�   r‘   r¡   r   r   r   rH   I  rI   c                 C   s   | j dd�j|dd�S rž   rr   r¡   r   r   r   rH   J  rI   c                 C   s   | j dd�j|dd�S rž   rs   r¡   r   r   r   rH   K  rI   c                 C   s   | j dd�j|dd�S rŸ   r–   r¡   r   r   r   rH   L  rI   c                 C   s   | j dd�j|dd�S rŸ   r˜   r¡   r   r   r   rH   M  rI   c              	   C   sÈ   |j jr|||ƒnd }|d k	r|tjdd��. t dt¡ |j |j¡}|j  |j ¡}W 5 Q R X t 	|j|¡ t 	|j |¡ nHt
jtdd�� |||ƒ W 5 Q R X t
jtdd�� |||ƒ W 5 Q R X d S )NT)ÚrecordÚignorez'arg1' columns are not unique)Úmatchz'arg2' columns are not unique)r   Z	is_uniqueÚwarningsÚcatch_warningsÚsimplefilterÚRuntimeWarningr>   Úunionr,   rˆ   ÚpytestZraisesÚ
ValueError)rŒ   r   r   rn   r1   Zexpected_indexZexpected_columnsr   r   r   Útest_no_pairwise_with_otherE  s"    ÿýÿz(TestPairwise.test_no_pairwise_with_otherc                 C   s   |   ¡  |¡S r„   r�   r¡   r   r   r   rH   k  rI   c                 C   s   |   ¡  |¡S r„   r‘   r¡   r   r   r   rH   l  rI   c                 C   s   | j dd� |¡S ©Nr   rD   rr   r¡   r   r   r   rH   m  rI   c                 C   s   | j dd� |¡S r¯   rs   r¡   r   r   r   rH   n  rI   c                 C   s   | j dd� |¡S ©Nr   r”   r–   r¡   r   r   r   rH   o  rI   c                 C   s   | j dd� |¡S r°   r˜   r¡   r   r   r   rH   p  rI   c                 C   sä   ||t ddddgƒƒ}t |j|j¡ t |j|j¡ ||t ddddgƒƒ}| ¡ j}| ¡ j}tj||dd� |t ddddgƒ|ƒ}t |j|j¡ t |j|j¡ |t ddddgƒ|ƒ}| ¡ j}| ¡ j}tj||dd� d S )Nr
   r   r   Fr†   )r   r,   rˆ   r>   r   r‰   rR   rŠ   r‹   r   r   r   Útest_pairwise_with_seriesh  s    



z&TestPairwise.test_pairwise_with_seriesc                 C   sT   t tdƒtddd�d�}| d¡ |¡}t tjgd tddd�d�}t ||¡ d S )Nr   Z2020)Zperiodsrh   Z12H)	r   r~   r   r*   r4   r&   r5   r,   r?   )rŒ   r\   r1   rA   r   r   r   Útest_corr_freq_memory_errorŠ  s    z(TestPairwise.test_corr_freq_memory_errorc              	   C   sÒ   t  tdƒtdƒtdƒg¡}tdƒ}tt d¡ dd¡||d�}|jdd	� 	¡ }t  tdƒtdƒtdƒtdƒg¡}t  tdƒtdƒtdƒg¡}tt 
t d
tj¡t d
d¡t d
d¡f¡||d�}t ||¡ d S )NÚabZxyZABr   é   r   r�   gš™™™™™¹?)Úalpha)r   r   g      @@gK\Ç¸âðO@)r   r   Úlistr~   r   r&   rY   Zreshaper—   r+   ZvstackÚfullÚNaNr,   rO   )rŒ   r   r>   rf   r1   rA   r   r   r   Útest_cov_mulittindex‘  s"    "

ýÿ÷z!TestPairwise.test_cov_mulittindexc                 C   s’   t jddgddggddgd�}tt d¡|d	�}| d
¡ ¡ }ttjt jt t 	d¡d¡ddgd ddgd gd ddgd�|d�}t
 ||¡ d S )NÚMÚNÚPÚQr6   r7   rz   )r   r   r   r   r   r   r�   )r   Zfrom_arraysr   r&   Zonesr*   r4   r5   ÚrepeatrY   r,   rO   )rŒ   r   rf   r1   rA   r   r   r   Ú$test_multindex_columns_pairwise_funcª  s    &þúz1TestPairwise.test_multindex_columns_pairwise_funcN)Ú__name__Ú
__module__Ú__qualname__r¬   ÚmarkÚparametrizer�   rœ   r    r£   r®   r±   r²   r¹   r¿   r   r   r   r   rƒ   Ø   sx   
úþ
úþ
úþ
úþ
úþ
rƒ   )!r§   Únumpyr&   r¬   Zpandasr   r   r   r   r   Zpandas._testingZ_testingr,   Zpandas.core.algorithmsr   Zfixturer   r   r   r2   r8   rÃ   rÄ   rB   rU   r~   r]   rg   rl   rm   r€   r‚   rƒ   r   r   r   r   Ú<module>   s`   &&&&&&&&&÷ÿ





þþ
þþ
