U
    -e                     @   s   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
 d dlmZ d dlmZ d dlmZ ejdd Zejdd ZG d	d
 d
ZG dd dZG dd dZdS )    N)	DataFrameIndex
MultiIndexSeries	Timestamp
date_rangeto_datetime)BaseIndexer)get_groupbyc                   C   sP   t ddddddddddg
ddddddddddg
tdddd	d
dddddg
dS )z0Frame for testing times argument in EWM groupby.abcr            
2020-01-01
2020-01-02
2020-01-10z
2020-01-22
2020-01-03z
2020-01-23
2020-01-04ABC)r   r    r   r   a/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/pandas/tests/window/test_groupby.pytimes_frame   s$    r   c                   C   s.   t dgd dgd  dgd  tddS 	Nr      r      r      (   r   r   r   nparanger   r   r   r   
roll_frame+   s    r&   c                   @   s  e Zd Zdd Zdd Zdd Zejddd	d
ddddgdd Z	ejdddgdd Z
ejddddddgdd Zejdddgd d!ggd"d# Zejddd gd$d% Zejddd gd&d' Zejd(d d)d)gd)d*ggfdd)d!gd!d)ggfgd+d, Zd-d. Zd/d0 Zejd1d)d2gd3d4ggd5d6 Zd7d8 Zd9d: Zejd;d<d=d>gd?d@ ZdAdB ZdCdD ZdEdF ZdGdH ZejdIdd
gdJdK ZdLdM ZdNdO ZdPdQ ZdRdS ZejdTdUdVddWfdXi fgdYdZ Zejd[d\d]id]fd\d^id_fgd`da Z ejdbd2d4gdcdd Z!dedf Z"dgdh Z#didj Z$dkdl Z%dmdn Z&ejdodVdpdqd^d3d)d)d^d3d)d)gfdVdVdqd^d^d)d)d^d^d)d)gfd=d=dqd^d^d^d^d^d^d^d^gfd=d=drd^d^d^dsd^d^d^dsgfgdtdu Z'ejdve()dwdxgdydzggd{d| Z*d}d~ Z+ejddgdddddgigdd_ge,de,de,de,dgddddgdggdd Z-dd Z.dd Z/dd Z0dd Z1dd Z2d^S )TestRollingc              	   C   s0   d}t jt|d |jddd W 5 Q R X d S )Nz4groupby\(\) got an unexpected keyword argument 'foo'matchr   r   )foo)pytestraises	TypeErrorgroupby)selfr&   msgr   r   r   !test_groupby_unsupported_argument1   s    z-TestRolling.test_groupby_unsupported_argumentc                 C   s   | d}t|dd}|jdd }|d j}t|| |dj }t|| |jd }t|| |j |jd }t|| d S )Nr   byc                 S   s   |  d S )Nr   rollingmeanxr   r   r   <lambda>:       z*TestRolling.test_getitem.<locals>.<lambda>r   )	r.   r
   r   applyr5   r6   tmassert_series_equalr   )r/   r&   g	g_mutatedexpectedresultr   r   r   test_getitem6   s    
zTestRolling.test_getitemc                 C   sd   | d}|jddd}t|dd}|jdd }|j }t|| |j }t|| d S )Nr   r   r   min_periodsr2   c                 S   s   | j ddd S )Nr   r   rC   )r5   countr7   r   r   r   r9   M   r:   z3TestRolling.test_getitem_multiple.<locals>.<lambda>)r.   r5   r
   r   r;   rE   r<   r=   )r/   r&   r>   rr?   r@   rA   r   r   r   test_getitem_multipleH   s    


z!TestRolling.test_getitem_multiplefsumr6   minmaxrE   kurtskewc                    sr   |j ddd}|jdd}t|  }| fdd}|jddd	}t|d td
g}||_t	
|| d S )Nr   F
group_keys   windowc                    s   t | d  S NrP   getattrr5   r7   rH   r   r   r9   f   r:   z*TestRolling.test_rolling.<locals>.<lambda>r   Zaxisr!   r.   r5   rU   r;   dropr   from_arraysrangeindexr<   assert_frame_equalr/   rH   r&   r>   rF   rA   r@   expected_indexr   rV   r   test_rollingU   s    zTestRolling.test_rollingstdvarc                    sv   |j ddd}|jdd}t| dd}| fdd	}|jddd
}t|d tdg}||_t	
|| d S )Nr   FrN   rP   rQ   r   Zddofc                    s   t | d ddS )NrP   r   rc   rT   r7   rV   r   r   r9   t   r:   z/TestRolling.test_rolling_ddof.<locals>.<lambda>rW   r!   rX   r^   r   rV   r   test_rolling_ddofn   s    zTestRolling.test_rolling_ddofinterpolationlinearlowerhighermidpointnearestc                    st   |j ddd}|jdd}|jd d}| fdd	}|jdd
d}t|d tdg}||_t	
|| d S )Nr   FrN   rP   rQ   皙?re   c                    s   |  djd dS )NrP   rk   rl   )r5   quantiler7   rl   r   r   r9      r:   z3TestRolling.test_rolling_quantile.<locals>.<lambda>r   rW   r!   )r.   r5   rm   r;   rY   r   rZ   r[   r\   r<   r]   )r/   re   r&   r>   rF   rA   r@   r_   r   rl   r   test_rolling_quantile|   s    
z!TestRolling.test_rolling_quantilezf, expected_valcorrr   cov      ?c              
   C   s   t tddgd dgd  dddddgd ddd	g}t tddddddgd
d	}t|jddd||}tjg|gd  d }t |dgtj	dgd dgd  dgd dgd  t
tddd gddd	gdd}t|| d S )N
   r      r   r   rP   )valueidx1idx2ru   rv   )rt   rv   r   levelrt      namescolumnsr\   )r   r[   	set_indexrU   r.   r5   r$   nanr   rZ   listr<   r]   )r/   rH   Zexpected_valdfotherrA   expected_datar@   r   r   r   /test_rolling_corr_cov_other_same_size_as_groups   s,    ,z;TestRolling.test_rolling_corr_cov_other_same_size_as_groupsc                    sV    d}|jdd}t| } fdd}||}tj|d< t|| d S )Nr   rP   rQ   c                    s   t | d S rS   rT   r7   rH   r&   r   r   func   s    zITestRolling.test_rolling_corr_cov_other_diff_size_as_groups.<locals>.func)r.   r5   rU   r;   r$   r   r<   r]   r/   rH   r&   r>   rF   rA   r   r@   r   r   r   /test_rolling_corr_cov_other_diff_size_as_groups   s    


z;TestRolling.test_rolling_corr_cov_other_diff_size_as_groupsc                    sN   | d}|jdd}t|j dd} fdd}||}t|| d S )Nr   rP   rQ   Tpairwisec                    s   t | jd ddS )NrP   Tr   )rU   r   r5   r7   rV   r   r   r      s    z8TestRolling.test_rolling_corr_cov_pairwise.<locals>.func)r.   r5   rU   r   r;   r<   r=   r   r   rV   r   test_rolling_corr_cov_pairwise   s    

z*TestRolling.test_rolling_corr_cov_pairwisezfunc, expected_values      ?      @c                 C   s   t ddddgddddgddddgd}|d	d
}t|| }t dtjg |d  dtjg  dtjg |d  dtjg  dtjddddddddgd	d d gdd}t	|| d S )Ng1g2r   r   r   ry   rP   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   rz   r\   )
r   r.   r5   rU   r$   r   r   from_tuplesr<   r]   )r/   r   Zexpected_valuesr   ZrolrA   r@   r   r   r   test_rolling_corr_cov_unordered   s4    



z+TestRolling.test_rolling_corr_cov_unorderedc                    sx   |j ddd}|jdd}|jdd  d}| fd	d}|jdd
d}t|d tdg}||_t	|| d S )Nr   FrN   rP   rQ   c                 S   s   |   S NrI   r7   r   r   r   r9      r:   z0TestRolling.test_rolling_apply.<locals>.<lambda>rawc                    s   |  djdd  dS )NrP   c                 S   s   |   S r   r   yr   r   r   r9      r:   zBTestRolling.test_rolling_apply.<locals>.<lambda>.<locals>.<lambda>r   )r5   r;   r7   r   r   r   r9      r:   r   rW   r!   )
r.   r5   r;   rY   r   rZ   r[   r\   r<   r]   )r/   r   r&   r>   rF   rA   r@   r_   r   r   r   test_rolling_apply   s    zTestRolling.test_rolling_applyc                 C   s   t dgd dgd  dgd d}|d}tdd	d
dddg}dd g|_t tjddgd dg|d}|jdd }t	
|| |  |jdd }t	
|| d S )Nr*   r   barr   ry   r"   r   )r   r   )r   rP   )r   rs   )r*   r   )r*   r   )r*   r          @r   r   r|   rQ   )r   r.   r   r   r{   r$   r   r5   rI   r<   r]   )r/   r   r>   mir@   rA   r   r   r   test_rolling_apply_mutability   s    $

z)TestRolling.test_rolling_apply_mutabilityzexpected_value,raw_valueT        Fc                 C   sp   dd }t dddgdddgd}|djdj||d}t|gd tjd	dd gd
dd}t	|| d S )Nc                 S   s   t t| tjS r   )int
isinstancer$   Zndarrayr7   r   r   r   isnumpyarray  s    z6TestRolling.test_groupby_rolling.<locals>.isnumpyarrayr   r   r   )idrt   r   r   )r   r   r   r   r   r   rz   rt   r\   name)
r   r.   rt   r5   r;   r   r   r   r<   r=   )r/   Zexpected_valueZ	raw_valuer   r   rA   r@   r   r   r   test_groupby_rolling  s    z TestRolling.test_groupby_rollingc                 C   s  t tdd}||jddd }t tjgd tdd}t	
|| t tdd}||jddd }t tjgd	 td
d}t	
|| tdgd dgd  tdd}|djddd }ttjdddtjtjddddtjgtjddd gddgd}t	|| tdgd dgd  tdd}|djddd }ttjdddtjtjdddtjg
tjddd gddgd}t	|| d S )Nr   ry   Tr   )centerrR   rs   )r   r   r   r   r   rP   r   )rs   rP   r   rP   )r   r   r   r   r   r      r   r   r      r    	   )r   r   r   r   r   r   r   r   r   rP   r   rs   r   ry   r   r   r   r    r   r   )r   rr   rz   )r\   r}   rr   )
r   r   r   r   r   r   r   r   r   r   )r   r[   r.   r5   r6   r$   r   r   r   r<   r=   r   r]   )r/   ZseriesrA   r@   r   r   r   r   "test_groupby_rolling_center_center  sH    

" "z.TestRolling.test_groupby_rolling_center_centerc                 C   s   t tdddgd dgd  tddd	}|d
jdddddj }tddddddddddg
dtj	dt
dfdt
dfdt
dfdt
dfdt
dfdt
dfdt
dfdt
dfdt
dfdt
dff
d
dgd d!}t|| d S )"Nr   r   group_1ry   group_2rP   rr   )Dategbrt   )datar   r   Tr   )onr   rD   r         ?r   g      @      @g      @      @      @rt   r   r   r   z
2020-01-05z
2020-01-06z
2020-01-07z
2020-01-08z
2020-01-09rz   r   r\   )r   r   r[   r.   r5   rt   r6   r   r   r   r   r<   r=   r/   r   rA   r@   r   r   r   test_groupby_rolling_center_on^  s@    
   










z*TestRolling.test_groupby_rolling_center_onrD   rs   rP   r   c              
   C   s   t dgd dgd  tdd}d}|dj|d|d	 }| dd
g }ddddddddddg
}dd |D }td|d }tjg| }|||d|   | }	|||d|   | }
t dgd dgd  |	|
 d}t	
|| d S )Nr   rr   r   r   )groupr   rs   r   T)r   rD   r   r   r   r   r   r         @g      @r   r          @c                 S   s   g | ]}|d  qS )g      $@r   .0r8   r   r   r   
<listcomp>  s     zGTestRolling.test_groupby_rolling_center_min_periods.<locals>.<listcomp>r   r   )r   r[   r.   r5   r6   Zreset_indexrK   r$   r   r<   r]   )r/   rD   r   window_sizerA   Z
grp_A_meanZ
grp_B_meanZnum_nansZnansZgrp_A_expectedZgrp_B_expectedr@   r   r   r   'test_groupby_rolling_center_min_periods  s&    "
  z3TestRolling.test_groupby_rolling_center_min_periodsc                 C   s   t ddddgddddgdd	d
d	gd}|ddg d }t tjtjdtjgdgtjddd gdd}t	|| |dd d }t
tjtjdtjgtjddd gddd}t|| d S )Nr   r   r   r   r   r   r   rr   r      r   r   r   )r   r   r   r   r   rz   r|   r   )r   r.   r5   rK   r$   r   r   r   r<   r]   r   r=   r   r   r   r   test_groupby_subselect_rolling  s.    "  z*TestRolling.test_groupby_subselect_rollingc                 C   s   G dd dt }tddddddgd	 id
gd dgd  dgd  d}||jj|d	ddd }||jjd	dd }t|| d S )Nc                   @   s   e Zd ZdddZdS )zFTestRolling.test_groupby_rolling_custom_indexer.<locals>.SimpleIndexerr   Nc                 S   sH   |d kr| j nd}tj|tjdd }| | j  }|||dk < ||fS )Nr   dtyper   )r   r$   r%   int64copy)r/   Z
num_valuesrD   r   closedstependstartr   r   r   get_window_bounds  s
    zXTestRolling.test_groupby_rolling_custom_indexer.<locals>.SimpleIndexer.get_window_bounds)r   NNNN)__name__
__module____qualname__r   r   r   r   r   SimpleIndexer  s        r   r   r   r   r   r   r   r   r   rs   r   r   r   )r   rC   rR   rD   )r	   r   r.   r\   r5   rI   r<   r]   )r/   r   r   rA   r@   r   r   r   #test_groupby_rolling_custom_indexer  s      z/TestRolling.test_groupby_rolling_custom_indexerc                 C   s   t tdtddddg tdgd d}|djdd	d
dd  }ttjddtjddgt	j
dtdfgd dtdfgd  dd	gddd}t|| d S )Nry   r   r   r   
2019-01-01column1Zcolumn2r   dater   1Dr   leftr   r   r   r   r   r   r   rz   r   r   r[   r   r.   r5   rI   r   r$   r   r   r   r<   r=   r   r   r   r   'test_groupby_rolling_subset_with_closed  s(    
		z3TestRolling.test_groupby_rolling_subset_with_closedc                 C   s   t tdtddddg tdgd d}|ddd	g jd
d	ddd  }ttjddtjddgt	j
dtdfgd dtdfgd  dd	gddd}t|| d S )Nry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rz   r   r   r   r   r   r   .test_groupby_subset_rolling_subset_with_closed  s4    

  	z:TestRolling.test_groupby_subset_rolling_subset_with_closedr   c                 C   s~   t dddgtjdddgddgdd	d
}t||d| }t tjtjdgtjdddgd	ddgdd	d
}t	|| d S )Nr   r   )r   r8   )r   r   )r   z12rz   r   r   r   )r   r   r8   )r   r   r   )r   r   r   )
r   r   r   rU   r.   r5   r$   r   r<   r=   )r/   r   ZdsrA   r@   r   r   r   "test_groupby_rolling_index_changed  s$      z.TestRolling.test_groupby_rolling_index_changedc                 C   s   t dg i}|djdd }|jdd}tjtg ddtg ddgdd gd|_t	
|| t g g d	}|dd
gjdd }|jdd
gd}tjtg ddtg ddtg ddgdd
d gd|_t	
|| d S )Ns1r   rQ   r}   float64r   r   rz   )r   s2r   )r   r.   r5   rI   rY   r   Zfrom_productr   r\   r<   r]   )r/   r@   rA   r   r   r    test_groupby_rolling_empty_frame  s&     


z,TestRolling.test_groupby_rolling_empty_framec                 C   s6  t ddtddddgddtddddgdd	tddd
dgddtddddgdd	tddddggdddgdd}|d}| |d< |jddd}|dd }t ddtdddddgddtdddddgddtdddddgdd	tddd
ddgdd	tdddddggddddgdddg}t|| d S )Nr   r     r   r   r   r   Zr   r   Hry   Er   r\   r   Z	eventTimer   Zcount_to_dateZ10dr   c                 S   s
   | j d S )Nr   )shaper   r   r   r   r9   D  r:   z?TestRolling.test_groupby_rolling_string_index.<locals>.<lambda>r   r   r   )	r   r   r~   r.   Zcumcountr5   r;   r<   r]   )r/   r   groupsZrolling_groupsrA   r@   r   r   r   !test_groupby_rolling_string_index4  s6    	

	
z-TestRolling.test_groupby_rolling_string_indexc                 C   s|   t ddgddgdjdddd }t tddgddggdd	gtjd
dgdd gdd}|jdd}t	
|| d S )Nr   r   )r*   r   r*   F)sortr   r   r   )r   r   r   rz   r|   r   )r   r.   r5   rJ   r$   arrayr   r   rY   r<   r]   )r/   rA   r@   r   r   r   test_groupby_rolling_no_sortQ  s     z(TestRolling.test_groupby_rolling_no_sortc                 C   s   t tdtddddg tdddd}|djd	d
ddd  }ttjddtjddgdt	j
dtdfdtdfdtdfdtdfdtdfdtdfgdd
gdd}t|| d S )Nry   r   r   r   Z20190101)r   periodsr   r   Z3dr   r   r   r   r   z
2018-12-27z
2018-12-29z
2018-12-31z
2018-12-28z
2018-12-30r   rz   r   )r   r[   r   r.   r5   rE   r   r$   r   r   r   r   r<   r=   r   r   r   r   $test_groupby_rolling_count_closed_onb  s<    

	
  





z0TestRolling.test_groupby_rolling_count_closed_on)r   kwargsr5   r   r   	expandingc                 C   s   t ddgddgddgddgddggddgd}t|d|f | }t tjgd tjdtjddgd	tjd
ddddgdd gdd}|jdd}t	
|| d S )Nr   r   r   r   r   r   rs   g&?r   r   r   )r   r   )r   r   r   rP   rz   r   )r   rU   r.   Zsemr$   r   r   r   rY   r<   r]   )r/   r   r  r   rA   r@   r   r   r   test_groupby_rolling_sem  s       z$TestRolling.test_groupby_rolling_sem)rollingskeyr   r   Nr\   c              	   C   sp   t tddtjgdddgdddgd}|dkr:|d}tjt| d	d
 |dj	d| W 5 Q R X d S )Nz2020-06-01 12:00z2020-06-01 14:00r   r   r   r   r\   r   z values must not have NaTr(   r   60min)r  )
r   r   r$   r   r~   r+   r,   
ValueErrorr.   r5   )r/   r	  r
  r   r   r   r   "test_groupby_rolling_nans_in_index  s    
z.TestRolling.test_groupby_rolling_nans_in_indexrO   c                 C   s   dddgdddgg}t j|dd}tdddg|d}|jd	d
g|dd }tdddgt jdddgd	d
d	d
gdd}t|| d S )Nval1val2ru   rv   rz   r   r   r   r   ru   rv   rN   r   r   r   )r  r  r  r  )r  r  r  r  )	r   rZ   r   r.   r5   r6   r   r<   r=   )r/   rO   arraysr\   srA   r@   r   r   r   test_groupby_rolling_group_keys  s    
z+TestRolling.test_groupby_rolling_group_keysc                 C   s   dddgdddgg}t j|dd}tdddgtdd|d	}|d
dgd }tddddgit jdddgd
dd
dgdd	}t	|| d S )Nr  r  r  rz   r   r   r   r"   r   ru   r   r   r   r   r   )r  r   r  r  )r  r   r  r  rv   )
r   rZ   r   r[   r.   r5   r6   r   r<   r]   r/   r  r\   r   rA   r@   r   r   r   1test_groupby_rolling_index_level_and_column_label  s    
z=TestRolling.test_groupby_rolling_index_level_and_column_labelc              	   C   sd   t tdddgd d}|dd }tjdd	d
dddddgdd gd}t	|j
| d S )Nr   r   r   rP   r   r   r   r   r   )r   rP   )r   ry   r   r   )r   rs   )r   r   rz   )r   r$   r%   r.   r5   r6   r   r   r<   assert_index_equalr\   r/   r   rA   r_   r   r   r   )test_groupby_rolling_resulting_multiindex  s    z5TestRolling.test_groupby_rolling_resulting_multiindexc                 C   s   t tdddgd ddddgd d}|dd	gd }tjd
dddddddddddgdd	d gd}t	|j
| d S )Ng      (@r   r   ry   r   rP   r   r   r   )r   r   r   )r   r   rP   )r   r   r    )r   r   r   )r   r   ry   )r   r   rr   )r   r   r   )r   r   rs   )r   r   r   )r   rP   r   )r   rP   r   )r   rP   r   rz   )r   r$   r%   r.   r5   rI   r   r   r<   r  r\   r  r   r   r   *test_groupby_rolling_resulting_multiindex2  s&    *z6TestRolling.test_groupby_rolling_resulting_multiindex2c              	   C   s   t tdddgd ddddgd d}|jddd	}|d
d }tjddddddddgd
d dgd}t	j
|j|dd d S )Nr   r   r   rP   r   r   r   T)appendr   )r   r   r   )r   r   r   )r   rP   r   )r   ry   r   )r   r   r   )r   r   rP   )r   rs   r   )r   r   rP   rz   equiv)exact)r   r$   r%   r~   r.   r5   r6   r   r   r<   r  r\   r  r   r   r   *test_groupby_rolling_resulting_multiindex3  s     *
z6TestRolling.test_groupby_rolling_resulting_multiindex3c                 C   sJ   |j ddd}|dd j}|jdd}|dd j}t|| d S )	Nr   FrN   c                 S   s   |  d S rS   r5   rI   r7   r   r   r   r9     r:   zUTestRolling.test_groupby_rolling_object_doesnt_affect_groupby_apply.<locals>.<lambda>rP   rQ   c                 S   s   |  d S rS   r  r7   r   r   r   r9     r:   )r.   r;   r\   r5   r<   r  )r/   r&   r>   r@   _rA   r   r   r   7test_groupby_rolling_object_doesnt_affect_groupby_apply
  s
    zCTestRolling.test_groupby_rolling_object_doesnt_affect_groupby_apply)rR   rD   r   r@   r   r   rightr   c                 C   s   t ddddddddg}|ddddddddgj|||d	d
}t tj|ddttddgd
dddddddggd
d
d
d
ddddgd
dddddddggdd}t|| d S )Nr   r   r   rP   rs   ry   r   r    )rR   rD   r   r   r   r   )Zlevelscodesr   )	r   r.   r5   rb   r$   r  r   r<   r]   )r/   rR   rD   r   r@   r   rA   Zexpected_resultr   r   r   test_groupby_rolling_var  s"    
   &z$TestRolling.test_groupby_rolling_varr}   )r    )r   r   r   r   c                 C   s|   t ddggd ddggd  ddggd  |d}|d	}|jjd
d}|d}| }d	|jksjtt	|j| d S )Nr   r   r   r   r   r   r    r   r   T)deeprP   )
r   r.   objr   r5   rI   r}   AssertionErrorr<   r]   )r/   r}   r   r>   Zoriginal_objrF   rA   r   r   r   test_by_column_not_in_values+  s    2

z(TestRolling.test_by_column_not_in_valuesc                 C   s   ddddgddddgg}t j|dd}tddd	d
dgi|d}|jddd d }ttjdtjdgt j	ddddgdddgddd}t
|| d S )NFalconParrotCaptiveWild)AnimalTyperz   z	Max Speedg     `x@g     u@g      >@g      4@r   r   rw   r   g      @g      I@)r)  r)  r+  )r)  r)  r,  )r*  r*  r+  )r*  r*  r,  r-  r.  r   )r   rZ   r   r.   r5   rI   r   r$   r   r   r<   r=   r  r   r   r   test_groupby_level8  s&    

	zTestRolling.test_groupby_levelzby, expected_datar   num      Y@     b@      i@
2018-01-01
2018-01-02     @o@)r   r0  c                    s   dddgdddgdddgdddgg}t |d	d
dgd t d
  d
<  d
g  fdd|D } j|ddjddd }d	ddddgi}|| t | jd}t	|| d S )Nr   r4  r1  r5  r3  r   r2  r6  r   r   r0  r   c                    s   g | ]}t  |qS r   )rU   )r   attrr   r   r   r   n  s     z3TestRolling.test_as_index_false.<locals>.<listcomp>F)Zas_indexr   r   r   r   )
r   r   r~   r.   r5   r6   updater\   r<   r]   )r/   r3   r   r   Zgp_byrA   r@   r   r   r   test_as_index_falseP  s$    
zTestRolling.test_as_index_falsec           
      C   s   t |j}d}t |d|}d|d< d}t ||}t j|d< d|d< t||dd}|dd jd	dd
	 }t
|dttdgd dg |ddtdgd dg |ddgd}	t||	 d S )N  r   r   g52DE)r\   adl2r\   r<  rr   r   i  )r   r   r   )r$   r   typerepeatr   r   r~   r.   r5   r6   r   r   rZ   r   r<   r=   )
r/   Zany_int_numpy_dtypetypsizeidxvalZarrr   rA   r@   r   r   r   test_nan_and_zero_endpoints{  s4    

z'TestRolling.test_nan_and_zero_endpointsc              	      sX   ddddg}d t  fdd|D }tjtdd	 |d
jddd W 5 Q R X d S )Nr   r   r   r   r:  c                    s(   g | ] }t d |   |d ddqS )r   r   *   )tr8   r   r   r   secr   r   r     s     zBTestRolling.test_groupby_rolling_non_monotonic.<locals>.<listcomp>z.* must be monotonicr(   r   rE  Z3s)r   rR   )r   r+   r,   r  r.   r5   )r/   Zshuffledr   r   rG  r   "test_groupby_rolling_non_monotonic  s    z.TestRolling.test_groupby_rolling_non_monotonicc                 C   s   dddgdddgdddgdddgd	d
dgd	ddgd	ddgdddgdddgdddgg
}t |dddgd}t|d |d< |d}|dddd }|djdddd  }t	|| d S )NZDavidz1/1/2015d   z1/5/2015i  z	5/30/20152   z	7/25/2015ZRyanz1/4/2014z	1/19/2015z	3/31/2016ZJoez7/1/2015z9/9/2015z
10/15/2015r   r   amount)r   r}   c                 S   s   |  dd  S )N180DrL  r  r7   r   r   r   r9     r:   z4TestRolling.test_groupby_monotonic.<locals>.<lambda>rM  r   )
r   r   Zsort_valuesr~   r.   r;   r5   rI   r<   r=   )r/   r   r   r@   rA   r   r   r   test_groupby_monotonic  s,    

z"TestRolling.test_groupby_monotonicc                 C   s   t dddd}tdgd dgd  dgd	  t||ftd
d}|dddd }|djdddj	
 }t|| d S )Nz2016-01-01 09:30:00r   r  )r   r  freqr   r   r   r   r    r!   r   r   r   c                 S   s   |  dd  S )N4sr   r4   r7   r   r   r   r9     r:   zJTestRolling.test_datelike_on_monotonic_within_each_group.<locals>.<lambda>rP  r   )r   r   r$   Zconcatenater%   r~   r.   r;   r5   r   r6   r<   r=   )r/   datesr   r@   rA   r   r   r   ,test_datelike_on_monotonic_within_each_group  s    	z8TestRolling.test_datelike_on_monotonic_within_each_groupc              	   C   sd   t dgd dgd  dd dD d tdd}tjtd	d
 |djddd W 5 Q R X d S )Nr   r   r   c                 S   s   g | ]}t |d d qS )r   rF  )r   yearr   r   r   r     s     zPTestRolling.test_datelike_on_not_monotonic_within_each_group.<locals>.<listcomp>)i  i  r   ry   r   z&Each group within B must be monotonic.r(   r   Z365Dr   r   )r   r[   r+   r,   r  r.   r5   )r/   r   r   r   r   0test_datelike_on_not_monotonic_within_each_group  s    z<TestRolling.test_datelike_on_not_monotonic_within_each_group)3r   r   r   r1   rB   rG   r+   markparametrizer`   rd   rn   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(  r/  r   r9  rC  rI  rN  rR  rT  r   r   r   r   r'   0   s   

 



&
 
A#

 
 

	
 



 r'   c                
   @   s   e Zd Zejdd Zejddddddd	d
gdd Zejdddgdd Z	ejddddddgdd Z
ejdddgdd Zdd ZdS ) TestExpandingc                 C   s.   t dgd dgd  dgd  tddS r   r#   )r/   r   r   r   frame  s    zTestExpanding.framerH   rI   r6   rJ   rK   rE   rL   rM   c                    sn   |j ddd}| }t|  }| fdd}|jddd}t|d tdg}||_t	
|| d S )	Nr   FrN   c                    s   t |    S r   rU   r  r7   rV   r   r   r9     r:   z.TestExpanding.test_expanding.<locals>.<lambda>r   rW   r!   r.   r  rU   r;   rY   r   rZ   r[   r\   r<   r]   r/   rH   rX  r>   rF   rA   r@   r_   r   rV   r   test_expanding  s    zTestExpanding.test_expandingra   rb   c                    sr   |j ddd}| }t| dd}| fdd}|jddd	}t|d td
g}||_t	
|| d S )Nr   FrN   r   rc   c                    s   t |   ddS )Nr   rc   rY  r7   rV   r   r   r9     r:   z3TestExpanding.test_expanding_ddof.<locals>.<lambda>r   rW   r!   rZ  r[  r   rV   r   test_expanding_ddof  s    z!TestExpanding.test_expanding_ddofre   rf   rg   rh   ri   rj   c                    sp   |j ddd}| }|jd d}| fdd}|jddd	}t|d td
g}||_t	
|| d S )Nr   FrN   rk   rl   c                    s   |   jd dS )Nrk   rl   )r  rm   r7   rl   r   r   r9     r:   z7TestExpanding.test_expanding_quantile.<locals>.<lambda>r   rW   r!   )r.   r  rm   r;   rY   r   rZ   r[   r\   r<   r]   )r/   re   rX  r>   rF   rA   r@   r_   r   rl   r   test_expanding_quantile
  s    
z%TestExpanding.test_expanding_quantilero   rp   c           
         s    d}| }t| } fdd}||}ttddttdd }tj|j|df< tj|d< t	
|| t|j d	d
} fdd}	||	}t	|| d S )Nr   c                    s   t |   S r   rY  r7   rH   rX  r   r   func_0#  s    z5TestExpanding.test_expanding_corr_cov.<locals>.func_0r   =   H   q   r   Tr   c                    s   t | j  ddS )NTr   )rU   r   r  r7   rV   r   r   func_12  s    z5TestExpanding.test_expanding_corr_cov.<locals>.func_1)r.   r  rU   r;   r   r[   r$   r   Zilocr<   r]   r   r=   )
r/   rH   rX  r>   rF   rA   r`  r@   Znull_idxrd  r   r_  r   test_expanding_corr_cov  s    



z%TestExpanding.test_expanding_corr_covc                    st   |j ddd}| }|jdd  d}| fdd}|jddd	}t|d td
g}||_t	|| d S )Nr   FrN   c                 S   s   |   S r   r   r7   r   r   r   r9   =  r:   z4TestExpanding.test_expanding_apply.<locals>.<lambda>r   c                    s   |   jdd  dS )Nc                 S   s   |   S r   r   r   r   r   r   r9   >  r:   zFTestExpanding.test_expanding_apply.<locals>.<lambda>.<locals>.<lambda>r   )r  r;   r7   r   r   r   r9   >  r:   r   rW   r!   )
r.   r  r;   rY   r   rZ   r[   r\   r<   r]   )r/   r   rX  r>   rF   rA   r@   r_   r   r   r   test_expanding_apply8  s    z"TestExpanding.test_expanding_applyN)r   r   r   r+   fixturerX  rU  rV  r\  r]  r^  re  rf  r   r   r   r   rW    s"   
 

 

rW  c                
   @   s   e Zd Zejddddddggdejdd	d
ggdejdddgggdd Zejddejdddggdejdddgggdd Z	dd Z
dd Zdd ZdS ) TestEWMzmethod, expected_datar6   r   gUUUUUU?gm۶m?g""""""@ra   g۞?g?gt ?rb   rq   gn۶m۶?g++?c                 C   sh   t dgd tdd}t|djdd| }t d|itjdd	d
dgdd gdd}t|| d S )Nr   rP   r"   r   r   comr   r   r   r   r   rz   r   )	r   r[   rU   r.   ewmr   r   r<   r]   r/   methodr   r   rA   r@   r   r   r   test_methodsH  s    
zTestEWM.test_methodsro   r   r   rp   grڶ?g߿yq+?c                    s   t dgd tdd}t|djdd  }t d|itjdd	d
dgdd d gdd}t|| |d	 fdd}t|| d S )Nr   rP   r"   r   r   ri  r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   rz   r   c                    s   t | jdd  S )Nr   ri  )rU   rk  r7   rm  r   r   r9   x  r:   z/TestEWM.test_pairwise_methods.<locals>.<lambda>)
r   r[   rU   r.   rk  r   r   r<   r]   r;   rl  r   ro  r   test_pairwise_methodsb  s     zTestEWM.test_pairwise_methodsc                 C   s|   d}| d}|dj||d }tddddd	dd
ddddg
itjddddddddddg
dd gdd}t|| d S )N23 daysr   r   halflifetimesr   r   gCus=?g;pGR?gZkB?g>(?g8Kr?gҧU?gA9w?r   r   )r   ry   )r   r   )r   r   r  r   )r   r   )r   rs   )r   r    rz   r   )	popr.   rk  r6   r   r   r   r<   r]   )r/   r   rs  rt  rA   r@   r   r   r   
test_times{  sB    
zTestEWM.test_timesc                 C   sN   d}| d}|d}|j||d }|j||jd }t|| d S )Nrq  r   r   rr  )ru  r.   rk  r6   valuesr<   r]   )r/   r   rs  rt  r   rA   r@   r   r   r   test_times_array  s    

zTestEWM.test_times_arrayc              	   C   s   t dddddgtddddtdd}|djd	d
d}| }t tdddddgd dtjdddddgttdgdd gdd}t	
|| |d  }tdgd tjdddddgtddddgdd
gddd}t	|| | }t	
|| d S )Nr   r   z2021-9-1rs   r   )r  rO  )r   	timestampr   r   Z1Hry  r   r   )ry  r   rz   r   r   r   )r   r   r[   r.   r5   rE   r   rZ   r   r<   r]   r   r=   )r/   r   grprA   Zexpected_dfZexpected_seriesr   r   r   "test_dont_mutate_obj_after_slicing  s@     	z*TestEWM.test_dont_mutate_obj_after_slicingN)r   r   r   r+   rU  rV  r$   r   rn  rp  rv  rx  r{  r   r   r   r   rh  G  s    
"
'	rh  )numpyr$   r+   Zpandasr   r   r   r   r   r   r   Zpandas._testingZ_testingr<   Zpandas.api.indexersr	   Zpandas.core.groupby.groupbyr
   rg  r   r&   r'   rW  rh  r   r   r   r   <module>   s&   $	

       >`