o
    թZh%                     @   sd   d dl Zd dlZd dlZd dlmZmZ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)IndexTimedeltaIndextimedelta_range)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   sx   t ddd}t ddd}||}t ddd}t|| ttjdddtjd	}t d
ddd}|| || d S )N1day   periodsZ3day   r         )Zdtype1 day
   D)startr
   freq)r   uniontmassert_index_equalr   npZarangeZint64)selfi1i2resultexpected r   b/var/www/html/lang_env/lib/python3.10/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 }||sJ ||}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s0J 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_17306   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_1745>   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   r0   r   r   r   test_union_bug_4564H   s
   

z&TestTimedeltaIndex.test_union_bug_4564c                 C   sh   t ddd}|g d }|g d }|jd u sJ |jd u s J ||}t|| |jdks2J d S )Nz1 Dayr   r	   )r      r   r*   )r   r   r6   r   )r   r   r   r   r   )r   r"   r#   r$   r   r   r   r   test_union_freq_inferP   s   
z(TestTimedeltaIndex.test_union_freq_inferc                 C   s   t dddd}|tjd }||}t|dksJ t dddd}|tjd }||}t dd	dd}t|| |j|jksEJ d S )
Nr   r*   hr+   r   r   r6   z1 day 01:00:00r   )	r   r3   r4   r   intersectionlenr   r   r   )r   index_1index_2r   r   r   r   r   test_intersection_bug_1708_   s   

z-TestTimedeltaIndex.test_intersection_bug_1708c                 C   sl   t dddd}t dddd}|j||d}|d u r!t||  t|| |j||d}||u s4J d S )Nr   r*   r8   r+   r    )r   r9   r   r   r'   )r   r!   firstsecondZ	intersectinterr   r   r   test_intersection_equaln   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   r8   r+   r   r    )r   r9   r   r   )r   Zperiod_1Zperiod_2r!   r;   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sJ ||us!J t|| d S )Nr   r   r8   r+   r   r    )r   r9   r   Zassert_copy)r   r!   r;   r<   r   r   r   r   test_zero_length_input_index   s   z/TestTimedeltaIndex.test_zero_length_input_indexzrng, expectedr   r   r8   r(   r
   r   namer*   otherNr   )r   rE   c                 C   s^   t ddddd}|j||d}|d u r| }t|| |j|jks%J |j|jks-J d S )Nr   r*   r8   r(   rD   r    )r   r9   r'   r   r   rE   r   r   rngr   r!   baser   r   r   r   test_intersection   s   z$TestTimedeltaIndex.test_intersection)5 hour2 hour4 hourz9 hourrE   rL   rM   )rL   rK   rK   1 hourrO   rO   rL   rM   z3 hourc                 C   s   t g ddd}|j||d}|d u r| }t|| |j|jks%J t||d d d kr>|d u r>t|jt	s<J d S |jd u sEJ d S )NrP   r(   rN   r    rQ   )
r   r9   r'   r   r   rE   all
isinstancer   r   rG   r   r   r   test_intersection_non_monotonic   s   z2TestTimedeltaIndex.test_intersection_non_monotonic)__name__
__module____qualname__r   r%   r)   r/   r1   r5   r7   r=   rA   pytestmarkZparametrizerB   rC   r   r   rJ   rT   r   r   r   r   r      sV    


	

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!   indexrF   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 r#| }t|| td|| td	ddd}|||}t ddgd d}|d u rM| }t|| td|| d S )
N)r\   z3 daysr_   r^   r]   r[   r]   r^   r   r&   r\   r[   r   r_   )r   r   r`   r'   r   r   ra   )r   r!   rb   rF   rc   r   r   r   r   test_difference_sort   s"   z1TestTimedeltaIndexDifference.test_difference_sortN)rU   rV   rW   rd   re   r   r   r   r   rZ      s    rZ   )numpyr   rX   Zpandasr3   r   r   r   Zpandas._testingZ_testingr   Zpandas.tseries.offsetsr   r   rZ   r   r   r   r   <module>   s     D