o
    dq=                     @   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   f/var/www/html/visualizacion-main/env/lib/python3.10/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   s\   | }|t jt| }|jddd|}t|d t |dd  |dd  d  d S )N2      windowmin_periodsr   r
   )nprandomrandnlenrollingcovtmassert_almost_equal)seriesABresultr   r   r   test_rolling_cov2   s   0r3   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.   corrcoefmakeTimeSeriesnan)r/   r0   r1   r2   abr   r   r   test_rolling_corr:   s   ,r;   funcr,   r5   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 )Nr4   r   r!   r
   Fcheck_names)getattrr+   locsliceindex	droplevelr-   assert_series_equal)r<   framer2   expectedr   r   r   test_rolling_pairwise_cov_corrK   s
    rG   methodc                    s    d t jdd }t  jdd} fdd}t|| t||   ttjj	j
 jjdt  jdd}t fdd D }t|| d S )	Nr
   r4   r"   c                    s   t jdd | S )Nr4   rI   r?   r+   x)rH   r/   r   r   <lambda>Z       z(test_flex_binary_frame.<locals>.<lambda>rB   r   c                    s,   i | ]}|t  | jd d| qS )r4   rI   rJ   ).0k)rE   frame2rH   r   r   
<dictcomp>f   s   , z*test_flex_binary_frame.<locals>.<dictcomp>)r?   r+   applyr-   assert_frame_equalcopyr   r'   r(   r)   shaperB   r   )rH   rE   resres2expres3r   )rE   rR   rH   r/   r   test_flex_binary_frameT   s   r\   r"      c                 C   s@   t td}t td}|j| dj|d  sJ d S )N   rI   )other)r   r'   zerosaranger+   r5   isnaall)r"   sr_   r   r   r   $test_rolling_corr_with_zero_variancek   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 s2J t tjdd} | d jddd| d }tdd |D sTJ d S )NgF$?g)?gT5?g?'N?gFr1?g+	C-?gR	`?g1:b%?g9T!X4!?gXS_?gS= ?g\+Lt?r   r   T)centerr
   c                 s   $    | ]}t t |d kV  qdS r
   Nr'   abs
nan_to_numrP   rL   r   r   r   	<genexpr>      " z#test_corr_sanity.<locals>.<genexpr>   r   c                 s   rg   rh   ri   rl   r   r   r   rm      rn   )r   r'   arrayr+   r5   rc   r(   rand)dfrX   r   r   r   test_corr_sanityt   s    rs   c                  C      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   rB   r
   r   r   r   r!   )NNr   r
   Nr   )r   r+   r,   r-   rD   s1s2r2   rF   s2ar   r   r   test_rolling_cov_diff_length      r}   c                  C   rt   )Nru   rv   rw   r
   r   r   r   r!   )NNr   rx   )r   r+   r5   r-   rD   ry   r   r   r   test_rolling_corr_diff_length   r~   r   fc                 C      | j dddj| ddS Nr4   r   r!   Tpairwiser+   r,   rK   r   r   r   rM          rM   c                 C   r   r   r+   r5   rK   r   r   r   rM      r   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   r0   r1   foonamer	   barr   rB   namesfloat64)r   rB   dtype)	r   r   ranger   from_productrB   r   r-   rU   )r   rr   df_expected	df_resultr   r   r   2test_rolling_functions_window_non_shrinkage_binary   s   	r   c                 C   r   r   r   rK   r   r   r   rM      r   c                 C   r   r   r   rK   r   r   r   rM      r   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 )
Nr9   r   r   r   r   r   rw   r   )rB   r   r   )	r   r   astyper   r   rB   r   r-   rU   )r   df1df2df1_expecteddf2_expected
df1_result
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TestPairwiser   c                 C      |   S N)r,   rK   r   r   r   rM          zTestPairwise.<lambda>c                 C   r   r   )r5   rK   r   r   r   rM      r   c                 C   sX   ||}t |j|j t |j|j ||}| j}| j}t j||dd d S NFcheck_dtyper-   assert_index_equalrB   r   dropnavaluesassert_numpy_array_equalselfr   r   r   r2   rF   r   r   r   test_no_flex   s   

zTestPairwise.test_no_flexc                 C      |   jddS NTr   	expandingr,   rK   r   r   r   rM          c                 C   r   r   r   r5   rK   r   r   r   rM      r   c                 C      | j ddjddS Nr   rI   Tr   r   rK   r   r   r   rM          c                 C   r   r   r   rK   r   r   r   rM      r   c                 C   r   Nr   comTr   ewmr,   rK   r   r   r   rM      r   c                 C   r   r   r   r5   rK   r   r   r   rM      r   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   rB   levelsr   r   uniquer   r   r   r   r   r   r   test_pairwise_with_self   s   

z$TestPairwise.test_pairwise_with_selfc                 C   r   NFr   r   rK   r   r   r   rM   
  r   c                 C   r   r   r   rK   r   r   r   rM     r   c                 C   r   Nr   rI   Fr   r   rK   r   r   r   rM     r   c                 C   r   r   r   rK   r   r   r   rM     r   c                 C   r   Nr   r   Fr   r   rK   r   r   r   rM     r   c                 C   r   r   r   rK   r   r   r   rM     r   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      |   j|ddS r   r   rL   yr   r   r   rM   "      c                 C   r   r   r   r   r   r   r   rM   #  r   c                 C      | j ddj|ddS r   r   r   r   r   r   rM   $  rN   c                 C   r   r   r   r   r   r   r   rM   %  rN   c                 C   r   r   r   r   r   r   r   rM   &  rN   c                 C   r   r   r   r   r   r   r   rM   '  rN   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   r   r2   rF   r   r   r   test_pairwise_with_other  s   



z%TestPairwise.test_pairwise_with_otherc                 C   r   r   r   r   r   r   r   rM   A  r   c                 C   r   r   r   r   r   r   r   rM   B  r   c                 C   r   r   r   r   r   r   r   rM   C  rN   c                 C   r   r   r   r   r   r   r   rM   D  rN   c                 C   r   r   r   r   r   r   r   rM   E  rN   c                 C   r   r   r   r   r   r   r   rM   F  rN   c                 C   s  |j jr	|||nd }|d urItjdd tdt |j|j}|j |j }W d    n1 s4w   Y  t	|j| t	|j | d S t
jtdd ||| W d    n1 s`w   Y  t
jtdd ||| W d    d S 1 s}w   Y  d S )NT)recordignorez'arg1' columns are not unique)matchz'arg2' columns are not unique)r   	is_uniquewarningscatch_warningssimplefilterRuntimeWarningrB   unionr-   r   pytestraises
ValueError)r   r   r   r   r2   expected_indexexpected_columnsr   r   r   test_no_pairwise_with_other>  s(   "z(TestPairwise.test_no_pairwise_with_otherc                 C      |   |S r   r   r   r   r   r   rM   c      c                 C   r   r   r   r   r   r   r   rM   d  r   c                 C      | j dd|S Nr   rI   r   r   r   r   r   rM   e  r   c                 C   r   r   r   r   r   r   r   rM   f  r   c                 C   r   Nr   r   r   r   r   r   r   rM   g  r   c                 C   r   r   r   r   r   r   r   rM   h  r   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   rB   r   r   r   r   r   r   r   r   test_pairwise_with_series`  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   2020)periodsrw   12H)	r   r   r   r+   r5   r'   r8   r-   rD   )r   rd   r2   rF   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abxyABr      r   rO   g?)alpha)r   r   g      @@gK\ǸO@)r   r   listr   r   r'   ra   reshaper   r,   vstackfullNaNr-   rU   )r   r   rB   rr   r2   rF   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Qr9   r:   r   )r   r   r   r   r   )r   r   )Nr9   r:   rO   )r   from_arraysr   r'   onesr+   r5   r8   repeatra   int64r-   rU   )r   r   rr   r2   rF   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      sz    





r   )!r   numpyr'   r   pandasr   r   r   r   r   pandas._testing_testingr-   pandas.core.algorithmsr   fixturer   r   r   r3   r;   r   r   rG   r\   r   re   rs   r}   r   r   r   r   r   r   r   r   <module>   sb    &&&&&&&&&







