o
    թZhU                     @   sB  d dl m Z  d dlZd dlZd dlZd dlZd dlZd dlmZm	Z	 d dl
mZ d dlmZ d dlZd dlmZmZmZ d dlmZ d dlmZ d dlmZmZmZ d d	lmZ d d
lmZ ej !dZ"e# dd Z$ej#dd Z%ej#dd Z&G dd dZ'ej (dg ddd Z)dd Z*ej (dg ddd Z+dS )    )datetimeN)DAYSMONTHS)IncompatibleFrequency)InvalidIndexError)	DataFrameSeries	Timestamp)
date_range)PeriodPeriodIndexperiod_range)_get_period_range_edges)offsetsz@ignore:Resampling with a PeriodIndex is deprecated:FutureWarningc                   C   s   t S )N)r    r   r   ^/var/www/html/lang_env/lib/python3.10/site-packages/pandas/tests/resample/test_period_index.py_index_factory&      r   c                   C   s   dS )Npir   r   r   r   r   _series_name+   r   r   c                  C   s   ddd} | S )zK
    Series with period range index and random data for test purposes.
    Dc                 S   sr   t   dddg}t jd|td t| ||d}W d    n1 s%w   Y  ttj	d
t||dS )	N|zPeriod with BDay freqPeriodDtype\[B\] is deprecatedignore)categoryfreq   index)warningscatch_warningsjoinfilterwarningsFutureWarningr   r   nprandomdefault_rngstandard_normallen)startendr   msgrngr   r   r   _simple_period_range_series6   s   
	z?simple_period_range_series.<locals>._simple_period_range_seriesN)r   r   )r.   r   r   r   simple_period_range_series0   s   
r/   c                   @   s  e Zd Zejdg dejdg ddd Zdd Zejdg d	ejdg d
ejdddiddigdd Zejde	ejdddgejdddgejdg ddd Z
dd Zejdg d d!d" Zejdd#d$gd%d& Zd'd( Zd)d* Zd+d, Zejde	ejd-ddgejdg d.d/d0 Zejd1d#d2gejd-ddgd3d4 Zd5d6 Zejd7d8g d9fd:d;d<gfgd=d> Zd?d@ ZdAdB ZejdCedDejdDgdEdF ZejdCedDejdDgdGdH ZdIdJ ZdKdL ZdMdN Z dOdP Z!ejdQe"ejd1d#d2gejd-ddgdRdS Z#dTdU Z$ejde	dVdW Z%ejdXddgdYdZ Z&d[d\ Z'd]d^ Z(ejdd_gejdg dd`da Z)dbdc Z*ddde Z+dfdg Z,dhdi Z-djdk Z.dldm Z/dndo Z0dpdq Z1drds Z2dtdu Z3dvdw Z4ejj5dxdydzd{ Z6ejd|g d}d~d Z7ejd|g ddd Z8dd Z9dd Z:dd Z;ejdddgejdddgdd Z<ejde=j>de=j>ddgg dfe=j>e=j>de=j>e=j>e=j>dde=j>e=j>g
g dfgejddde?j@ddgfdddgfdddgfgdd ZAdd ZBejdg ddd ZCdd ZDejdg ddd ZEdd ZFdd ZGejddddddgfd:dddddgfgdd ZHejdeIJ eIKdeILdgdd ZMdS )TestPeriodIndexr   )2D1h2hkind)periodN	timestampc                 C   s   |}|dkr|  | }n(|jd j dd}|jd |jj j dd}t|||dd}|  ||}d}	tj	t
|	d	 |j||d
 }
W d    n1 sUw   Y  t|
| d S )Nr6   r   r*   howleft)r*   r+   r   	inclusivez?The 'kind' keyword in (Series|DataFrame).resample is deprecatedmatchr4   )to_timestampresampleasfreqr   r   r
   reindex	to_periodtmassert_produces_warningr$   assert_almost_equal)selfseries_and_framer   r4   objexpectedr*   r+   	new_indexr,   resultr   r   r   test_asfreqF   s   zTestPeriodIndex.test_asfreqc                 C   s2  |}t |jd jdd|jd jdddd}| j|dd}d	}tjt|d
 |jdddjdd}W d    n1 s?w   Y  t	|| |
d}t |jd jdd|jd jdddd}| j|dd}d}tjt|d
 |jdddjdd}W d    n1 sw   Y  t|| d S )Nr   r*   r7   r9   r2   r   g      @)Z
fill_value3The 'kind' keyword in Series.resample is deprecatedr<   r6   r>   value      @6The 'kind' keyword in DataFrame.resample is deprecated)r
   r   r?   rB   rD   rE   r$   r@   rA   assert_series_equalZto_frameassert_frame_equal)rG   seriessrK   rJ   r,   rL   framer   r   r   test_asfreq_fill_valueY   s0   
z&TestPeriodIndex.test_asfreq_fill_value)h12hr1   W)Nr5   r6   kwargsondateleveldc           	   	   C   s   t jt|t jd}t||dtjj||gddgdd}d}d}tj	t
|d	3 tjt|d	 |j|fd
|i| W d    n1 sFw   Y  W d    d S W d    d S 1 s^w   Y  d S )Ndtype)r]   avr_   )namesr   zResampling from level= or on= selection with a PeriodIndex is not currently supported, use \.set_index\(\.\.\.\) to explicitly set indexrQ   r<   r4   )r%   aranger)   int64r   pdZ
MultiIndexZfrom_arrayspytestraisesNotImplementedErrorrD   rE   r$   r@   )	rG   r   r   r4   r[   r-   dfr,   depr_msgr   r   r   test_selectiont   s   "zTestPeriodIndex.test_selectionmonthmethffillbfillconvr*   r+   )offsetr5   )r   r   Brv   MEM)QEQc                 C   s   |ddd| d}|dkrt nd }d}	|d u rd}	t }tj||	d" t|j||d	| }
|
j||d
}||| }W d    n1 sHw   Y  t|
| d S )N1/1/1990z
12/31/1991Y-r   rv   r   +Resampling with a PeriodIndex is deprecatedr<   
conventionr7   )	r$   rD   rE   getattrr@   r?   rA   rC   rR   )rG   rs   r5   rr   ro   rn   r/   tswarnr,   rL   rJ   r   r   r   test_annual_upsample_cases   s   	z*TestPeriodIndex.test_annual_upsample_casesc                 C   sz   |dddd}| d }||jj }tdddd|_t|| t| d | t| d | d S )Nr|   	6/30/1995ry   r   Y-DECY)r@   meangroupbyr   yearr   rD   rR   )rG   r/   r   rL   rJ   r   r   r   test_basic_downsample   s   z%TestPeriodIndex.test_basic_downsamplezrule,expected_error_msg))r   z<YearEnd: month=12>)Q-MARz<QuarterEnd: startingMonth=3>)ry   z
<MonthEnd>)zw-thuz<Week: weekday=3>c                 C   s\   |dddd}d| d}t jt|d ||  W d    d S 1 s'w   Y  d S )Nr|   r   zw-wedr   z3Frequency <Week: weekday=2> cannot be resampled to z&, as they are not sub or super periodsr<   )rh   ri   r   r@   r   )rG   r/   ruleZexpected_error_msgr   r,   r   r   r   test_not_subperiod   s   "z"TestPeriodIndex.test_not_subperiodr   r1   c                 C   s   |dddd}| d }d}tjt|d |j |dd	 }W d    n1 s+w   Y  |j|dd
}||d|}t	|| d S )Nr|   r   ry   r   r   9The 'convention' keyword in Series.resample is deprecatedr<   r+   r   r7   rp   )
r@   r   rD   rE   r$   rp   r?   rA   rC   rR   )rG   r   r/   r   rL   r,   	resampledrJ   r   r   r   test_basic_upsample   s   z#TestPeriodIndex.test_basic_upsamplec                 C   s   t dddd}ttjdt||}d}tjt	|d |j
dd	d
jdd}W d    n1 s4w   Y  |dj|jddd}t|| d S )N1/1/2000   r   periodsr   r   r   r<   ry   r+   r   )limitrp   )methodr   )r   r   r%   r&   r'   r(   r)   rD   rE   r$   r@   rp   rA   rB   r   rR   )rG   r-   r   r,   rL   rJ   r   r   r   test_upsample_with_limit   s   z(TestPeriodIndex.test_upsample_with_limitc                 C   sN   |dddd}t d|i}|d }|d d }t|d | d S )Nr|   
12/31/1995r   r   rb   r   )r   r@   rp   rD   rR   )rG   r/   r   rk   rdfexpr   r   r   test_annual_upsample   s
   z$TestPeriodIndex.test_annual_upsamplec                 C   sb   t dddd}tg d|d}|d }t dd	dd}|jdd
dj|dd}t|| d S )N2000Z2003r   r   )   r         r   ry   2000-01z2003-12r*   r7   rp   r   )r   r   r@   rp   rA   rB   rD   rR   )rG   r-   r   rL   ex_indexrJ   r   r   r   test_annual_upsample2   s   z%TestPeriodIndex.test_annual_upsample2r   )rt   ru   rw   c                 C   s   d| }|dd|d}|dkrt nd }d}	|d u rd}	t }tj||	d  |j||d	 }
|
j||d
}||d }W d    n1 sHw   Y  t|
| d S )NQ-r|   r   r   rv   r   r~   r<   r   r7   rp   	r$   rD   rE   r@   rp   r?   rA   rC   rR   )rG   rn   rs   r5   r   r/   r   r   r   r,   rL   rJ   r   r   r   test_quarterly_upsample   s   
z'TestPeriodIndex.test_quarterly_upsampletargetrv   c           	      C   s   |dddd}|dkrd nt }d}|d u rd}t }tj||d  |j||d	 }|j||d
}||d }W d    n1 sCw   Y  t|| d S )Nr|   r   ry   r   r   r   r~   r<   r   r7   rp   r   )	rG   r   r   r/   r   r   r,   rL   rJ   r   r   r   test_monthly_upsample   s   z%TestPeriodIndex.test_monthly_upsamplec                 C   s   t tdtddddddd}tj|dd	< ttd
dtddgdd}t ddg|d}d}tjt	|d |
 jddd }W d    n1 sKw   Y  t|| tjt	|d |jddd }W d    n1 sqw   Y  t|| d S )Nd   Z20130101rU   idx)r   r   namefloatr   ra   
      z2013-01-01 00:00minz2013-01-01 00:01)r   g     @A@g     S@r   rN   r<   r5   r>   )r   ranger
   r%   nanr   r   rD   rE   r$   rC   r@   r   rR   )rG   rU   r   rJ   r,   rL   Zresult2r   r   r   test_resample_basic	  s(   z#TestPeriodIndex.test_resample_basiczfreq,expected_valsry   )      r   	   2M<   (   c                 C   sP   t dtdddd}|| }td|t|d}t ||d}t|| d S )Nr   r   r   r*   r   r   r*   r   r   )r   r   r@   countr)   rD   rR   )rG   r   Zexpected_valsrT   rL   expected_indexrJ   r   r   r   test_resample_count  s   
z#TestPeriodIndex.test_resample_countc                 C   s@   t tdtddddd}|}t|d| }t|| d S )Nr   r   ry   r*   r   r   r   )r   r   r   r   r@   rD   rR   )rG   Zresample_methodrT   rJ   rL   r   r   r   test_resample_same_freq+  s   z'TestPeriodIndex.test_resample_same_freqc                 C   sh   d}t dddd}ttd|d}|d}tjt|d |  W d    d S 1 s-w   Y  d S )	NzcFrequency <MonthEnd> cannot be resampled to <Week: weekday=6>, as they are not sub or super periodsr   r   ry   r   r   rZ   r<   )r   r   r   r@   rh   ri   r   r   )rG   r,   r   serrsr   r   r   test_resample_incompat_freq3  s   

"z+TestPeriodIndex.test_resample_incompat_freqtzAmerica/Los_Angelesc                 C   s   |}t dddddtjd}t dddddtjd}t||ddd	}td|d
}||}d}tjt|d |j	ddd
 }W d    n1 sHw   Y  t||dddt  }	td|	d
}
t||
 d S )Ni     r   r   )r   rn   dayhourminutetzinfor   rX   r   )r   r   r   rN   r<   r   r5   r>   )r*   r+   r   r         ?)r   pytzutcr
   r   
tz_convertrD   rE   r$   r@   r   r   r   ZDayrR   )rG   r   Zlocal_timezoner*   r+   r   rT   r,   rL   r   rJ   r   r   r   test_with_local_timezone?  s   	
z(TestPeriodIndex.test_with_local_timezonec                 C   sr   t ddd||d}td|d}|d }tjddg|dd	|}td
|d}t|| |j	j
|ks7J d S )Nz
2017-01-010   rX   )r   r   r   unitr   r   r   z
2017-01-02)r   r          @)r
   r   r@   r   rg   DatetimeIndexas_unitrD   rR   r   r   )rG   r   r   Zdtir   rL   Zexp_dtirJ   r   r   r   test_resample_with_tz_  s   	
z%TestPeriodIndex.test_resample_with_tzc                 C   s^   t dddd}ttt||d}|d}tj|jdd|_|	d
 }t|| d S )Nz
2017-03-12z2017-03-12 1:45:00Z15minr   r   z
US/PacificZ900s)r
   r   r%   zerosr)   tz_localizerg   r   r   r@   r   rD   rR   )rG   r   rU   rJ   rL   r   r   r   'test_resample_nonexistent_time_bin_edgev  s   
z7TestPeriodIndex.test_resample_nonexistent_time_bin_edgec                 C   sr   t dddd}|dd}tttt||d}|tj	dd	
 }t d
dddddd}t|j| d S )Nz
2017-10-10z
2017-10-20r2   r*   r+   r   UTCzAmerica/Sao_Paulodatar   Z1Dr   z
2017-10-09r   Zshift_forwardr:   )r*   r+   r   r   Znonexistentr;   )r
   r   r   r   listr   r)   r   rg   ZGrouperr   rD   assert_index_equalr   )rG   r   rk   rL   rJ   r   r   r   (test_resample_nonexistent_time_bin_edge2  s   z8TestPeriodIndex.test_resample_nonexistent_time_bin_edge2c                 C   sD   t ddddd}ttt||d}|d }t|| d S )Nz2014-10-25 22:00:00z2014-10-26 00:30:00Z30minzEurope/Londonr   r   r   )	r
   r   r%   r   r)   r@   r   rD   rR   )rG   r   rJ   rL   r   r   r   %test_resample_ambiguous_time_bin_edge  s   z5TestPeriodIndex.test_resample_ambiguous_time_bin_edgec                 C   s\   t tjdddtddddd}|d }|d d d}t	|| d S )	Nr   rf   r`   z
2010-01-01rz   r   r   rx   )
r   r%   re   r
   r@   rp   lastZastyperD   rR   )rG   rU   r   Zbothr   r   r   !test_fill_method_and_how_upsample  s   z1TestPeriodIndex.test_fill_method_and_how_upsampler   c                 C   s   d| }|dd|d}|dkrd nt }d}|d u rd}t }tj||d  |j||d	 }	|	j||d
}
|
|d }
W d    n1 sHw   Y  t|	|
 d S )NzW-r|   r   r   r   r   r~   r<   r   r7   rp   r   )rG   r   r   r   r/   r   r   r   r,   rL   rJ   r   r   r   test_weekly_upsample  s   
z$TestPeriodIndex.test_weekly_upsamplec                 C   sx   |dddd}d}t jt|d |jddd	 }W d    n1 s$w   Y  |jd
dd }t || d S )Nr|   r   ry   r   rN   r<   r   r6   r>   r*   r7   zYE-DEC)rD   rE   r$   r@   r   r?   rR   )rG   r/   r   r,   rL   rJ   r   r   r   test_resample_to_timestamps  s   z+TestPeriodIndex.test_resample_to_timestampsc                 C   s   |ddd| d}| d|  }|jddd}t|jd	 dd|jd
 ddd| d}|j|dddd}||_t|| d S )N19901992r}   r   r   r   r*   r7   r   r9   r+   rU   rp   r   )	r@   rp   r?   r   r   rA   rB   rD   rR   )rG   r/   rn   r   Zquar_tsstampsZqdatesrJ   r   r   r   test_resample_to_quarterly  s   z*TestPeriodIndex.test_resample_to_quarterlyr8   c                 C   s   |dddd}d}t jt|d |jd|d }W d    n1 s$w   Y  |jd|d	}|j|jd
d}t || d S )Nr   r   zY-JUNr   r   r<   r   r   r7   rp   r   )	rD   rE   r$   r@   rp   rA   rB   r   rR   )rG   r/   r8   r   r,   rL   rJ   r   r   r   $test_resample_to_quarterly_start_end  s   z4TestPeriodIndex.test_resample_to_quarterly_start_endc                 C   sd   t g ddd}ttjdd|d}| }|d }|d 	d}t
|| d S )N)      i  r   r   r   r   r   YE)r   r   r%   r&   r'   r(   r?   r@   rp   rC   rD   rR   )rG   r-   rU   r   ZfilledrJ   r   r   r   test_resample_fill_missing  s   z*TestPeriodIndex.test_resample_fill_missingc                 C   sp   t g ddd}ttjdd|d}d}tjt|d |	d
  W d    d S 1 s1w   Y  d S )	N)r   r   r   r   r   r   r   r   r   r   z8Reindexing only valid with uniquely valued Index objectsr<   )r   r   r%   r&   r'   r(   rh   ri   r   r@   rp   )rG   r-   rU   r,   r   r   r   test_cant_fill_missing_dups  s   "z+TestPeriodIndex.test_cant_fill_missing_dups5minc                 C   s   t dddd}ttjdt||d}| |	 }|dkr(|
|}d}tjt|d	 |j||d
	 }W d    n1 sEw   Y  t|| d S )Nr   z1/5/2000r   r   r   r   r6   rN   r<   r>   )r   r   r%   r&   r'   r(   r)   r?   r@   r   rC   rD   rE   r$   rR   )rG   r   r4   r-   r   rJ   r,   rL   r   r   r   test_resample_5minute  s   
z%TestPeriodIndex.test_resample_5minutec                 C   s   |dddd}| d }|dtdd}t|| |dd}d}tjt|d |j d	d
d }W d    n1 sAw   Y  tddd	d}|jd	d
d|}t|| d S )Nr   z2/1/2000rv   r   r   z1/3/2000r   r<   rX   rU   r   z2/1/2000 23:00r7   )r@   rA   rB   r   rD   rR   rE   r$   )rG   r/   r   rL   rJ   r,   Zexp_rngr   r   r   "test_upsample_daily_business_daily  s   
z2TestPeriodIndex.test_upsample_daily_business_dailyc                 C   sd   t dddd}ttd|d}|d d }|dt}|dtj|j }t	
|| d S )	Nz1/1/2012r   i  r   r   r   z2012-01-04 06:5510min)r
   r   r%   arrayr@   applyr)   locr   rD   rR   )rG   drrU   ZsubsetrL   rJ   r   r   r   test_resample_irregular_sparse  s   z.TestPeriodIndex.test_resample_irregular_sparsec                 C   s   t dddd}ttjdt||d}|d }|	 
 s%J |d  d d }|d }t|| d S )	Nr   r   zW-WEDr   r   r   zW-THUr9   )r
   r   r%   r&   r'   r(   r)   r@   rA   Zisnaallrp   rD   rR   )rG   r-   r   rL   rJ   r   r   r   test_resample_weekly_all_na  s   z+TestPeriodIndex.test_resample_weekly_all_nac           	      C   s   t dd|d}ttt||d}|d}|d}|d }| }|j	d |_	|d d}t
j|j	dd|_	t|| |d	 }d S )
Nz	2012-4-13z2012-5-1)r*   r+   r   r   r   r   rZ   r   r   )r
   r   r   r)   r   r   r@   r   copyr   rg   r   rD   rR   )	rG   r   r   r   Zts_utcZts_localrL   Zts_local_naiver   r   r   r   test_resample_tz_localized$  s   

z*TestPeriodIndex.test_resample_tz_localizedc                 C   s   t ddddd}tddg|d}|jd	d
d
d }t ddd	dd}tdg|d}t|| d}tjt|d |jd	dd }W d    n1 sLw   Y  tddd	d}tdg|d}t|| d S )Nz2001-09-20 15:59z2001-09-20 16:00r   zAustralia/Sydneyr   r   r   r   r   rightclosedlabelz
2001-09-21)r   r   r   g      ?rN   r<   r5   r>   z
2001-09-20r   )	r
   r   r@   r   rD   rR   rE   r$   r   )rG   r   rU   rL   r   rJ   r,   r   r   r   test_resample_tz_localized28  s   z+TestPeriodIndex.test_resample_tz_localized2c                 C   s   t dddd}|d}t|d}tjdt||d< ttjdt||d	< t|	d

 d |	d
 d	 ddd	gd}|	d
dddjdd	gd}t|| d S )Nz1/1/2011i N  rX   r   ESTr   r   firstsecondr   )r  r  )columnssumr   )r
   r   r   r%   r&   r'   r(   r)   Zcumsumr@   r  r   ZaggrB   rD   rS   )rG   r-   r   rJ   rL   r   r   r   test_resample_tz_localized3M  s"   

 z+TestPeriodIndex.test_resample_tz_localized3c                 C   s   t tjddtddddd}tj|jd< |jdd	d
d	 }|dd  jdd	d
d	 }t
|| |jdd	d	d	 }|dd  jdd	d	d	 }tdddd}t
|j| t
|| d S )Nr      z1/1/2012 9:30Z1minr   r   r   r   r:   r   r   r   r   )r   r%   r&   r'   r(   r
   r   ilocr@   r   rD   rR   r   r   )rG   rU   rL   r   r   r   r   r   test_closed_left_cornerc  s   z'TestPeriodIndex.test_closed_left_cornerc                 C   sT   t dddd}ttd|d}|d }| d  }t	|| d S )NZ2000Q1r   Q-DECr   r   r   r   )
r   r   r%   re   r@   r   r?   rC   rD   rR   )rG   r-   r   rL   r   r   r   r   test_quarterly_resamplingw  s
   z)TestPeriodIndex.test_quarterly_resamplingc                 C   sR   t dddd}t|}dd t|D }t|g d|d}|jd	d
d
d  d S )Nz8/6/2012z	8/26/2012r   r   c                 S   s   g | ]}|gd  qS )r   r   ).0xr   r   r   
<listcomp>  s    zATestPeriodIndex.test_resample_weekly_bug_1726.<locals>.<listcomp>)openhighlowcloseZvol)r  r   zW-MONr:   r   )r
   r)   r   r   r@   r  )rG   indnr   rk   r   r   r   test_resample_weekly_bug_1726  s
   z-TestPeriodIndex.test_resample_weekly_bug_1726c                 C   s   t ddgdd}tddg|d}|jdd	d	d
  }g d}t j|ddd	|j
}t j|dd}tg d|d}t|| d S )Nl     Z! l     NE! r   zAmerica/Chicagor   r   r   rY   r   r   )z2016-03-09 12:00:00-06:00z2016-03-10 00:00:00-06:00z2016-03-10 12:00:00-06:00z2016-03-11 00:00:00-06:00z2016-03-11 12:00:00-06:00z2016-03-12 00:00:00-06:00z2016-03-12 12:00:00-06:00z2016-03-13 00:00:00-06:00z2016-03-13 13:00:00-05:00z2016-03-14 01:00:00-05:00z2016-03-14 13:00:00-05:00z2016-03-15 01:00:00-05:00z2016-03-15 13:00:00-05:00T)r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   )rg   r   r   r   r   r@   r   rp   to_datetimer   r   rD   rS   )rG   r   rk   rL   Zexpected_index_valuesrJ   r   r   r   "test_resample_with_dst_time_change  s"   z2TestPeriodIndex.test_resample_with_dst_time_changec                 C   sn   t tddtjd}|d }|d d }|jd tdks)J |jd |jd ks5J d S )NZ20000101Z20000201r   ZBMSrv   r   Z20000103)	r   rg   Zbdate_ranger%   float64r@   r   r   r	   )rG   Z
timeseriesZres1Zres2r   r   r   test_resample_bms_2752  s   z&TestPeriodIndex.test_resample_bms_2752z6Commented out for more than 3 years. Should this work?)reasonc                 C   sl   t dddd}ttd|d}t dddd	}|jdd
d|}|jdd}|d }t	
|| d S )Nr   r   rx   r   r   z
2000-01-01z
2000-03-31r   r   r+   r7   rq   r   )r   r   r%   re   rA   rB   Zfillnar@   r   rD   rR   )rG   r-   r   Z	exp_indexrJ   rL   r   r   r   test_monthly_convention_span  s   z,TestPeriodIndex.test_monthly_convention_spanzfrom_freq, to_freq))r   rx   )rz   r   )rx   rz   )r   rZ   c                 C   \   t dd|d}ttjdt|df|}|| }t	
||j|ddd  d S )N	8/15/2012r   r   r   r   r   r
   r   r%   r&   r'   r(   r)   r@   r   rD   rS   rG   Z	from_freqZto_freqr   rk   r   r   r   r   test_default_right_closed_label  s    z/TestPeriodIndex.test_default_right_closed_label))r   ZMS)rz   ZYS)rx   ZQS)rX   r   )r   rX   c                 C   r  )Nr   r   r   r   r:   r   r!  r"  r   r   r   test_default_left_closed_label  s    z.TestPeriodIndex.test_default_left_closed_labelc                 C   sT   t dddd}ttjdt||d}|d }t	
|jd |  d S )	Nz
2012-01-01z
2012-12-31ry   r   r   r   r   r   )r   r   r%   r&   r'   r(   r)   r@   r   rD   rF   r  )rG   r   r   rL   r   r   r   test_all_values_single_bin  s   z*TestPeriodIndex.test_all_values_single_binc                 C   s   t tjddtdddd}|d }tj	|j
dd	  |j
d	d   gd
dj}tjtdtdgddd|_t|| d S )Nr   )r   r   z2000-1-1r   )r   r   Z5Dr   r   r   )Zaxisz2000-1-6zM8[ns])ra   r   )r   r%   r&   r'   r(   r
   r@   r   rg   concatr  Tr   r	   r   rD   rS   )rG   rk   rL   rJ   r   r   r   (test_evenly_divisible_with_no_extra_bins  s   
0z8TestPeriodIndex.test_evenly_divisible_with_no_extra_binsc                 C   s   t ddd}tdddddd	gd d
ddddd	gd  ||d }t dddd}tdddddd	gd |d}|d }t|| tdddddd	gd |d}|d }t|| d S )Nz2001-5-4   r   r   P   Z   r      )ZREST_KEYZ
DLY_TRN_QTZDLY_SLS_AMTZCOOP_DLY_TRN_QTZCOOP_DLY_SLS_AMTr   F   r   2   r   r   Z7Dr      r
  i  i  i0  i  )	r
   r   appendZ
sort_indexr@   r   rD   rS   r  )rG   r   rk   rJ   rL   r   r   r   )test_evenly_divisible_with_no_extra_bins2  sl   			
	
z9TestPeriodIndex.test_evenly_divisible_with_no_extra_bins2zfreq, period_mult)rX      )rY   r   Nr5   c           
      C   s   t dddd}ttt||d}| | |}t d||t| d}||}d}t	j
t|d |j||d }	W d    n1 sJw   Y  t	|	| d S )	Nr   r   r   r   r   rN   r<   r>   )r   r   r   r)   r?   r@   ZohlcrC   rB   rD   rE   r$   rS   )
rG   r   Zperiod_multr4   r   rU   rJ   rK   r,   rL   r   r   r   test_upsampling_ohlc1  s   
z$TestPeriodIndex.test_upsampling_ohlczperiods, values1970-01-01 00:00:00z1970-01-01 00:00:02z1970-01-01 00:00:03)r   r   r      r   )
r   r   r   r         r5  r         zfreq, expected_values1sr   r5  r   Z2sg      "@Z3sg      @c                 C   s   t |dd}t||d}tdt||d}t||d}d}	tjt|	d ||}
W d    n1 s4w   Y  |
 }t	|| d S )NrU   r   r   r4  r   r~   r<   )
r   r   r   r)   rD   rE   r$   r@   r   rS   )rG   r   valuesr   Zexpected_valuesr   rV   r   rJ   r,   r   rL   r   r   r   test_resample_with_natB  s   (
z&TestPeriodIndex.test_resample_with_natc                 C   sd   t tjgd dd}tg d|dgd}t g |jd}t|dgdd	}|d
 }t|| d S )Nr   rU   r   )r   r   r   rb   )r   r  )r   r   r  )r   r  ra   r:  )	r   rg   NaTr   r   r@   r   rD   rS   )rG   r   rV   r   rJ   rL   r   r   r   test_resample_with_only_natw  s   z+TestPeriodIndex.test_resample_with_only_natz$start,end,start_freq,end_freq,offset))1991090519910909 03:00rX   24h10h)r?  19910909 12:00rX   rA  rB  )r?  z19910909 23:00rX   rA  rB  )19910905 10:0019910909rX   rA  rB  )rD  19910909 10:00rX   rA  rB  )r?  rF  rX   rA  rB  )19910905 12:00rE  rX   rA  rB  )rG  r@  rX   rA  rB  )rG  rC  rX   rA  rB  )rG  rC  rX   rA  Z34h)rG  rC  rX   17hrB  )rG  rC  rX   rH  3h)r?  z19910913 06:00r3   rA  rB  )r?  z19910905 01:39ZMin5Min3Min)r?  z19910905 03:18Z2MinrJ  rK  c                 C   s   t |||d}ttt||d}d}tjt|d |j||d}	W d    n1 s-w   Y  |		 }
|

|}
|
 j||d	 }t|
| d S )Nr   r   r~   r<   rs   )r   r   r%   re   r)   rD   rE   r$   r@   r   r?   rR   )rG   r*   r+   Z
start_freqZend_freqrs   r   r   r,   r   rL   rJ   r   r   r   test_resample_with_offset  s   
z)TestPeriodIndex.test_resample_with_offsetc                 C   s   t dddd}ttt||d}d}tjt|d |jdd	d
}W d    n1 s-w   Y  |	 }|
d}|
 jdd	d
	 }|jd |_t|| d S )NrG  z19910909 1:00rX   r   r   r~   r<   ry   rI  rL  rx   )r   r   r%   re   r)   rD   rE   r$   r@   r   r?   r   Z
_with_freqrR   )rG   r   r   r,   r   rL   rJ   r   r   r   test_resample_with_offset_month  s   
z/TestPeriodIndex.test_resample_with_offset_monthz1first,last,freq,freq_to_offset,exp_first,exp_last))r?  19920406r   r   r?  rO  )z19910905 00:0019920406 06:00r   r   r?  rO  )19910905 06:00rP  rX   rX   rQ  rP  )Z19910906rO  ry   rx   z1991-091992-04)Z19910831Z19920430ry   rx   1991-08rR  )rS  rR  ry   rx   rS  rR  c           	      C   sZ   t |}t |}t ||d}t ||d}tjj|}t|||}||f}||ks+J d S )Nr   )r   rg   ZtseriesZfrequenciesZ	to_offsetr   )	rG   r  r   r   Zfreq_to_offsetZ	exp_firstZexp_lastrL   rJ   r   r   r   test_get_period_range_edges  s   z+TestPeriodIndex.test_get_period_range_edgesc                 C   s   t dddd}td}tj|dd< t|| }d}tjt|d |	d}W d    n1 s3w   Y  |j
d	d
}tdtjgtddgddd}t|| d S )NZ2018rx   r6  r   r   r~   r<   r{   r   )Z	min_countrP   Z2018Q1Z2018Q2r  r   r   )r
   r%   Zonesr   r   rC   rD   rE   r$   r@   r  r   rR   )rG   r   r   rU   r,   r   rL   rJ   r   r   r   test_sum_min_count  s   
z"TestPeriodIndex.test_sum_min_countc                 C   s   d}d}t jt|d tdddd}W d    n1 sw   Y  ttt||d}tddd	d}td
dg|d}t jt|d |d	 }W d    n1 sUw   Y  t 
|| d S )Nz:'T' is deprecated and will be removed in a future version.z:'L' is deprecated and will be removed in a future version.r<   z2020-01-01 00:00:00 00:00z2020-01-01 00:00:00 00:01Lr   r   r   g    K@g     L@r'  rD   rE   r$   r   r   r%   re   r)   r@   r   rR   )rG   Zmsg_tZmsg_lrng_lr   r-   rJ   rL   r   r   r   test_resample_t_l_deprecated  s    z,TestPeriodIndex.test_resample_t_l_deprecatedz.freq, freq_depr, freq_res, freq_depr_res, data2QZ2q2YZ2yg      ?Z2mr   rP   c                 C   s  d|dd   d}d|dd   d d|dd   d}d|dd   d t jt|d tdd|d	}W d    n1 sAw   Y  ttt||d
}	tdd|d	}
t||
d}t jt|d |	|	 }W d    n1 sww   Y  t 
|| d S )N'r   z)' is deprecated and will be removed in a zfuture version. Please use 'z
' instead.r<   z
2020-01-01z
2020-08-01r   r   r   rW  )rG   r   	freq_deprZfreq_resZfreq_depr_resr   rl   Zdepr_msg_resrX  r   r-   rJ   rL   r   r   r   ,test_resample_lowercase_frequency_deprecated  s   
z<TestPeriodIndex.test_resample_lowercase_frequency_deprecatedrs   r   c                 C   sR   d|j  d}|}tjt|d |j|d W d    d S 1 s"w   Y  d S )NzInvalid offset: 'z' for converting time series r<   r   )baserh   ri   
ValueErrorrA   )rG   rs   rH   r,   rk   r   r   r   !test_asfreq_invalid_period_offset  s
   
"z1TestPeriodIndex.test_asfreq_invalid_period_offset)N__name__
__module____qualname__rh   markparametrizerM   rW   rm   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   timezonedateutilr   Zgettzr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r	  r  r  r  r  r  Zxfailr  r#  r$  r%  r(  r1  r3  rg   r=  r%   r   r<  r>  rM  rN  rT  rU  rY  r^  r   Z
MonthBeginZ
BYearBeginZBusinessHourra  r   r   r   r   r0   E   sJ   
	









	
	




%


	
	;

	


r0   zfreq,freq_depr))r   Z2ME)rZ  Z2QE)z2Q-FEBz2QE-FEB)r[  Z2YE)2Y-MARz2YE-MAR)r   Z2me)rZ  Z2qe)ri  z2ye-marc                 C   sd   d|dd   d|dd   d}| }t jt|d || W d    d S 1 s+w   Y  d S )Nzfor Period, please use 'r   z' instead of 'r\  r<   rh   ri   r`  r@   )rH   r   r]  r,   rI   r   r   r   .test_resample_frequency_ME_QE_YE_error_message  s
   ""rk  c                 C   sj   | ddddd d }d}t jt|d |d }W d    n1 s&w   Y  t|dks3J d S )	Nz2007-01z2010-05ry   r   r   r~   r<   r   )rD   rE   r$   r@   r   r)   )r/   Zlen0ptsr,   rL   r   r   r   test_corner_cases_period2  s   rl  r]  )Z2BMEZ2CBMEZ2SMEz2BQE-FEBz2BYE-MARc                 C   sT   d|dd   }| }t jt|d || W d    d S 1 s#w   Y  d S )NzInvalid frequency: r   r<   rj  )rH   r]  r,   rI   r   r   r   $test_resample_frequency_invalid_freq<  s
   "rm  ),r   r    rh  numpyr%   rh   r   Zpandas._libs.tslibs.ccalendarr   r   Zpandas._libs.tslibs.periodr   Zpandas.errorsr   Zpandasrg   r   r   r	   Zpandas._testingZ_testingrD   Zpandas.core.indexes.datetimesr
   Zpandas.core.indexes.periodr   r   r   Zpandas.core.resampler   Zpandas.tseriesr   re  r#   Z
pytestmarkZfixturer   r   r/   r0   rf  rk  rl  rm  r   r   r   r   <module>   sX    


       ^
	

