o
    ŀgh)                     @   sf   d dl mZ d dlZd dlZd dlZd dlmZmZm	Z	m
Z
 d dlmZ d dlmZ G dd dZdS )    	timedeltaN)	TimedeltaTimedeltaIndextimedelta_rangeto_timedelta)TimedeltaArrayc                   @   s   e Zd Zdd Zdd Zejdg d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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*S )+TestTimedeltaIndexc                 C   sD   d}t jt|d tg dd W d    d S 1 sw   Y  d S )NzThe 'closed' keywordmatchT)closed)tmassert_produces_warningFutureWarningr   selfmsg r   e/var/www/html/myenv/lib/python3.10/site-packages/pandas/tests/indexes/timedeltas/test_constructors.pytest_closed_deprecated   s   "z)TestTimedeltaIndex.test_closed_deprecatedc                 C   s   t dd}t j|gtd}d}tjt|d t| W d    n1 s&w   Y  tjt|d tj	|dd W d    n1 sDw   Y  tjt|d t
| W d    d S 1 s`w   Y  d S )NNaTnsdtypez!Invalid type for timedelta scalarr
   zm8[ns])np
datetime64arrayobjectpytestraises	TypeErrorr   r   _from_sequencer   )r   natarrr   r   r   r   test_array_of_dt64_nat_raises   s   

"z0TestTimedeltaIndex.test_array_of_dt64_nat_raisesunit)YyMc              	   C   s   d}d}t jt|d/ tjt|d tg d| W d    n1 s%w   Y  W d    d S W d    d S 1 s=w   Y  d S )Nz/Units 'M', 'Y', and 'y' are no longer supportedz?The 'unit' keyword in TimedeltaIndex construction is deprecatedr
   )         )r   r   
ValueErrorr   r   r   r   )r   r%   r   depr_msgr   r   r   test_unit_m_y_raises'   s   "z'TestTimedeltaIndex.test_unit_m_y_raisesc                 C   s2   t jdt jd}t|dd}|jjj|u sJ d S )N
   r   F)copy)r   arangeint64r   _data_ndarraybase)r   r#   tdir   r   r   test_int64_nocopy/   s   z$TestTimedeltaIndex.test_int64_nocopyc                 C   sB   t dddd}t|dd}|j|jksJ dt|di vsJ d S )	N1 secondi 1speriodsfreqinferr<   inferred_freq_cache)r   r   r<   getattr)r   r6   resultr   r   r   test_infer_from_tdi6   s   z&TestTimedeltaIndex.test_infer_from_tdic              	   C   st  t dddd}d}d}tjt|d t|dd	 W d    n1 s#w   Y  tjt|d% tjt|d t|dd	 W d    n1 sHw   Y  W d    n1 sWw   Y  tjt|d t|j	dd	 W d    n1 suw   Y  tjt|d/ tjt|d t|j	dd	 W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )
Nr8   d   r9   r:   %TimedeltaArray.__init__ is deprecatedzMInferred frequency .* from passed values does not conform to passed frequencyr
   Dr>   )
r   r   r   r,   r   r   r   r   r   r3   )r   r6   r-   r   r   r   r   test_infer_from_tdi_mismatchC   s.   "z/TestTimedeltaIndex.test_infer_from_tdi_mismatchc                 C   s   t jddd}d}tjt|d t|d W d    n1 s"w   Y  tjt|d t| W d    n1 s=w   Y  tjt|d tt| W d    d S 1 s\w   Y  d S )Nz
2016-01-01r*   r;   z"cannot be converted to timedelta64r
   zEurope/Brussels)	pd
date_ranger   r   r    r   tz_localizer   asarray)r   dtir   r   r   r   test_dt64_data_invalid]   s   
"z)TestTimedeltaIndex.test_dt64_data_invalidc                 C   sz   t ddg}t ddg}t|| t ddg}t ddg}t|| t dtjg}t tddtjg}t|| d S )Ngffffff@gffffff#@   	   g       @g      "@)nanoseconds)r   r   assert_index_equalr   nanr   rI   r   r   r6   expectedr   r   r   test_float64_ns_roundedm   s   z*TestTimedeltaIndex.test_float64_ns_roundedc                 C   s8   t ddgdd}ttddtddg}t|| d S )Ng      ?g      @rF   r%   )days)r   r   r   r   rR   rT   r   r   r   test_float64_unit_conversion~   s   z/TestTimedeltaIndex.test_float64_unit_conversionc                 C   s   t dtjt dg}tt|t| ttt|tt| tj	tjt dg}tt|t| ttt|tt| d S )N1 days3 days)
r   rI   r   r   rR   Indexr   r   r   rS   )r   r#   r   r   r   "test_construction_base_constructor   s   "&z5TestTimedeltaIndex.test_construction_base_constructorzFignore:The 'unit' keyword in TimedeltaIndex construction:FutureWarningc                 C   s   t g d}t ddtddtdddtjdg}t|| t g d}t t	dd	d
}t|| t g d}t g dd	d
}t|| t g d}t g ddd
}t|| d S )N)rZ   z1 days 00:00:052 daysz2 days 00:00:02z0 days 00:00:03rZ   z1 days, 00:00:05rO   rF   )rX   secondsr*   )0 days 00:00:00z0 days 00:00:01z0 days 00:00:02srW   )r`   z0 days 00:00:05z0 days 00:00:09)r      rP   )z0 days 00:00:00.400z0 days 00:00:00.450z0 days 00:00:01.200)i  i  i  ms)
r   r   timedelta64r   rI   offsetsSecondr   rR   range)r   rU   rB   r   r   r   test_constructor   s6   	


	z#TestTimedeltaIndex.test_constructorc                 C   s:   t dddd}dd tddD }t|}t|| d S )	Nr9   rP   ra   r:   c                 S   s   g | ]}d | dqS )P0DT0H0MSr   .0ir   r   r   
<listcomp>   s    z;TestTimedeltaIndex.test_constructor_iso.<locals>.<listcomp>r)   r/   )r   rg   r   r   rR   )r   rU   	durationsrB   r   r   r   test_constructor_iso   s   z'TestTimedeltaIndex.test_constructor_isoc                 C   sZ   d}t jt|d tddd}W d    n1 sw   Y  tddd}t || d S )Nz:Non-integer 'periods' in pd.date_range, pd.timedelta_ranger
   rZ   g      %@rH   r/   )r   r   r   r   rR   )r   r   rngexpr   r   r   &test_timedelta_range_fractional_period   s   z9TestTimedeltaIndex.test_timedelta_range_fractional_periodc                 C   s  d}t jt|d tdddd W d    n1 sw   Y  d}t jt|d td W d    n1 s8w   Y  dd	 td
D }t|}tdd td
D }t|| t	g d}t|}t
g ddd}t|| t|j}t|| d}t jt|d tg ddd W d    n1 sw   Y  d}t jt|d td
dd W d    d S 1 sw   Y  d S )Nz!periods must be a number, got foor
   rZ   foorF   )startr;   r<   z[TimedeltaIndex\(\.\.\.\) must be called with a collection of some kind, '1 days' was passedc                 s   s    | ]}t |V  qd S )Nr   rk   r   r   r   	<genexpr>   s    z?TestTimedeltaIndex.test_constructor_coverage.<locals>.<genexpr>r/   c                 S   s   g | ]}t |qS r   r   rk   r   r   r   rn      s    z@TestTimedeltaIndex.test_constructor_coverage.<locals>.<listcomp>)rZ   r^   r[   )r)   rO   r*   drW   zQInferred frequency None from passed values does not conform to passed frequency D)rZ   r^   z4 daysr>   zVOf the four parameters: start, end, periods, and freq, exactly three must be specifiedr:   )r   r   r    r   r   rg   r   rR   r   r   r   asi8r,   )r   r   genrB   rU   strings	from_intsr   r   r   test_constructor_coverage   s:   

"z,TestTimedeltaIndex.test_constructor_coveragec                 C   s<   t ddddd}|jdksJ t|dd}|jdksJ d S )NrZ   r)   rF   TEST)ru   r;   r<   namezsomething else)r~   )r   r~   r   )r   idxidx2r   r   r   test_constructor_name   s   z(TestTimedeltaIndex.test_constructor_namec                 C   s   d}t jt|d tdgdd W d    n1 sw   Y  d}t jt|d tjdgdd W d    d S 1 s=w   Y  d S )Nz with no precision is not allowedr
   2000rd   r   z3The 'timedelta64' dtype has no unit. Please pass in)r   r   r,   r   rI   r\   r   r   r   r   $test_constructor_no_precision_raises   s   "z7TestTimedeltaIndex.test_constructor_no_precision_raisesc                 C   s`   d}t jt|d tdgdd W d    n1 sw   Y  tdgdd}|jdks.J d S )Nz;Supported timedelta64 resolutions are 's', 'ms', 'us', 'ns'r
   r   ztimedelta64[D]r   ztimedelta64[us]zm8[us])r   r   r,   r   r   )r   r   r6   r   r   r   'test_constructor_wrong_precision_raises   s   z:TestTimedeltaIndex.test_constructor_wrong_precision_raisesc                 C   s   t ddd}|jd usJ t|d d}|jd u sJ t|jd d}|jd u s(J d}tjt|d t|d d}W d    n1 sBw   Y  |jd u sNJ d S )Nr)   rb   rH   r>   rE   r
   )r   r<   r   r3   r   r   r   r   )r   r6   rB   r   tdar   r   r   test_explicit_none_freq	  s   z*TestTimedeltaIndex.test_explicit_none_freqc                 C   sL   t ddd}t|}t|}t|| t|}t|}t|| d S )Nr)   rb   rH   )r   rI   Categoricalr   r   rR   CategoricalIndex)r   r6   catrB   cir   r   r   test_from_categorical  s   

z(TestTimedeltaIndex.test_from_categoricalN)__name__
__module____qualname__r   r$   r   markparametrizer.   r7   rC   rG   rN   rV   rY   r]   filterwarningsrh   rp   rs   r|   r   r   r   r   r   r   r   r   r   r	      s0    
	
%*	r	   )datetimer   numpyr   r   pandasrI   r   r   r   r   pandas._testing_testingr   pandas.core.arrays.timedeltasr   r	   r   r   r   r   <module>   s    