a
    Pf                     @   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
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d Zdd ZdS )    N)	DataFrameDatetimeIndexIndex
MultiIndexSeries	Timestamp
date_rangeto_datetime)BaseIndexer)get_groupbyc                   C   s    t g dg dtg ddS )z0Frame for testing times argument in EWM groupby.)
abcr   r   r   r   r   r   r   )
r   r   r      r   r      r   r      )

2020-01-01r   r   z
2020-01-02
2020-01-10z
2020-01-22z
2020-01-03
2020-01-23r   z
2020-01-04ABC)r   r	    r   r   Y/var/www/ai-form-bot/venv/lib/python3.9/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                   @   sD  e Zd Zdd Zdd Zdd Zejdg dd	d
 Z	ejdddgdd Z
ejdg d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%d& Zejd'dd(gd)d*ggd+d, Zd-d. Zd/d0 Zejd1g d2d3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Zejd=d>d?gd@dA ZdBdC ZdDdE ZdFdG ZdHdI ZejdJdKdLddMfdNi fgdOdP ZejdQdRdSidSfdRdTidUfgdVdW Z ejdXd(d*gdYdZ Z!d[d\ Z"d]d^ Z#d_d` Z$dadb Z%dcdd Z&ejdedLdfdgg dhfdLdLdgg difdjdjdgg dkfdjdjdlg dmfgdndo Z'ejdpe()dqdrgdsdtggdudv Z*dwdx Z+ejdydzgd{g d|igdzdUge,d}e,d~e,d}e,d~gg ddggdd Z-dd Z.dd Z/dd Z0dd Z1dd Z2dTS )TestRollingc                 C   sD   d}t jt|d |jddd W d    n1 s60    Y  d S )Nz4groupby\(\) got an unexpected keyword argument 'foo'matchr   r   )foo)pytestraises	TypeErrorgroupby)selfr%   msgr   r   r   !test_groupby_unsupported_argument2   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   applyr4   r5   tmassert_series_equalr   )r.   r%   g	g_mutatedexpectedresultr   r   r   test_getitem7   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_periodsr1   c                 S   s   | j ddd S )Nr   r   rB   )r4   countr6   r   r   r   r8   N   r9   z3TestRolling.test_getitem_multiple.<locals>.<lambda>)r-   r4   r   r   r:   rD   r;   r<   )r.   r%   r=   rr>   r?   r@   r   r   r   test_getitem_multipleI   s    


z!TestRolling.test_getitem_multiplefsumr5   minmaxrD   ZkurtZskewc           	         s   |j ddd}|jdd}t|  }d}tjt|d" | fdd	}W d    n1 s`0    Y  |jdd
d}t	|d t
dg}||_t|| d S )Nr   F
group_keys   window7DataFrameGroupBy.apply operated on the grouping columnsr'   c                    s   t | d  S NrN   getattrr4   r6   rG   r   r   r8   i   r9   z*TestRolling.test_rolling.<locals>.<lambda>r   Zaxisr    r-   r4   rT   r;   assert_produces_warningDeprecationWarningr:   dropr   from_arraysrangeindexassert_frame_equal	r.   rG   r%   r=   rE   r@   r/   r?   expected_indexr   rU   r   test_rollingV   s    0zTestRolling.test_rollingstdvarc           	         s   |j ddd}|jdd}t| dd}d}tjt|d	" | fd
d}W d    n1 sd0    Y  |jddd}t	|d t
dg}||_t|| d S )Nr   FrL   rN   rO   r   ZddofrQ   r'   c                    s   t | d ddS )NrN   r   rd   rS   r6   rU   r   r   r8   y   r9   z/TestRolling.test_rolling_ddof.<locals>.<lambda>rV   r    rW   r_   r   rU   r   test_rolling_ddofq   s    0zTestRolling.test_rolling_ddofinterpolationZlinearlowerZhigherZmidpointZnearestc           	         s   |j ddd}|jdd}|jd d}d}tjt|d	" | fd
d}W d    n1 sb0    Y  |jddd}t	|d t
dg}||_t|| d S )Nr   FrL   rN   rO   皙?rf   rQ   r'   c                    s   |  djd dS )NrN   ri   rj   )r4   quantiler6   rj   r   r   r8      r9   z3TestRolling.test_rolling_quantile.<locals>.<lambda>r   rV   r    )r-   r4   rk   r;   rX   rY   r:   rZ   r   r[   r\   r]   r^   )	r.   rf   r%   r=   rE   r@   r/   r?   r`   r   rj   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  g dd dddg}t tdg d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g ddd}t|| d S )N
   r      r   )r   r   r   rN   rq   )valueidx1idx2rs   rt   )rr   rt   r   levelrN   rr      )rs   rs   rt   namescolumnsr]   )r   r\   	set_indexrT   r-   r4   r#   nanr   r[   listr;   r^   )r.   rG   Zexpected_valdfotherr@   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           	         s    d}|jdd}t| } fdd}d}tjt|d ||}W d    n1 sd0    Y  tj|d< t	|| d S )Nr   rN   rO   c                    s   t | d S rR   rS   r6   rG   r%   r   r   func   s    zITestRolling.test_rolling_corr_cov_other_diff_size_as_groups.<locals>.funcrQ   r'   )
r-   r4   rT   r;   rX   rY   r:   r#   r}   r^   	r.   rG   r%   r=   rE   r@   r   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           	         s   | d}|jdd}t|j dd} fdd}d}tjt|d	 ||}W d    n1 sf0    Y  t|| d S )
Nr   rN   rO   Tpairwisec                    s   t | jd ddS )NrN   Tr   )rT   r   r4   r6   rU   r   r   r      s    z8TestRolling.test_rolling_corr_cov_pairwise.<locals>.funcrQ   r'   )	r-   r4   rT   r   r;   rX   rY   r:   r<   r   r   rU   r   test_rolling_corr_cov_pairwise   s    
(z*TestRolling.test_rolling_corr_cov_pairwisezfunc, expected_values      ?      @c                 C   s   t g dg dg d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g dg ddd}t	|| d S )N)g1g2r   r   )r   r   r   r   )r   r   rw   rN   r   r   r   r   r   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   NNrx   r]   )
r   r-   r4   rT   r#   r}   r   from_tuplesr;   r^   )r.   r   Zexpected_valuesr   Zrolr@   r?   r   r   r   test_rolling_corr_cov_unordered   s$    
z+TestRolling.test_rolling_corr_cov_unorderedc           	         s   |j ddd}|jdd}|jdd  d}d	}tjt|d
" | fdd}W d    n1 sf0    Y  |jddd}t|d t	dg}||_
t|| d S )Nr   FrL   rN   rO   c                 S   s   |   S NrI   r6   r   r   r   r8      r9   z0TestRolling.test_rolling_apply.<locals>.<lambda>rawrQ   r'   c                    s   |  djdd  dS )NrN   c                 S   s   |   S r   r   yr   r   r   r8      r9   zBTestRolling.test_rolling_apply.<locals>.<lambda>.<locals>.<lambda>r   )r4   r:   r6   r   r   r   r8      r9   r   rV   r    )r-   r4   r:   r;   rX   rY   rZ   r   r[   r\   r]   r^   )	r.   r   r%   r=   rE   r@   r/   r?   r`   r   r   r   test_rolling_apply   s    0zTestRolling.test_rolling_applyc                 C   s   t dgd dgd  dgd d}|d}tg d}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   rw   r!   r   ))r   r   )r   rN   )r   rq   )r)   r   )r)   r   )r)   r          @r   r   rz   rO   )r   r-   r   r   ry   r#   r}   r4   rI   r;   r^   )r.   r   r=   mir?   r@   r   r   r   test_rolling_apply_mutability  s    $

z)TestRolling.test_rolling_apply_mutabilityzexpected_value,raw_valueT        Fc                 C   sl   dd }t g dg d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ndarrayr6   r   r   r   isnumpyarray  s    z6TestRolling.test_groupby_rolling.<locals>.isnumpyarrayr   r   r   r   r   r   )idrr   r   r   r   r   )r   r   r   r   r   r   rx   rr   r]   name)
r   r-   rr   r4   r:   r   r   r   r;   r<   )r.   Zexpected_valueZ	raw_valuer   r   r@   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   rw   Tr   )centerrP   rq   )r   r   r   r   r   rN   r   )rq   rN   r   rN   )r   r   r   r   r   r      r   r   r      r   	   )r   r   r   r   r   r   r   r   r   rN   r   rq   r   rw   r   r   r   r   r   r   )r   rp   rx   )r]   r{   rp   )
r   r   r   r   r   r   r   r   r   r   )r   r\   r-   r4   r5   r#   r}   r   r   r;   r<   r   r^   )r.   Zseriesr@   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j|d
 |d gd
dgd}t	g dd|d}t
|| d S )Nr   r   group_1rw   group_2rN   rp   )Dategbrr   )datar   r   Tr   )onr   rC   rx   )
r         ?r   g      @      @g      @      @      @r   r   rr   r   r]   )r   r   r\   r-   r4   rr   r5   r   r[   r   r;   r<   )r.   r   r@   r   r?   r   r   r   test_groupby_rolling_center_onk  s"    

z*TestRolling.test_groupby_rolling_center_onrC   )rq   rN   r   c                 C   s   t dgd dgd  tdd}d}|dj|d|d	 }| dd
g }g d}dd |D }td|d }tjg| }|||d|   | }	|||d|   | }
t dgd dgd  |	|
 d}t	
|| d S )Nr   rp   r   r   )groupr   rq   r   T)r   rC   r   )
r   r   r   r   r         @g      @r   r          @c                 S   s   g | ]}|d  qS )g      $@r   .0r7   r   r   r   
<listcomp>  r9   zGTestRolling.test_groupby_rolling_center_min_periods.<locals>.<listcomp>r   r   )r   r\   r-   r4   r5   Zreset_indexrK   r#   r}   r;   r^   )r.   rC   r   window_sizer@   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 g dg dg d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 )N)r   r   r   r   )r   r   r   r   )rp   r      r   r   r   r   r   r   )r   r   r   r   r   rx   rz   r   )r   r-   r4   rK   r#   r}   r   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g d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 u 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_valuesrC   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   rq   r   r   r   )r   rB   rP   rC   )r
   r   r-   r]   r4   rI   r;   r^   )r.   r   r   r@   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gd dgd  dd dD d d	}|d
jddddd  }ttjtjddtjtjddgtj	|d
dg d
dgddd}t
|| d S )Nr   r   rN   r   c                 S   s   g | ]}t |qS r   r   r   dater   r   r   r     s   zGTestRolling.test_groupby_rolling_subset_with_closed.<locals>.<listcomp>
2019-01-01r   
2019-01-02r   r   column1Zcolumn2r   r   r   1Dr   leftr   r   r   r         "@rx   r   r   r\   r-   r4   rI   r   r#   r}   r   Z
from_framer;   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gd dgd  dd dD d d	}|d
ddg jddddd  }ttjtjddtjtjddgtj	|d
dg d
dgddd}t
|| d S )Nr   r   rN   r   c                 S   s   g | ]}t |qS r   r   r   r   r   r   r     s   zNTestRolling.test_groupby_subset_rolling_subset_with_closed.<locals>.<listcomp>r   r   r   r   r   r   r   r   r   r   r   rx   r   r   r   r   r   r   .test_groupby_subset_rolling_subset_with_closed  s4    
z:TestRolling.test_groupby_subset_rolling_subset_with_closedr   rK   rJ   c                 C   sv   t g dtjg dddgddd}t||d| }t tjtjd	gtjg d
g dddd}t	|| d S )N)r   r   r   ))r   r7   )r   r   )r   z12rx   r   r   r   r   ))r   r   r7   )r   r   r   )r   r   r   )r   r   r   )
r   r   r   rT   r-   r4   r#   r}   r;   r<   )r.   r   Zdsr@   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g dd|_t	
|| d S )Ns1r   rO   r{   float64r   r   rx   )r   s2r   )r   r   N)r   r-   r4   rI   rZ   r   Zfrom_productr   r]   r;   r^   )r.   r?   r@   r   r   r    test_groupby_rolling_empty_frame  s$    


z,TestRolling.test_groupby_rolling_empty_framec                 C   s0  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g d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g ddddg}t|| d S )Nr   r     r   r   r   r   Zr   r   Hrw   Er   )r]   r   	eventTimer   r]   r   count_to_dateZ10dr   r   c                 S   s
   | j d S )Nr   )shaper   r   r   r   r8   J  r9   z?TestRolling.test_groupby_rolling_string_index.<locals>.<lambda>r   r   r   )r]   r   r   r  )	r   r   r|   r-   Zcumcountr4   r:   r;   r^   )r.   r   groupsZrolling_groupsr@   r?   r   r   r   !test_groupby_rolling_string_index:  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   rx   rz   r   )r   r-   r4   rJ   r#   arrayr   r   rZ   r;   r^   )r.   r@   r?   r   r   r   test_groupby_rolling_no_sortW  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g dd| dd}tjg d|gdd
gd}t	t
jddt
jddgd|d}t|| d S )Nrw   r   r   r   Z20190101)r   periodsunitr   r   Z3dr   r   r   r   )z
2018-12-27z
2018-12-29z
2018-12-31z
2018-12-28z
2018-12-30r   M8[]r   )r   r   r   r   r   r   rx   r   r   )r   r\   r   r-   r4   rD   r   r   r[   r   r#   r}   r;   r<   )r.   r  r   r@   Zdtir   r?   r   r   r   $test_groupby_rolling_count_closed_onh  s:    
	

z0TestRolling.test_groupby_rolling_count_closed_on)r   kwargsr4   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 i | }t tjgd tjdtjddgd	tjg d
dd gdd}|jdd}t	
|| d S )Nr   r   r   r   r   r   rq   g&?r   )r   r   )r   r   )r   r   r   rN   rx   r   )r   rT   r-   Zsemr#   r}   r   r   rZ   r;   r^   )r.   r   r  r   r@   r?   r   r   r   test_groupby_rolling_sem  s    &z$TestRolling.test_groupby_rolling_sem)rollingskeyr   r   Nr]   c                 C   s   t tddtjgg dg dd}|dkr6|d}tjt| dd	& |d
j	di | W d    n1 sv0    Y  d S )Nz2020-06-01 12:00z2020-06-01 14:00r   r   r   r]   r   z values must not have NaTr'   r   60min)r  )
r   r	   r#   r}   r|   r*   r+   
ValueErrorr-   r4   )r.   r  r  r   r   r   r   "test_groupby_rolling_nans_in_index  s    
z.TestRolling.test_groupby_rolling_nans_in_indexrM   c                 C   s|   g dg dg}t j|dd}tg d|d}|jddg|dd	 }tg d
t jg dg ddd}t|| d S )Nval1r  val2rs   rt   rx   r   r   rs   rt   rL   r   )r   r   r   )r  r  r  r  r  )r  r  r  r  )rs   rt   rs   rt   )	r   r[   r   r-   r4   r5   r   r;   r<   )r.   rM   arraysr]   sr@   r?   r   r   r   test_groupby_rolling_group_keys  s    z+TestRolling.test_groupby_rolling_group_keysc                 C   s   g dg dg}t j|dd}tg dtdd|d}|dd	gd
 }tdg dit jg dg ddd}t	|| d S )Nr  r  rx   )r   r   r   r   r!   r   rs   r   r   r   )r   r   r   )r  r   r  r  r   )r  r   r  r  )rs   r   rs   rt   )
r   r[   r   r\   r-   r4   r5   r   r;   r^   r.   r  r]   r   r@   r?   r   r   r   1test_groupby_rolling_index_level_and_column_label  s    
z=TestRolling.test_groupby_rolling_index_level_and_column_labelc                 C   sX   t tdddgd d}|dd }tjg ddd gd	}t	|j
| d S )
Nr   r   r   rN   r   r   r   )r   r   )r   rN   )r   rw   r   r   )r   rq   )r   r   rx   )r   r#   r$   r-   r4   r5   r   r   r;   assert_index_equalr]   r.   r   r@   r`   r   r   r   )test_groupby_rolling_resulting_multiindex  s    z5TestRolling.test_groupby_rolling_resulting_multiindexc                 C   sf   t tdddgd g dd d}|dd	gd }tjg d
g dd}t	|j
| d S )Ng      (@r   r   rw   r   r   r   rN   r   r   r   r   ))r   r   r   )r   r   rN   )r   r   r   )r   r   r   )r   r   rw   )r   r   rp   )r   r   r   )r   r   rq   )r   r   r   )r   rN   r   )r   rN   r   )r   rN   r   )r   r   Nrx   )r   r#   r$   r-   r4   rI   r   r   r;   r#  r]   r$  r   r   r   *test_groupby_rolling_resulting_multiindex2  s    &z6TestRolling.test_groupby_rolling_resulting_multiindex2c                 C   st   t tdddgd g dd d}|jddd	}|d
d }tjg dg dd}t	j
|j|dd d S )Nr   r   r   rN   r&  r   r   T)appendr   r   ))r   r   r   r   )r   rN   r   )r   rw   r   )r   r   r   )r   r   rN   )r   rq   r   )r   r   rN   )r   Nr   rx   equiv)exact)r   r#   r$   r|   r-   r4   r5   r   r   r;   r#  r]   r$  r   r   r   *test_groupby_rolling_resulting_multiindex3  s    &
z6TestRolling.test_groupby_rolling_resulting_multiindex3c                 C   s   |j ddd}d}tjt|d  |dd j}W d    n1 sF0    Y  |jdd	}d}tjt|d  |d
d j}W d    n1 s0    Y  t|| d S )Nr   FrL   rQ   r'   c                 S   s   |  d S rR   r4   rI   r6   r   r   r   r8     r9   zUTestRolling.test_groupby_rolling_object_doesnt_affect_groupby_apply.<locals>.<lambda>rN   rO   c                 S   s   |  d S rR   r,  r6   r   r   r   r8   !  r9   )r-   r;   rX   rY   r:   r]   r4   r#  )r.   r%   r=   r/   r?   _r@   r   r   r   7test_groupby_rolling_object_doesnt_affect_groupby_apply  s    ..zCTestRolling.test_groupby_rolling_object_doesnt_affect_groupby_apply)rP   rC   r   r?   r   r   )Nr   r   r   Nr   r   r   )NNr   r   NNr   r   rN   )NNNNNNNNright)NNNr   NNNr   c                 C   sx   t g d}|g dj|||dd}t tj|ddttddgg d	gg d
g dgdd}t|| d S )N)r   r   r   rN   rq   rw   r   r   )r   r   r   r   r   r   r   r   )rP   rC   r   r   r   r   r   r   )r   r   r   r   rN   rq   rw   r   )r   r   r   r   r   r   r   r   )r   r   rN   rw   r   r   rq   r   )Zlevelscodesr   )	r   r-   r4   rc   r#   r  r   r;   r^   )r.   rP   rC   r   r?   r   r@   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vsjJ t|j| d S )Nr   r   r   r   r   r   r   r   r   T)deeprN   )	r   r-   objr   r4   rI   r{   r;   r^   )r.   r{   r   r=   Zoriginal_objrE   r@   r   r   r   test_by_column_not_in_values=  s    2

z(TestRolling.test_by_column_not_in_valuesc                 C   s   g dg dg}t j|dd}tdg di|d}|jdd	d d
 }ttjdtjdgt j	g dg dddd}t
|| d S )N)Falconr6  Parrotr7  )CaptiveWildr8  r9  )AnimalTyperx   z	Max Speed)g     `x@g     u@g      >@g      4@r   r   ru   r   g      @g      I@))r6  r6  r8  )r6  r6  r9  )r7  r7  r8  )r7  r7  r9  )r:  r:  r;  r   )r   r[   r   r-   r4   rI   r   r#   r}   r   r;   r<   r!  r   r   r   test_groupby_levelJ  s    	zTestRolling.test_groupby_levelzby, expected_datar   num)      Y@     b@r?        i@
2018-01-01
2018-01-02)r>  r@  r?       @o@)r   r=  c                    s   g dg dg dg dg}t |g dd  d d| d	 d<  dg  fd
d|D } j|ddjddd }dg di}|| t | jd}d|v r|d d| d	|d< t	|| d S )N)r   rA  r>  )r   rB  r@  )r   rA  r?  )r   rB  rC  )r   r   r=  r   r   r  r  c                    s   g | ]}t  |qS r   )rT   )r   attrr  r   r   r     r9   z3TestRolling.test_as_index_false.<locals>.<listcomp>F)Zas_indexr   r   r   r   )r   r   r   r   r   )
r   Zastyper|   r-   r4   r5   updater]   r;   r^   )r.   r2   r   r  r   Zgp_byr@   r?   r   r  r   test_as_index_falseb  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]   rI  rp   r   i  )r   r   r   )r#   r   typerepeatr}   r   r|   r-   r4   r5   r   r   r[   r   r;   r<   )
r.   Zany_int_numpy_dtypetypsizeidxvalZarrr   r@   r?   r   r   r   test_nan_and_zero_endpoints  s4    

z'TestRolling.test_nan_and_zero_endpointsc                    sh   g d}d t  fdd|D }tjtdd$ |djdd	d
 W d    n1 sZ0    Y  d S )N)r   r   r   r   rG  c                    s(   g | ] }t d |   |d ddqS )r   r   *   )tr7   r   r   r   secr   r   r     r9   zBTestRolling.test_groupby_rolling_non_monotonic.<locals>.<listcomp>z.* must be monotonicr'   r   rR  Z3s)r   rP   )r   r*   r+   r  r-   r4   )r.   Zshuffledr   r   rS  r   "test_groupby_rolling_non_monotonic  s    z.TestRolling.test_groupby_rolling_non_monotonicc                 C   s   g dg dg dg dg dg dg dg dg d	g d
g
}t |g dd}t|d |d< |d}d}tjt|d* |dddd }W d    n1 s0    Y  |dj	dddd 
 }t|| d S )N)Davidz1/1/2015d   )rV  z1/5/2015  )rV  z	5/30/20152   )rV  z	7/25/2015rY  )Ryanz1/4/2014rW  )rZ  z	1/19/2015rX  )rZ  z	3/31/2016rY  )Joez7/1/2015rW  )r[  z9/9/2015rX  )r[  z
10/15/2015rY  )r   r   amount)r   r{   r   rQ   r'   r   c                 S   s   |  dd  S )N180Dr\  r,  r6   r   r   r   r8     r9   z4TestRolling.test_groupby_monotonic.<locals>.<lambda>r]  r  r\  )r   r	   Zsort_valuesr;   rX   rY   r|   r-   r:   r4   rI   r<   )r.   r   r   r/   r?   r@   r   r   r   test_groupby_monotonic  s0    

 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}tjt|d* |d	d
dd }W d    n1 s0    Y  |	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   rQ   r'   r   r   c                 S   s   |  dd  S )N4sr   r3   r6   r   r   r   r8     r9   zJTestRolling.test_datelike_on_monotonic_within_each_group.<locals>.<lambda>r`  r  )r   r   r#   Zconcatenater$   r;   rX   rY   r|   r-   r:   r4   r   r5   r<   )r.   datesr   r/   r?   r@   r   r   r   ,test_datelike_on_monotonic_within_each_group  s"    
 z8TestRolling.test_datelike_on_monotonic_within_each_groupc                 C   sx   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 d    n1 sj0    Y  d S )Nr   r   r   c                 S   s   g | ]}t |d d qS r   r   )r   yearr   r   r   r     r9   zPTestRolling.test_datelike_on_not_monotonic_within_each_group.<locals>.<listcomp>)i  i  r   rw   r   z&Each group within B must be monotonic.r'   r   Z365Dr   r  )r   r\   r*   r+   r  r-   r4   )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   r0   rA   rF   r*   markparametrizera   re   rl   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.  r1  r   r   r5  r<  r   rF  rP  rU  r^  rb  re  r   r   r   r   r&   1   s   





&
 
A

(


	



"r&   c                   @   s   e Zd Zejdd Zejdg ddd Zejdddgd	d
 Z	ejdg d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.framerG   rH   c           	         s   |j ddd}| }t|  }d}tjt|d" | fdd}W d    n1 s\0    Y  |jddd	}t	|d t
d
g}||_t|| d S )Nr   FrL   rQ   r'   c                    s   t |    S r   rT   r  r6   rU   r   r   r8     r9   z.TestExpanding.test_expanding.<locals>.<lambda>r   rV   r    r-   r  rT   r;   rX   rY   r:   rZ   r   r[   r\   r]   r^   	r.   rG   ri  r=   rE   r@   r/   r?   r`   r   rU   r   test_expanding  s    0zTestExpanding.test_expandingrb   rc   c           	         s   |j ddd}| }t| dd}d}tjt|d" | fdd	}W d    n1 s`0    Y  |jdd
d}t	|d t
dg}||_t|| d S )Nr   FrL   r   rd   rQ   r'   c                    s   t |   ddS )Nr   rd   rj  r6   rU   r   r   r8      r9   z3TestExpanding.test_expanding_ddof.<locals>.<lambda>r   rV   r    rk  rl  r   rU   r   test_expanding_ddof  s    0z!TestExpanding.test_expanding_ddofrf   rg   c           	         s   |j ddd}| }|jd d}d}tjt|d" | fdd	}W d    n1 s^0    Y  |jdd
d}t	|d t
dg}||_t|| d S )Nr   FrL   ri   rj   rQ   r'   c                    s   |   jd dS )Nri   rj   )r  rk   r6   rj   r   r   r8   3  r9   z7TestExpanding.test_expanding_quantile.<locals>.<lambda>r   rV   r    )r-   r  rk   r;   rX   rY   r:   rZ   r   r[   r\   r]   r^   )	r.   rf   ri  r=   rE   r@   r/   r?   r`   r   rj   r   test_expanding_quantile(  s    
"z%TestExpanding.test_expanding_quantilerm   rn   c                    s   d}| }t| } fdd}d}tjt|d ||}W d    n1 s`0    Y  ttddttdd	 }	t	j
|j|	d
f< t	j
|d< t|| t|j dd} fdd}
d}tjt|d ||
}W d    n1 s0    Y  t|| d S )Nr   c                    s   t |   S r   rj  r6   rG   ri  r   r   func_0C  s    z5TestExpanding.test_expanding_corr_cov.<locals>.func_0rQ   r'   r   =   H   q   r   Tr   c                    s   t | j  ddS )NTr   )rT   r   r  r6   rU   r   r   func_1T  s    z5TestExpanding.test_expanding_corr_cov.<locals>.func_1)r-   r  rT   r;   rX   rY   r:   r~   r\   r#   r}   Zilocr^   r   r<   )r.   rG   ri  r=   rE   r@   rq  r/   r?   Znull_idxru  r   rp  r   test_expanding_corr_cov<  s"    
(
(z%TestExpanding.test_expanding_corr_covc           	         s   |j ddd}| }|jdd  d}d}tjt|d" | fd	d}W d    n1 sb0    Y  |jdd
d}t|d t	dg}||_
t|| d S )Nr   FrL   c                 S   s   |   S r   r   r6   r   r   r   r8   a  r9   z4TestExpanding.test_expanding_apply.<locals>.<lambda>r   rQ   r'   c                    s   |   jdd  dS )Nc                 S   s   |   S r   r   r   r   r   r   r8   e  r9   zFTestExpanding.test_expanding_apply.<locals>.<lambda>.<locals>.<lambda>r   )r  r:   r6   r   r   r   r8   e  r9   r   rV   r    )r-   r  r:   r;   rX   rY   rZ   r   r[   r\   r]   r^   )	r.   r   ri  r=   rE   r@   r/   r?   r`   r   r   r   test_expanding_apply\  s    
"z"TestExpanding.test_expanding_applyN)r   r   r   r*   fixtureri  rf  rg  rm  rn  ro  rv  rw  r   r   r   r   rh    s   




rh  c                
   @   s   e Zd Zejddg d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_datar5   )r   gUUUUUU?gm۶m?g""""""@rb   g۞?g?gt ?rc   ro   gn۶m۶?g++?c                 C   sd   t dgd tdd}t|djdd| }t d|itjg ddd gd	d
}t|| d S )Nr   rN   r!   r   r   comr   )r   r   r   r   rx   r   )	r   r\   rT   r-   ewmr   r   r;   r^   r.   methodr   r   r@   r?   r   r   r   test_methodsp  s    
zTestEWM.test_methodsrm   r   r   rn   grڶ?g߿yq+?c                    s   t dgd tdd}t|djdd  }t d|itjg dg d	d
d}t|| |ddg 	 fdd}t|| d S )Nr   rN   r!   r   r   rz  r   ))r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   NNrx   r   c                    s   t | jdd  S )Nr   rz  )rT   r|  r6   r~  r   r   r8     r9   z/TestEWM.test_pairwise_methods.<locals>.<lambda>)
r   r\   rT   r-   r|  r   r   r;   r^   r:   r}  r   r  r   test_pairwise_methods  s    
zTestEWM.test_pairwise_methodsc                 C   s\   d}| d}|dj||d }tdg ditjg ddd gdd	}t|| d S )
N23 daysr   r   halflifetimesr   )
r   gCus=?g;pGR?gZkB?r   g>(?g8Kr?r   gҧU?gA9w?)
r   r   )r   rw   )r   r   )r   r   r  r   )r   r   )r   rq   )r   r   rx   r   )	popr-   r|  r5   r   r   r   r;   r^   )r.   r   r  r  r@   r?   r   r   r   
test_times  s    
zTestEWM.test_timesc                 C   sN   d}| d}|d}|j||d }|j||jd }t|| d S )Nr  r   r   r  )r  r-   r|  r5   valuesr;   r^   )r.   r   r  r  r   r@   r?   r   r   r   test_times_array  s    

zTestEWM.test_times_arrayc              	   C   s   t g d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g dttdgdd gdd}t	
|| |d  }tdgd tjg dtddddgdd	gddd}t	|| | }t	
|| d S )N)r   r   r   r   r   z2021-9-1rq   h)r
  r_  )r   	timestampr   r   Z1hr  r  r   )r  r   rx   r   r   r   )r   r   r\   r-   r4   rD   r   r[   r~   r;   r^   r   r<   )r.   r   grpr@   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*   rf  rg  r#   r}   r  r  r  r  r  r   r   r   r   ry  o  s    

"
'	ry  c                  C   s   t g dg dd} | dg}|dj| d}tjg ddd gd}t tjtjtjgtjd	d	gd|d
}t	|| d S )N)rc  rc  rc  rN   rq   rw   r   r   r   r   ))rc  r   )rc  r   )rc  r   rx   r   r   
r   r-   r4   rm   r   r   r#   r}   r;   r^   r   r   r@   r]   r?   r   r   r   .test_rolling_corr_with_single_integer_in_index  s    r  c                  C   s   t g dg dd} | dg}|dj| d}tjg ddd gd}t tjtjtjgtjd	d	gd|d
}t	|| d S )N)r   r   r   r  r   r   r   r  ))r   r   )r   r   )r   r   rx   r   r   r  r  r   r   r   &test_rolling_corr_with_tuples_in_index	  s    r  )numpyr#   r*   Zpandasr   r   r   r   r   r   r   r	   Zpandas._testingZ_testingr;   Zpandas.api.indexersr
   Zpandas.core.groupby.groupbyr   rx  r   r%   r&   rh  ry  r  r  r   r   r   r   <module>   s,   (


       Wn 