o
    $jh)                     @   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   r/var/www/html/Deteccion_Ine/venv/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])npZ
datetime64arrayobjectpytestraises	TypeErrorr   r   Z_from_sequencer   )r   Z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   ZarangeZint64r   _dataZ_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freqZinferr6   Zinferred_freq_cache)r   r   r6   getattr)r   r0   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 )
Nr2   d   r3   r4   %TimedeltaArray.__init__ is deprecatedzMInferred frequency .* from passed values does not conform to passed frequencyr
   Dr7   )
r   r   r   r)   r   r   r   r   r   r.   )r   r0   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'   r5   z"cannot be converted to timedelta64r
   zEurope/Brussels)	pdZ
date_ranger   r   r   r   Ztz_localizer   Zasarray)r   Z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   rA   r   r   r0   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      @r>   r"   )days)r   r   r   r   rF   rH   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   rA   r   r   rF   Indexr   r   r   rG   )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)rN   z1 days 00:00:052 daysz2 days 00:00:02z0 days 00:00:03rN   z1 days, 00:00:05rC   r>   )rL   secondsr'   )0 days 00:00:00z0 days 00:00:01z0 days 00:00:02srK   )rT   z0 days 00:00:05z0 days 00:00:09)r      rD   )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   rA   offsetsZSecondr   rF   range)r   rI   r:   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 )	Nr3   rD   rU   r4   c                 S   s   g | ]}d | dqS )ZP0DT0H0MSr   .0ir   r   r   
<listcomp>   s    z;TestTimedeltaIndex.test_constructor_iso.<locals>.<listcomp>r&   r,   )r   rZ   r   r   rF   )r   rI   Z	durationsr:   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
   rN   g      %@r@   r,   )r   r   r   r   rF   )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
   rN   Zfoor>   )startr5   r6   z[TimedeltaIndex\(\.\.\.\) must be called with a collection of some kind, '1 days' was passedc                 s   s    | ]}t |V  qd S )Nr   r]   r   r   r   	<genexpr>   s    z?TestTimedeltaIndex.test_constructor_coverage.<locals>.<genexpr>r,   c                 S   s   g | ]}t |qS r   r   r]   r   r   r   r`      s    z@TestTimedeltaIndex.test_constructor_coverage.<locals>.<listcomp>)rN   rR   rO   )r&   rC   r'   drK   zQInferred frequency None from passed values does not conform to passed frequency D)rN   rR   z4 daysr7   zVOf the four parameters: start, end, periods, and freq, exactly three must be specifiedr4   )r   r   r   r   r   rZ   r   rF   r   r   r   Zasi8r)   )r   r   genr:   rI   stringsZ	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 )NrN   r&   r>   TEST)re   r5   r6   namezsomething else)rl   )r   rl   r   )r   idxZ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
   2000rX   r   z3The 'timedelta64' dtype has no unit. Please pass in)r   r   r)   r   rA   rP   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
   ro   ztimedelta64[D]r   ztimedelta64[us]zm8[us])r   r   r)   r   r   )r   r   r0   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&   rV   r@   r7   r=   r
   )r   r6   r   r.   r   r   r   r   )r   r0   r:   r   Z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&   rV   r@   )r   rA   ZCategoricalr   r   rF   ZCategoricalIndex)r   r0   catr:   cir   r   r   test_from_categorical  s   

z(TestTimedeltaIndex.test_from_categoricalN)__name__
__module____qualname__r   r!   r   markZparametrizer+   r1   r;   r?   rB   rJ   rM   rQ   filterwarningsr[   ra   rd   rj   rn   rp   rq   rr   ru   r   r   r   r   r	      s0    
	
%*	r	   )datetimer   numpyr   r   ZpandasrA   r   r   r   r   Zpandas._testingZ_testingr   Zpandas.core.arrays.timedeltasr   r	   r   r   r   r   <module>   s    