o
    dB0                     @   sJ   d dl Zd dlZd dlmZmZmZ d dlmZ	 dd Z
G dd dZdS )    N)PeriodIndex
date_rangeperiod_rangec                 C   s   |  tjt| S )N)ZtakenprandomZpermutationlen)obj r	   [/app/.heroku/python/lib/python3.10/site-packages/pandas/tests/indexes/period/test_setops.py_permute   s   r   c                   @   sL   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S )TestPeriodIndexc              
   C   s  t dddd}t dddd}tg ddd}t dddd}t dddd}t ddd	d}t dddd}tg dd}	t dddd}
t d
ddd}t dddd}tg ddd}tg ddd}tg ddd}tg ddd}t dddd}t dddd}t dddd}t dddd}t ddd	d}tg ddd}tg ddd}t dddd}tg ddd}|||f|||f||	|
f|||f|||f|||f|||f|||ffD ]\}}}|j||d}|d u r| }t|| qd S )N1/1/2000D   freqperiods1/6/2000)
z
2000-01-06z
2000-01-07z
2000-01-08z
2000-01-09z
2000-01-10
2000-01-01z
2000-01-02z
2000-01-03z
2000-01-04z
2000-01-05r   1/4/2000   2000-01-01 09:00H2000-01-02 09:00)
r   2000-01-01 10:002000-01-01 11:002000-01-01 12:002000-01-01 13:00r   z2000-01-02 10:00z2000-01-02 11:00z2000-01-02 12:00z2000-01-02 13:00)2000-01-01 09:012000-01-01 09:032000-01-01 09:05T)r   r!   2000-01-01 09:08)r   r    r!   r#   r   M   
2000-04-01
   z
2003-01-01A
1998-01-01)
20032004200520062007Z1998Z19992000Z2001Z20021/3/20001/2/2000r   1/5/2000r   )
r1   r2   r   r3   r   r   z1/7/2000z1/8/2000z1/9/2000z	1/10/2000sort)r   r   unionsort_valuestmassert_index_equal)selfr5   other1rng1	expected1rng2other2	expected2rng3other3	expected3rng4other4	expected4rng5other5	expected5rng6other6	expected6rng7other7	expected7Zrng8Zother8Z	expected8rngotherexpectedZresult_unionr	   r	   r
   
test_union   sv   

zTestPeriodIndex.test_unionc                 C   s   t dddd}|d d j|dd  |d}t|| t|d d jt|dd  |d}|d u r9t|| t||sAJ t dddd}t dddd}|j||d}|tj|t|d}t|| d S )	Nr   	1/20/2000r   r   r'   r4   W-WED)r   r6   r8   r9   r   equalContentsZastypeobject)r:   r5   indexresultindex2rR   r	   r	   r
   test_union_misc   s   &zTestPeriodIndex.test_union_miscc           	      C   s  t dddd}|d d j|dd  |d}t||dd  t|d d }t|dd  }|j||d}|d u rEt||dd  t||dd sQJ t dddd}t dddd}|j||d}tjg td	}t|| t ddd
d}|j||d}t|| d S )Nr   rT   r   r   rU   r'   r4   rV   )ZdtypeZ2D)	r   intersectionr8   r9   r   rW   pdIndexrX   )	r:   r5   rY   rZ   leftrightr[   rR   Zindex3r	   r	   r
   test_intersection   s"   z!TestPeriodIndex.test_intersectionc                 C   s  t ddddd}t ddddd}t ddddd}t ddddd}t dddd d}t d	d
ddd}tg ddd}||f||f||ffD ]!\}	}
|j|	|d}t||
 |j|
jks[J |j|
jkscJ qBtg dddd}tg dddd}tddgddd}tg dddd}tddgdd d}t d	d
ddd}tg ddd}||f||f||ffD ](\}	}
|j|	|d}|d u r|
 }
t||
 |j|
jksJ |jdksJ qtdddd}	|	dd |	}t	|dksJ |	|	dd }t	|dksJ d S )Nz6/1/2000z	6/30/2000r   idx)r   namez	5/15/2000z	6/20/2000rQ   z7/1/2000z	7/31/2000)rd   r   r4   )z
2011-01-05
2011-01-04
2011-01-02
2011-01-03)re   rf   z
2011-02-02z
2011-02-03re   rf   z	6/15/2000r"   r   r   )
r   r   r]   r8   r9   rd   r   r7   r   r   )r:   r5   baser>   r@   rA   rC   rD   rF   rP   rR   rZ   r	   r	   r
   test_intersection_cases   sb   z'TestPeriodIndex.test_intersection_casesc              	   C   s  g d}t |dd}tdddd}|}t |dd}tdddd}t g ddd}t |dd}	t g dd}
|	}g d	}t |d
d}tdd
dd}|}t g ddd}t ddgdd}t dgdd}g d}t |dd}tdddd}t g ddd}g d}t |dd}tdddd}t ddgdd}|||f|||f|	|
|f|||f|||f|||f|||ffD ]\}}}|j||d}|d u rt|r| }t|| qd S )Nr0   r   r   r   r   r   r   )r1   r2   r   )r   r   r   r   r   r   r   )r    r   r!   r"   r   r!   r    )
2000-02-01r   z
2000-06-01z
2000-07-01z
2000-05-01
2000-03-01r&   r$   r&   r%   )rj   r   rk   )r*   r.   r-   r,   r+   r(   r)   r   r.   r-   r4   )r   r   
differencer   r7   r8   r9   )r:   r5   Z
period_rngr<   r;   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   Zresult_differencer	   r	   r
   test_difference   sP   		zTestPeriodIndex.test_differencec                 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 )	NZ20160920Z20160925r   r   Z20160921Z20160924r   Z20160922)r   r   rl   r8   r9   Zassert_attr_equal)r:   r5   rY   rQ   rR   Zidx_diffr	   r	   r
   test_difference_freq:  s   z$TestPeriodIndex.test_difference_freqc                 C   s0   t ddd}||}||}t|| d S )N
2011-01-01   r   )r   appendr]   r8   r9   )r:   rc   idx_duprZ   r	   r	   r
   "test_intersection_equal_duplicatesL  s   

z2TestPeriodIndex.test_intersection_equal_duplicatesc                 C   sV   t ddd}||}t ddd}||}||}tg ddd}t|| d S )Nro   rp   rq   rf   )ro   ro   rf   rf   rg   rg   r   r   )r   rr   r6   r   r8   r9   )r:   rc   rs   Zidx2Zidx2_duprZ   rR   r	   r	   r
   test_union_duplicatesS  s   


z%TestPeriodIndex.test_union_duplicatesN)__name__
__module____qualname__rS   r\   rb   ri   rm   rn   rt   ru   r	   r	   r	   r
   r      s    wDAr   )numpyr   Zpandasr^   r   r   r   Zpandas._testingZ_testingr8   r   r   r	   r	   r	   r
   <module>   s    