a
    Gb1%                     @   sl   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mZ G dd dZG dd dZdS )	    N)TimedeltaIndextimedelta_range)
Int64Index)Hourc                   @   sf  e Z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d Zejdddgdd Zdd Zejdedddddedd dddfedddd!dedd dd"dfedd#ddddd" eg ddd$fgd%d& Zejdeg d'dd(ed)d*gdd(feg d+d!d(ed,d)gd"d(feg d-dd(d"d"d. eg d-dd(fgd/d0 Zd"S )1TestTimedeltaIndexc                 C   sr   t ddd}t ddd}||}t ddd}t|| ttddd}t d	d
dd}|| || d S )N1day   periodsZ3day   r         1 day
   D)startr
   freq)r   uniontmassert_index_equalr   npZarange)selfZi1Zi2resultexpected r   Jlib/python3.9/site-packages/pandas/tests/indexes/timedeltas/test_setops.py
test_union   s    

zTestTimedeltaIndex.test_unionc                 C   sr   t ddd}|dd  }|d d }||s2J ||}t|| |j|dd}tg d}t|| d S )Nr   r   r	      Fsort)z4 Daysz5 Daysz1 Daysz2 Dayz3 Days)r   Z_can_fast_unionr   r   r   r   )r   tdileftrightr   r   r   r   r   test_union_sort_false   s    
z(TestTimedeltaIndex.test_union_sort_falsec                 C   sd   t g d}t | dd}||}t|| |d d |}t|| |j|jks`J d S )N)Z3dZ1dZ2dZinferr   r   )r   sort_valuesr   r   r   r   )r   idxZorderedr   r   r   r   test_union_coverage-   s    
z&TestTimedeltaIndex.test_union_coveragec                 C   sN   t dddd}t dddd}||}ttt|t|B }t|| d S )Nr      Z3Hr
   r   Z4H)r   r   r   sortedsetr   r   )r   Zrng_aZrng_br   expr   r   r   test_union_bug_17308   s
    
z&TestTimedeltaIndex.test_union_bug_1730c                 C   sH   t dg}t g d}||}t tt|t|B }t|| d S )Nz1 day 15:19:49.695000)z2 day 13:04:21.322000z1 day 15:27:24.873000z1 day 15:31:05.350000)r   r   r*   r+   r   r   r   r!   r"   r   r,   r   r   r   test_union_bug_1745A   s    

z&TestTimedeltaIndex.test_union_bug_1745c                 C   sL   t dd}|tjd }||}ttt|t|B }t	|| d S )Nr   Z30d   )
r   pdoffsetsZMinuter   r   r*   r+   r   r   r.   r   r   r   test_union_bug_4564L   s
    

z&TestTimedeltaIndex.test_union_bug_4564c                 C   sh   t ddd}|g d }|g d }|jd u s2J |jd u s@J ||}t|| |jdksdJ d S )Nz1 Dayr   r	   )r      r   r(   )r   r   r4   r   )r   r   r   r   r   )r   r    r!   r"   r   r   r   r   test_union_freq_inferU   s    
z(TestTimedeltaIndex.test_union_freq_inferc                 C   s   t dddd}|tjd }tt ||@ }W d    n1 sF0    Y  t|dks`J t dddd}|tjd }tt ||@ }W d    n1 s0    Y  t dd	dd}t|| |j	|j	ksJ d S )
Nr   r(   hr)   r   r   r4   z1 day 01:00:00r   )
r   r1   r2   r   r   Zassert_produces_warningFutureWarninglenr   r   )r   index_1index_2r   r   r   r   r   test_intersection_bug_1708d   s    &&z-TestTimedeltaIndex.test_intersection_bug_1708c                 C   sp   t dddd}t dddd}|j||d}|d u rBt||  t||sRJ |j||d}||u slJ d S )Nr   r(   r6   r)   r   )r   intersectionr   r   r%   ZequalContents)r   r   firstsecondZ	intersectZinterr   r   r   test_intersection_equalu   s    z*TestTimedeltaIndex.test_intersection_equalzperiod_1, period_2)r   r(   )r(   r   c                 C   sH   t d|dd}t d|dd}t dddd}|j||d}t|| d S )Nr   r6   r)   r   r   )r   r<   r   r   )r   Zperiod_1Zperiod_2r   r9   r:   r   r   r   r   r   test_intersection_zero_length   s
    z0TestTimedeltaIndex.test_intersection_zero_lengthc                 C   sR   t dddd}t dddd}|j||d}||us6J ||usBJ t|| d S )Nr   r   r6   r)   r   r   )r   r<   r   Zassert_copy)r   r   r9   r:   r   r   r   r   test_zero_length_input_index   s    z/TestTimedeltaIndex.test_zero_length_input_indexzrng, expectedr   r   r6   r&   r
   r   namer(   otherNr   )r   rC   c                 C   s^   t ddddd}|j||d}|d u r.| }t|| |j|jksJJ |j|jksZJ d S )Nr   r(   r6   r&   rB   r   )r   r<   r%   r   r   rC   r   r   rngr   r   baser   r   r   r   test_intersection   s    z$TestTimedeltaIndex.test_intersection)5 hour2 hour4 hourz9 hourrC   rJ   rK   )rJ   rI   rI   1 hourrM   rM   rJ   rK   z3 hourc                 C   s   t g ddd}|j||d}|d u r.| }t|| |j|jksJJ t||d d d krz|d u rzt|jt	sJ n|jd u sJ d S )NrN   r&   rL   r   rO   )
r   r<   r%   r   r   rC   all
isinstancer   r   rE   r   r   r   test_intersection_non_monotonic   s    z2TestTimedeltaIndex.test_intersection_non_monotonic)__name__
__module____qualname__r   r#   r'   r-   r/   r3   r5   r;   r?   pytestZmarkZparametrizer@   rA   r   r   rH   rR   r   r   r   r   r      sT   		
	

r   c                   @   s   e Zd Zdd Zdd ZdS )TestTimedeltaIndexDifferencec                 C   s   t dddd}t dddd}tddgd d}|||}t|| td|| t dddd}|||}tddgd d}t|| td|| d S )	N0 days5 daysr   r$   1 days4 daysr   2 days)r   r   
differencer   r   assert_attr_equal)r   r   indexrD   r   idx_diffr   r   r   test_difference_freq   s    z1TestTimedeltaIndexDifference.test_difference_freqc                 C   s   t g d}tdddd}|||}t ddgd d}|d u rF| }t|| td|| td	ddd}|||}t ddgd d}|d u r| }t|| td|| d S )
N)rY   z3 daysr\   r[   rZ   rX   rZ   r[   r   r$   rY   rX   r   r\   )r   r   r]   r%   r   r   r^   )r   r   r_   rD   r`   r   r   r   r   test_difference_sort   s"    z1TestTimedeltaIndexDifference.test_difference_sortN)rS   rT   rU   ra   rb   r   r   r   r   rW      s   rW   )Znumpyr   rV   Zpandasr1   r   r   Zpandas._testingZ_testingr   Zpandas.core.apir   Zpandas.tseries.offsetsr   r   rW   r   r   r   r   <module>   s    K