o
    _~#g^                     @   s   d dl Zd dlZd dlm  m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 ejdd Zejdd ZG dd	 d	Zejd
ddgdd ggdd Zeddd ZdS )    N)	DataFrameDatetimeIndexIndex
MultiIndexNaTSeries	Timestamp
date_range)offsetsc                   C   s"   t tddddtdddS )N20130101   speriodsfreqABr   )r   r	   range	set_index r   r   /var/www/static.ux5.de/https/Moving-Object-Detection-with-OpenCV/env/lib/python3.10/site-packages/pandas/tests/window/test_timeseries_window.pyregular   s
   r   c                  C   s8   t dtdi} tdtdtdtdtdg| _| S )Nr   r   20130101 09:00:0020130101 09:00:0220130101 09:00:0320130101 09:00:0520130101 09:00:06)r   r   r   index)dfr   r   r   ragged   s   r    c                   @   s  e Zd Zdd Zdd Zejdde	dgdd	 Z
ejdd
eddgdd Zejdddeg dgdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Z d6d7 Z!d8d9 Z"d:d; Z#d<d= Z$ejd>d?d@dAgdB fd?dCdAgdD dEg fd?dFdAgdD dGg fdHd@dAgdB fdHdCdAgdD dEg fdHdFdAgdD dGg fd@d@dAgdB fd@dCdAgdD dEg fd@dFdAgdD dGg fdId@dAgdB fdIdCdAgdD dEg fdIdFdAgdD dGg fdJd@dAgdB fdJdCdAgdD dEg fdJdFdAgdD dGg fgdKdL Z%ejdMg dNdOdP Z&dQdR Z'dSdT Z(dUdV Z)dWdX Z*dYdZ Z+d[S )\TestRollingTSc                 C   sP   t ddddtjdgitdtdtdtd	td
gd}| |d  d S )Nr   r            r   r   r   r   r   r   2s)r   npnanr   rollingsumselfr   r   r   r   test_doc_string-   s   
zTestRollingTS.test_doc_stringc                 C   s   d}t jt|d |jdd W d    n1 sw   Y  d}t jt|d | jdd W d    d S 1 s<w   Y  d S )Nz@passed window foobar is not compatible with a datetimelike indexmatchfoobarwindowwindow must be an integer)pytestraises
ValueErrorr)   reset_index)r,   r   msgr   r   r   test_invalid_window_non_int;   s   "z)TestRollingTS.test_invalid_window_non_intr   2MSr#   c                 C   sD   d}t jt|d |j|d W d    d S 1 sw   Y  d S )Nz-\<2 \* MonthBegins\> is a non-fixed frequencyr.   r1   r4   r5   r6   r)   )r,   r   r   r8   r   r   r   test_invalid_window_nonfixedE   s   "z*TestRollingTS.test_invalid_window_nonfixed1D2msc                 C   s   |j |d d S )Nr1   )r)   )r,   r   r   r   r   r   test_valid_windowL   s   zTestRollingTS.test_valid_windowminp      ?foo)r"   r#      c                 C   sF   d}t jt|d |jd|d W d    d S 1 sw   Y  d S )NzQlocal variable 'minp' referenced before assignment|min_periods must be an integerr.   r=   r2   min_periodsr;   )r,   r@   r   r8   r   r   r   test_invalid_minpP   s
   "zTestRollingTS.test_invalid_minpc                 C   s   |}d}t jt|d |jddd W d    n1 sw   Y  | }tdt|d|d< |jd	dd  d
}t jt|d |jd	dd W d    n1 sTw   Y  |jd	ddj  d S )NzSinvalid on specified as foobar, must be a column \(of DataFrame\), an Index or Noner.   r&   r0   )r2   onr   r   C2dr3   r   )	r4   r5   r6   r)   copyr	   lenr*   r   )r,   r   r   r8   r   r   r   test_onZ   s   zTestRollingTS.test_onc                 C   sb   t tddddtdd}|jjsJ |jddd  |d}|jjs(J |d  d S )	Nr   r   r   r   r   r&   r   rG   )	r   r	   r   r   is_monotonic_increasingr)   r*   r   r   r+   r   r   r   test_monotonic_onr   s   
zTestRollingTS.test_monotonic_onc                 C   s   t tddddtdd}|d}|j }|d |d< ||_|jjr'J d	}tjt	|d
 |
d  W d    n1 sBw   Y  | }d}tjt	|d
 |j
ddd  W d    d S 1 siw   Y  d S )Nr   r   r   r   r   r   rC   r   zindex values must be monotonicr.   r&   zNinvalid on specified as A, must be a column \(of DataFrame\), an Index or NonerN   )r   r	   r   r   r   to_listrO   r4   r5   r6   r)   r*   r7   )r,   r   non_monotonic_indexr8   r   r   r   test_non_monotonic_on   s$   

"z#TestRollingTS.test_non_monotonic_onc                 C   s   t tdtddddd}tdtdtdtdtd	g|d
< |d
dj jdd}|jdd
dj }t	
|| |d
ddg   dd
g }|jdd
ddg  }t	|| d S )Nr   r   3sr   )r   rI   r   r   r   r   r   r&   T)droprN   r   )r   r   r	   r   r   r)   r   r*   r7   tmassert_series_equalassert_frame_equal)r,   r   expectedresultr   r   r   test_frame_on   s    	$	zTestRollingTS.test_frame_onc                 C   s  t tdtdtdtdtdg|}tg dddd	tjd
g|dg dd}tg ddddtjd
g|d dg dd}|jddd }|}t	|| t
dddtjd
gdd}|jdddj }t|| |g d }|jdddg d  }t	|| d S )Nr   r   r   r   r   )r   r"   r#   rC   r$   r   r"   r#   r$   )r   r   rI   )r   rI   r   )columns        r"   rC   rC      rC   rI   r&   rN   r   )name)r   r   as_unitr   r'   r(   r)   r*   rV   rX   r   r   rW   )r,   unitdtir   	expected1rZ   rY   r   r   r   test_frame_on2   s<   		zTestRollingTS.test_frame_on2c                 C   s   |  }tdddd|_|jddd }|jdd }t|| tddd	d|_|jddd }|jd	dd }t|| |jddd }|jd	dd }t|| |jdd }|jd	d }t|| d S )
Nr   r   Dr   r"   rD   r=   r1   2D)rK   r	   r   r)   r*   rV   rX   r,   r   r   rY   rZ   r   r   r   test_basic_regular   s   z TestRollingTS.test_basic_regularc                 C   sd   |}|j ddd }| d }t|| |j ddd }|j ddd }t|| d S )Nr#   r"   rE   r&   )r)   r*   rV   rX   rh   r   r   r   test_min_periods   s   zTestRollingTS.test_min_periodsc                 C   sz  t tdtdtdtdtdg|}tddgd i|d	}d
}tjt|d |jddd W d    n1 s<w   Y  | }g d|d< |jddd	 }t
|| |d	 }t
|| | }g d|d< |jddd	 }t
|| | }tjddddg|d< |jddd	 }t
|| | }tjdddtjg|d< |jddd	 }t
|| d S )Nz20130101 09:00:01r   r   z20130101 09:00:04r   r   r"   r   r%   z3closed must be 'right', 'left', 'both' or 'neither'r.   r&   blabla)r2   closed)rA   r#   r#   r#   r"   right)rm   )rA   r#   rC   rC   r#   bothrA   r#   leftneither)r   r   ra   r   r4   r5   r6   r)   rK   r*   rV   rX   r'   r(   )r,   r   rb   rc   r   r8   rY   rZ   r   r   r   test_closed   sH   
zTestRollingTS.test_closedc                 C   s  |}|j ddd }| }g d|d< t|| |j ddd }| }g d|d< t|| |j ddd }| }tjtjd	tjd
g|d< t|| |j ddd }| }g d|d< t|| |j dd }| }g d|d< t|| |j ddd }| }g d|d< t|| |j dd	d }| }tjtjd	ddg|d< t|| |j ddd }| }g d|d< t|| d S )N1sr"   rD   r^   r"   r#   rC   r$   r   r&   r]   r#   rC   r_   rT   )r^   r"   rC   r   r_   r1   4s)r^   r"   rC      	   rv   rw   5s)r^   r"   rC   rv   
   )r)   r*   rK   rV   rX   r'   r(   r,   r    r   rZ   rY   r   r   r   test_ragged_sum.  sB   zTestRollingTS.test_ragged_sumc                 C   l   |}|j ddd }| }g d|d< t|| |j ddd }| }g d|d< t|| d S Nrs   r"   rD   rt   r   r&   r^   r"   g      ?      @g      @)r)   meanrK   rV   rX   rz   r   r   r   test_ragged_meanX     zTestRollingTS.test_ragged_meanc                 C   r|   r}   )r)   medianrK   rV   rX   rz   r   r   r   test_ragged_mediand  r   z TestRollingTS.test_ragged_medianc                 C   sp   |}|j dddd}| }g d|d< t|| |j dddd}| }g d|d< t|| d S )	Nrs   r"   rD         ?rt   r   r&   r~   )r)   quantilerK   rV   rX   rz   r   r   r   test_ragged_quantilep  s   z"TestRollingTS.test_ragged_quantilec                 C      |}|j dddjdd}| }dgd |d< t|| |j dddjdd}| }tjgd |d< t|| |j d	ddjdd}| }dgd
gd  |d< t|| |j dddjdd}| }tjddddg|d< t|| d S )Nrs   r"   rD   r   ddofr^   r   r   rT   r   r$   rx   g۞?rA   gPS?)r)   stdrK   rV   rX   r'   r(   rz   r   r   r   test_ragged_std|  "   zTestRollingTS.test_ragged_stdc                 C   r   )Nrs   r"   rD   r   r   r^   r   r   rT   g      ?r$   rx   r   rA   g?)r)   varrK   rV   rX   r'   r(   rz   r   r   r   test_ragged_var  r   zTestRollingTS.test_ragged_varc                 C   s|   |}|j ddd }| }tjgd |d< t|| |j ddd }| }tjgd g d |d< t|| d S )	NrT   r"   rD   r   r   rx   r#   )r^   r^   r^   )r)   skewrK   r'   r(   rV   rX   rz   r   r   r   test_ragged_skew  s   zTestRollingTS.test_ragged_skewc                 C   sz   |}|j ddd }| }tjgd |d< t|| |j ddd }| }tjgd dg |d< t|| d S )	NrT   r"   rD   r   r   rx   r$   g333333)r)   kurtrK   r'   r(   rV   rX   rz   r   r   r   test_ragged_kurt  s   zTestRollingTS.test_ragged_kurtc                 C   s   |}|j ddd }| }g d|d< t|| |}|j dd }t|| |j ddd }| }g d|d< t|| |j dd	d }| }tjtjd	tjd	g|d< t|| d S )
Nrs   r"   rD   )rA   r"   r"   r"   r"   r   r1   r&   )rA   r"   r#   r"   r#   r#   )r)   countrK   rV   rX   r'   r(   rz   r   r   r   test_ragged_count  s    zTestRollingTS.test_ragged_countc                 C   s   t tddddg ddd}|d }| }g d|d	< t|| t tddddg d
dd}t|| |d }| }g d|d	< t|| |d }| }g d|d	< t|| d S )Nr   r   r   r   rt   r   r   rs   r   )r   r$   rC   r$   r   r&   )      @r$   rC   rC   r$   rx   )r   r$   rC   rC   rC   )r   r	   r   r)   minrK   rV   rX   r,   r   rZ   rY   r   r   r   test_regular_min  s.   zTestRollingTS.test_regular_minc                 C   s   |}|j ddd }| }g d|d< t|| |j ddd }| }g d|d< t|| |j ddd }| }g d	|d< t|| d S )
Nrs   r"   rD   rt   r   r&   )r^   r"   r"   rC   rC   rx   )r^   r   r   r"   r"   )r)   r   rK   rV   rX   rz   r   r   r   test_ragged_min     zTestRollingTS.test_ragged_minc                 C   s   d}t dtjd|itd|ddd}|jddd	 }|d
 }|| dk   s2J |jddd	 }|d }|| dk   sNJ d S )Ni'  r   r#   r   r   r   r%   r"   rj   r&   g{Gz?   200s)	r   r'   randomdefault_rngstandard_normalr	   r)   r   all)r,   NdfprY   rZ   r   r   r   test_perf_min  s   zTestRollingTS.test_perf_minc                 C   s   |}|j ddd }| }g d|d< t|| |j ddd }| }g d|d< t|| |j ddd }| }g d|d< t|| d S )Nrs   r"   rD   rt   r   r&   rx   )r)   maxrK   rV   rX   rz   r   r   r   test_ragged_max  r   zTestRollingTS.test_ragged_maxzfreq, op, result_datamsr   r^   ry   r   rw   gqq?r   g       @r   hrf   c                 C   sn   t dd| dd}td|dd}tj|jd< d	|jd
< t|jd| d| }t||d}t|| d S )Nz2018-1-1 01:00:001ry   )startr   r   r   float)datar   dtyper"   r#   10r1   )r   r   )	r	   r   r'   r(   ilocgetattrr)   rV   rW   )r,   r   opresult_datar   r   rZ   rY   r   r   r   test_freqs_ops   s   
zTestRollingTS.test_freqs_opsf)
r*   r   r   r   r   r   r   r   r   r   c                 C   sh   |d }|j dd}|j dd}t|| }t|| }t|| |d}|d}t|| d S )Nr#   r"   r1   rs   r   )r)   r   rV   rX   r   )r,   r   r   r   errrZ   rY   r   r   r   test_all@  s   

zTestRollingTS.test_allc                    s   | t dtditddddd}|dd}|jd	d
}t|  } fdd}||jj	
|jddd}t|| d S )Nr   2   r   r   r   r%   09:0016:005hr1   c                    s"   |  dd} t| jddd  S )Nr   r   r   r"   rj   )between_timer   r)   )xr   r   r   
agg_by_dayo  s   z+TestRollingTS.test_all2.<locals>.agg_by_dayr   T)levelrU   )r   r'   aranger	   r   r)   r   groupbyr   dayapplyr7   rV   rX   )r,   arithmetic_win_operatorsr   dftr   rZ   r   rY   r   r   r   	test_all2]  s   zTestRollingTS.test_all2c                 C   s   t dddd}ttt||d}|d }ttjgdgt|d   |d}t	|| |jd	dd
 }t	|| |d }ttjdgdgt|d	   |d}t	|| |jddd
 }t	|| d S )Nz
2017-01-01   1hr   r%   2hr   r"   r#   rj   3hrA   rC   )
r	   r   r'   r   rL   r)   covr(   rV   rW   )r,   idxssrZ   rY   	expected2r   r   r   test_rolling_cov_offsety  s   "$z%TestRollingTS.test_rolling_cov_offsetc                 C   sr   t tdtdtdtdtdg|}tdg di|d}|d	 }tdg d
i|d}t|| d S )Nz20190101 09:00:30z20190101 09:00:27z20190101 09:00:20z20190101 09:00:18z20190101 09:00:10column)rC   r$   r$   r   rv   r%   rx   )r   r         @r         @)r   r   ra   r   r)   r   rV   rX   )r,   rb   r   r   rZ   rY   r   r   r    test_rolling_on_decreasing_index  s   
z.TestRollingTS.test_rolling_on_decreasing_indexc                 C   s>   t dg ig d}|d }t dg ig d}t|| d S )Nr   r%   rx   )r   r)   r   rV   rX   r   r   r   r   test_rolling_on_empty  s   z#TestRollingTS.test_rolling_on_emptyc                 C   sr   t dtditjtdddtdgddgd	d
}|jd|jdd }t dg di|jd
}t	
|| d S )Nr   rv   20190101rC   rH   r#   dateseq)namesr%   10drN   )r^   rA   r   r   g      $@g      .@)r   r   r   from_productr	   r)   r   get_level_valuesr*   rV   rX   r   r   r   r   !test_rolling_on_multi_index_level  s   
z/TestRollingTS.test_rolling_on_multi_index_levelN),__name__
__module____qualname__r-   r9   r4   markparametrizer
   
MonthBeginr<   Dayr?   r'   arrayrF   rM   rP   rS   r[   re   ri   rk   rr   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!   )   sx    



	 %/*

r!   z	msg, axisr   r"   r   c              	   C   s   t dtg}|dkrdnd|i}ttdfi |}d}|dkr#d}tjt|  dd	1 tj	t
|d	 |jd
|d  W d    n1 sIw   Y  W d    d S W d    d S 1 saw   Y  d S )N2020r"   r\   r   r#   z5The 'axis' keyword in DataFrame.rolling is deprecatedz5Support for axis=1 in DataFrame.rolling is deprecatedz values must not have NaTr.   rf   )axis)r   r   r   r'   eyer4   r5   r6   rV   assert_produces_warningFutureWarningr)   r   )r8   r   r   kwargsr   warn_msgr   r   r   test_nat_axis_error  s   "r   pyarrowc                  C   sF   t tjdtjdttdddddd} | d }t	||  d S )Nr   )r   z
2020-01-01rH   ztimestamp[ns][pyarrow]r%   r=   )
r   r'   r   float64r   r	   r)   r*   rV   rW   )rY   rZ   r   r   r   test_arrow_datetime_axis  s   r   )numpyr'   r4   pandas.util._test_decoratorsutil_test_decoratorstdpandasr   r   r   r   r   r   r   r	   pandas._testing_testingrV   pandas.tseriesr
   fixturer   r    r!   r   r   r   
skip_if_nor   r   r   r   r   <module>   s(    (


     
