o
    _~#g-                     @   s  d dl mZ d dlZd dlZd dlm  mZ d dl	Z
d dl	mZmZ d dlmZ d dlm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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d$d% Z e!d&d'd( Z"dS ))    )	timedeltaN)	DataFrameSeries)timedelta_rangec                  C   s\   t ddgt tddgd} | d }t dtjtjdgtddddd}t|| d S )	N      )minutesdataindex1min0 day   periodsfreq)	r   r   resampleasfreqnpnanr   tmassert_frame_equal)dfresultexpected r   /var/www/static.ux5.de/https/Moving-Object-Detection-with-OpenCV/env/lib/python3.10/site-packages/pandas/tests/resample/test_timedelta.pytest_asfreq_bug   s   r   c                  C   s`   t dt jdg} tdg di| d }tddtjdgitdd	dd
d}t	
|| d S )N0s2svalue)   r      1sg      @g      @r   r   r   r   )pdto_timedeltaNaTr   r   meanr   r   r   r   r   )r   r   r   r   r   r   test_resample_with_nat   s   r)   c                  C   sr   t dddd} tdg di| d}|d }dd	tjtjtjtjd
gi}t|t ddddd}t|| d S )Nz00:00:00z00:10:005minr   r    )r   r"   
   r	   2minr   r,   )r   r   r   r   r   r   r   r   )r   r   r   expected_datar   r   r   r   $test_resample_as_freq_with_subperiod&   s   r/   c                  C   s   t dtdi} | | jd  } tdddd| _t dtditjtddd	d
}|	d }t
||  |d }|	d }t
|| d  d S )NAi     z0 days30min2   r   r   minunitr$   )r   r   arangegroupbyr   sumr   r%   r&   r   r   r   assert_series_equal)r   r   r   sr   r   r   test_resample_with_timedeltas2   s   r=   c                  C   sV   t ttdtddddd} | d }t g dtddddd}t|| d S )	Nr"   1 dayr<   r4   r$   r   )r   r"   r   r   )r   listranger   r   r:   r   r;   )r<   r   r   r   r   r   %test_resample_single_period_timedeltaC   s   rA   c                  C   sF   t dddd} ttd| d}|d }|t}t|| d S )N0	   10msr   r$   )	r   r   r@   r   r(   astypefloatr   r;   )r   seriesr   r   r   r   r   #test_resample_timedelta_idempotencyJ   s
   
rH   c                  C   s   t dddd} ttjdt| | d}|jddd	 }|d }t dd
dd}t dddd}t	
|j| t	
|j| d S )Nr      r<   startr   r   r!   r$   r   5s)offset25srK   endr   29s)r   r   r   randomdefault_rngstandard_normallenr   r(   r   assert_index_equalr   )rngts	with_basewithout_baseexp_without_baseexp_with_baser   r   r   (test_resample_offset_with_timedeltaindexS   s   r]   c                  C   s   t dditjttdddd} | d d| d< | d	d
d }tjt	j
ddgddd	dd}t ddgddgd|d}|jddgdd}|d d|d< t|| d S )N	Group_objr0      r<   r6   r$   categoryGroup10sc                 S   s   |   jd S )Nr   )value_countsr   xr   r   r   <lambda>f   s    zDtest_resample_categorical_data_with_timedeltaindex.<locals>.<lambda>r   r,   zm8[s]dtyper+   ns)r^   ra   r   )axis)r   r%   r&   r?   r@   rE   r   aggTimedeltaIndexr   arrayas_unitreindexr   r   )r   r   exp_tdir   r   r   r   2test_resample_categorical_data_with_timedeltaindexb   s   "rq   c                  C   s   t dddd} td| i| d}t dddd}t||dd}tj|jd	< |d d }t	|| |d d }t	|| d S )
Nr>   z6 day4Dr+   timer$   2D)r   namer   )
r   r   r   r%   r'   ilocr   firstr   r;   )timesr   times2expresr   r   r   test_resample_timedelta_valuess   s   r|   zstart, end, freq, resample_freq))8h21h59min50srb   3h)r   22h1h5h)527D5006D3D10D)1Dr   r   rt   )r}   r~   rb   2h)0hr~   rb   r   )r   85DDrt   c                 C   sx   t | ||d}ttt||d}|| }t || |d}t|j	| |j	j
|j
ks0J t|jd r:J d S )NrO   r$   )r   rK   rP   )r   r   r   r8   rU   r   r5   r   rV   r   r   isnanrv   )rK   rP   r   resample_freqidxr<   r   expected_indexr   r   r   !test_resample_timedelta_edge_case   s   r   
duplicatesTFc                 C   s   t tjdjddtddddd}| rg d	|_|jd
d d d f d	dd }t dgd gd dgd g td
dddd}|j|_t
|| d S )Nr!   )'  r   )sizer   r   	3906250nsrJ   r$   )r0   Br0   Cr#   3sc                 S   s   t | S )N)rU   rd   r   r   r   rf      s    zEtest_resample_with_timedelta_yields_no_empty_groups.<locals>.<lambda>i   r      i     )r   r   rR   rS   normalr   columnslocr   applyr   r   )r   r   r   r   r   r   r   3test_resample_with_timedelta_yields_no_empty_groups   s   
&r   r7   )r<   msusri   c                 C   s   t d|  d}tdtjt ddd|itjdddd	d
}|d	d}tdt
dt
dgitjdddddd
|}t|| d S )Nzm8[]r    r   r<   r6   20200101UTC)r   tzr$   rt   gGz?z0 days 00:00:00.990000z0 days 00:00:02.990000r!   )r   r   r   )r   rh   r   r%   r&   r8   rE   
date_ranger   quantile	Timedeltar   r   )r7   rh   r   r   r   r   r   r    test_resample_quantile_timedelta   s"   	r   c                  C   st   t dd tdD } ttd| d}|jdddd }tg dt jd	d td
D ddd}t|| d S )Nc                 S       g | ]}t jd |d  dqS )x   r1   secondsr%   r   .0ir   r   r   
<listcomp>        z.test_resample_closed_right.<locals>.<listcomp>r,   r$   r5   right)closedlabel)r   r            rC   c                 S   r   )r   <   r   r   r   r   r   r   r      r      r+   )	r%   Indexr@   r   r   r:   rl   r   r;   )r   serr   r   r   r   r   test_resample_closed_right   s   r   pyarrowc                  C   sL   t jtddddd} ttjdtjd| d}|d }t	
|| d S )Nr>   r"   )r   zduration[ns][pyarrow]rg   r$   r   )r%   r   r   r   r   r8   float64r   r(   r   r;   )r   r   r   r   r   r   test_arrow_duration_resample   s   r   )#datetimer   numpyr   pytestpandas.util._test_decoratorsutil_test_decoratorstdpandasr%   r   r   pandas._testing_testingr   pandas.core.indexes.timedeltasr   r   r)   r/   r=   rA   rH   r]   rq   r|   markparametrizer   r   r   r   
skip_if_nor   r   r   r   r   <module>   s:    
	


