a
    é´«j?  ã                   @   sª  d dl Zd dlZd dlm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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d0d1„ Zej d2d3d4„ d5d4„ g¡d6d7„ ƒZ ej d2d8d4„ d9d4„ g¡d:d;„ ƒZ!G d<d=„ d=ƒZ"dS )>é    N)ÚIS64)Ú	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   ú`/var/www/html/laksyashrimp/venv/lib/python3.9/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   s(   t g d¢g d¢g d¢g d¢gg d¢d�S )z&Pairwise other frame for test_pairwise)Nr   r   )Nr   r	   )Né   r	   )Nr   r   )ÚYÚZr   r   r   r   r   r   r   Úpairwise_other_frame)   s    þr   c              	   C   sd   | }|t j d¡ t|ƒ¡ }|jddd� |¡}t |j	d t  |dd … |dd … ¡d ¡ d S ©Nr	   é2   é   ©ÚwindowZmin_periodséÿÿÿÿiÎÿÿÿ)r   r   )
ÚnpÚrandomÚdefault_rngÚstandard_normalÚlenÚrollingÚcovÚtmÚassert_almost_equalÚiloc©ÚseriesÚAÚBÚresultr   r   r   Útest_rolling_cov2   s    r5   c              	   C   sd   | }|t j d¡ t|ƒ¡ }|jddd� |¡}t |j	d t  
|dd … |dd … ¡d ¡ d S r    )r&   r'   r(   r)   r*   r+   Úcorrr-   r.   r/   Zcorrcoefr0   r   r   r   Útest_rolling_corr:   s    r7   c                  C   sx   t tjdtjd�tddd�d�} |  ¡ }tj| d d…< tj|d d…< | jt| ƒdd	� 	|¡}t
 |jd
 |  	|¡¡ d S )Né   ©Údtypez
2020-01-01©Zperiods©Úindexr   é
   r   r#   r%   )r   r&   ÚarangeÚfloat64r   ÚcopyÚnanr+   r*   r6   r-   r.   r/   )ÚaÚbr4   r   r   r   Ú!test_rolling_corr_bias_correctionB   s    ÿrE   Úfuncr,   r6   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 )Nr>   r   r#   r   F©Zcheck_names)Úgetattrr+   ÚlocÚslicer=   Z	droplevelr-   Úassert_series_equal)rF   Úframer4   Úexpectedr   r   r   Útest_rolling_pairwise_cov_corrO   s
     rN   Úmethodc                    sÊ   ˆ d ‰t ˆjdd�ˆƒˆ ƒ}t ˆ jdd�ˆƒˆƒ}ˆ  ‡‡fdd„¡}t ||¡ t ||¡ ˆ  ¡ ‰ttj 	d¡ 
ˆj¡ˆjˆjd�‰t ˆ jdd�ˆƒˆƒ}t‡ ‡‡fdd	„ˆ D ƒƒ}t ||¡ d S )
Nr   r>   ©r$   c                    s   t ˆjdd�ˆ ƒ| ƒS )Nr>   rP   ©rH   r+   ©Úx)rO   r1   r   r   Ú<lambda>^   ó    z(test_flex_binary_frame.<locals>.<lambda>r	   ©r=   r   c                    s,   i | ]$}|t ˆ | jd d�ˆƒˆ| ƒ“qS )r>   rP   rQ   )Ú.0Úk)rL   Úframe2rO   r   r   Ú
<dictcomp>l   rU   z*test_flex_binary_frame.<locals>.<dictcomp>)rH   r+   Úapplyr-   Úassert_frame_equalrA   r   r&   r'   r(   r)   Úshaper=   r   )rO   rL   ÚresZres2ÚexpZres3r   )rL   rY   rO   r1   r   Útest_flex_binary_frameX   s"    ýÿr`   r$   é   c                 C   s@   t t d¡ƒ}t t d¡ƒ}|j| d�j|d� ¡  ¡ s<J ‚d S )Nr8   rP   )Úother)r   r&   Zzerosr?   r+   r6   ZisnaÚall)r$   Úsrb   r   r   r   Ú$test_rolling_corr_with_zero_varianceq   s    re   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 ƒƒsdJ ‚t tj d¡ d¡ƒ} | d jddd� | d ¡}tdd„ |D ƒƒs¬J ‚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©rW   rS   r   r   r   Ú	<genexpr>Š   rU   z#test_corr_sanity.<locals>.<genexpr>r	   )é   r	   c                 s   s"   | ]}t  t  |¡¡d kV  qdS rg   rh   rj   r   r   r   rk   Ž   rU   )r   r&   Úarrayr+   r6   rc   r'   r(   )Údfr^   r   r   r   Útest_corr_sanityz   s     úÿÿro   c                  C   sŒ   t g d¢g d¢d�} t ddgddgd�}| jddd� |¡}t g d	¢ƒ}t ||¡ t g d
¢g d¢d�}| jddd� |¡}t ||¡ d S )N©r   r	   r   ©r   r   r	   r<   r   r   r   r	   r#   )NNr   ©r   Nr   )r   r+   r,   r-   rK   ©Ús1Ús2r4   rM   Zs2ar   r   r   Útest_rolling_cov_diff_length‘   s    rv   c                  C   sŒ   t g d¢g d¢d�} t ddgddgd�}| jddd� |¡}t g d	¢ƒ}t ||¡ t g d
¢g d¢d�}| jddd� |¡}t ||¡ d S )Nrp   rq   r<   r   r   r   r	   r#   )NNr   rr   )r   r+   r6   r-   rK   rs   r   r   r   Útest_rolling_corr_diff_lengthž   s    rw   Úfc                 C   s   | j ddd�j| dd�S ©Nr>   r   r#   T©Úpairwise©r+   r,   rR   r   r   r   rT   ®   rU   rT   c                 C   s   | j ddd�j| dd�S ry   ©r+   r6   rR   r   r   r   rT   ¯   rU   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   r2   r3   Úfoo©Únamer
   Úbar©r   r=   ©Únamesr@   )r   r=   r:   )	r   r   Úranger   Úfrom_productr=   r   r-   r\   )rx   rn   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 ry   r|   rR   r   r   r   rT   Å   rU   c                 C   s   | j ddd�j| dd�S ry   r}   rR   r   r   r   rT   Æ   rU   c                 C   s¨   t ƒ }t tdgdd�tg dd�d�}|d  d¡|d< t t |j|jg¡d�}t tj|j|jgddgd�tdgdd�dd	�}| |ƒ}t ||¡ | |ƒ}t ||¡ d S )
NrC   r   r€   r‚   rƒ   r@   r<   r„   )r=   r   r:   )	r   r   Zastyper   r‡   r=   r   r-   r\   )rx   Zdf1Zdf2Zdf1_expectedZdf2_expectedZ
df1_resultZ
df2_resultr   r   r   Ú*test_moment_functions_zero_length_pairwiseÂ   s    ýr‰   c                   @   sŽ  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„ ej	dd„ ejj
e ddd�d�dd„ d d„ g¡d!d"„ ƒZej d#¡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„ d0d„ d1d„ g¡d2d3„ ƒZd4d5„ Zd6d7„ Zd8d9„ Zd:S );ÚTestPairwiserx   c                 C   s   |   ¡ S ©N)r,   rR   r   r   r   rT   Þ   rU   zTestPairwise.<lambda>c                 C   s   |   ¡ S r‹   )r6   rR   r   r   r   rT   Þ   rU   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   ÚdropnaÚvaluesÚassert_numpy_array_equal©Úselfr   r   rx   r4   rM   r   r   r   Útest_no_flexÞ   s    

zTestPairwise.test_no_flexc                 C   s   |   ¡ jdd�S ©NTrz   ©Ú	expandingr,   rR   r   r   r   rT   ð   rU   c                 C   s   |   ¡ jdd�S r–   ©r˜   r6   rR   r   r   r   rT   ñ   rU   c                 C   s   | j dd�jdd�S ©Nr   rP   Trz   r|   rR   r   r   r   rT   ò   rU   c                 C   s   | j dd�jdd�S rš   r}   rR   r   r   r   rT   ó   rU   c                 C   s   | j dd�jdd�S ©Nr   ©ÚcomTrz   ©Úewmr,   rR   r   r   r   rT   ô   rU   c                 C   s   | j dd�jdd�S r›   ©rŸ   r6   rR   r   r   r   rT   õ   rU   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   FrG   r   r�   ©
r-   r�   r=   Zlevelsr   r   Úuniquer�   r‘   r’   r“   r   r   r   Útest_pairwise_with_selfí   s    ÿþ

z$TestPairwise.test_pairwise_with_selfc                 C   s   |   ¡ jdd�S ©NFrz   r—   rR   r   r   r   rT     rU   c                 C   s   |   ¡ jdd�S r¥   r™   rR   r   r   r   rT     rU   c                 C   s   | j dd�jdd�S ©Nr   rP   Frz   r|   rR   r   r   r   rT     rU   c                 C   s   | j dd�jdd�S r¦   r}   rR   r   r   r   rT     rU   c                 C   s   | j dd�jdd�S ©Nr   rœ   Frz   rž   rR   r   r   r   rT     rU   c                 C   s   | j dd�jdd�S r§   r    rR   r   r   r   rT     rU   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—   ©rS   Úyr   r   r   rT   (  rU   c                 C   s   |   ¡ j|dd�S r–   r™   r©   r   r   r   rT   )  rU   c                 C   s   | j dd�j|dd�S rš   r|   r©   r   r   r   rT   *  rU   c                 C   s   | j dd�j|dd�S rš   r}   r©   r   r   r   rT   -  rU   zPrecision issues on 32 bitF)ÚreasonÚstrict)Zmarksc                 C   s   | j dd�j|dd�S r›   rž   r©   r   r   r   rT   2  rU   c                 C   s   | j dd�j|dd�S r›   r    r©   r   r   r   rT   3  rU   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   rx   r4   rM   r   r   r   Útest_pairwise_with_other%  s    
ÿþ


z%TestPairwise.test_pairwise_with_otherzignore:RuntimeWarningc                 C   s   |   ¡ j|dd�S r¥   r—   r©   r   r   r   rT   N  rU   c                 C   s   |   ¡ j|dd�S r¥   r™   r©   r   r   r   rT   O  rU   c                 C   s   | j dd�j|dd�S r¦   r|   r©   r   r   r   rT   P  rU   c                 C   s   | j dd�j|dd�S r¦   r}   r©   r   r   r   rT   Q  rU   c                 C   s   | j dd�j|dd�S r§   rž   r©   r   r   r   rT   R  rU   c                 C   s   | j dd�j|dd�S r§   r    r©   r   r   r   rT   S  rU   c                 C   sÌ   |j jr|||ƒnd }|d urX|j |j¡}|j  |j ¡}t |j|¡ t |j |¡ nptjtdd�� |||ƒ W d   ƒ n1 s†0    Y  tjtdd�� |||ƒ W d   ƒ n1 s¾0    Y  d S )Nz'arg1' columns are not unique)Úmatchz'arg2' columns are not unique)	r   Z	is_uniquer=   Úunionr-   r�   ÚpytestZraisesÚ
ValueError)r”   r   r   rx   r4   Zexpected_indexZexpected_columnsr   r   r   Útest_no_pairwise_with_otherJ  s    ÿýÿ(z(TestPairwise.test_no_pairwise_with_otherc                 C   s   |   ¡  |¡S r‹   r—   r©   r   r   r   rT   n  rU   c                 C   s   |   ¡  |¡S r‹   r™   r©   r   r   r   rT   o  rU   c                 C   s   | j dd� |¡S ©Nr   rP   r|   r©   r   r   r   rT   p  rU   c                 C   s   | j dd� |¡S r³   r}   r©   r   r   r   rT   q  rU   c                 C   s   | j dd� |¡S ©Nr   rœ   rž   r©   r   r   r   rT   r  rU   c                 C   s   | j dd� |¡S r´   r    r©   r   r   r   rT   s  rU   c                 C   sÔ   ||t g d¢ƒƒ}t |j|j¡ t |j|j¡ ||t g d¢ƒƒ}| ¡ j}| ¡ j}tj||dd� |t g d¢ƒ|ƒ}t |j|j¡ t |j|j¡ |t g d¢ƒ|ƒ}| ¡ j}| ¡ j}tj||dd� d S )N)r   r   r   r   Fr�   )r   r-   r�   r=   r   r�   r‘   r’   r“   r   r   r   Útest_pairwise_with_seriesk  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2020r;   r<   Z12h)	r   r†   r   r+   r6   r&   rB   r-   rK   )r”   rd   r4   rM   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   rV   gš™™™™™¹?)Úalpha)r   r   g      @@gK\Ç¸âðO@)r   r‡   Úlistr†   r   r&   r?   ZreshaperŸ   r,   ZvstackÚfullrB   r-   r\   )r”   r   r=   rn   r4   rM   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j	dtj
d�d¡ddgd ddgd gg d¢d�|d�}t ||¡ d S )NÚMÚNÚPÚQrC   rD   r„   )r   r	   r   r   r   r9   r	   )NrC   rD   rV   )r   Zfrom_arraysr   r&   Zonesr+   r6   rB   Úrepeatr?   Zint64r-   r\   )r”   r   rn   r4   rM   r   r   r   Ú$test_multindex_columns_pairwise_func¬  s    

ýúöz1TestPairwise.test_multindex_columns_pairwise_funcN)Ú__name__Ú
__module__Ú__qualname__r°   ÚmarkÚparametrizer•   r¤   r¨   r   Zxfailr   r­   Úfilterwarningsr²   rµ   r¶   r¼   rÂ   r   r   r   r   rŠ   Ü   s„   
úþ
úþ
ÿþôþ

úþúþ
rŠ   )#Únumpyr&   r°   Zpandas.compatr   Zpandasr   r   r   r   r   Zpandas._testingZ_testingr-   Zpandas.core.algorithmsr   Zfixturer   r   r   r5   r7   rE   rÆ   rÇ   rN   r`   r†   re   ro   rv   rw   rˆ   r‰   rŠ   r   r   r   r   Ú<module>   sb   &&&&&&&&&÷ÿ





þþ
þþ
