o
    �¨Êhh)  ã                   @   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   úc/var/www/html/env/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 s›w   Y  W d   ƒ d S W d   ƒ d S 1 s³w   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 s›w   Y  d}t jt|d�� td
dd� W d   ƒ d S 1 s»w   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    