o
    5cR                     @   s   d dl m Z  d dlZd dlZd dlZd dlm  mZ d dl	Z
d dl	mZmZmZmZmZmZ d dlmZ d dlmZ d dlmZmZmZ e ddde dddZZd	d
 ZG dd dZG dd dZG dd dZdS )    )datetimeN)	DataFrameDatetimeIndexIndexSeriesbdate_range
date_range)
Int64Index)	BMonthEndMinuteMonthEndi     i  c                  C   sJ   t ddd} tt | | | g W d    d S 1 sw   Y  d S )N
2016-01-01   periods)r   tmassert_produces_warningFutureWarning
union_many)dti r   `/var/www/html/gps/gps/lib/python3.10/site-packages/pandas/tests/indexes/datetimes/test_setops.pytest_union_many_deprecated   s   "r   c                   @   s  e Zd Zg dZdd Zejdej	e
egdd Zejde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d Zejdg ddd Zejdd d!gd"d# Zd$d% Zejded&d' Zd(d) Zd*d+ Zejdg d,d-d. Zd/d0 Zd1S )2TestDatetimeIndexSetOps)NUTC
Asia/Tokyo
US/Easternzdateutil/Asia/Singaporedateutil/US/Pacificc                 C   s@   t d}|d d }|dd  }|j||d}t || d S N
      sort)r   makeDateIndexunionassert_index_equal)selfr#   
everythingfirstsecondr%   r   r   r   test_union20   s
   
z#TestDatetimeIndexSetOps.test_union2boxc           	      C   sX   t d}|d d }|dd  }|j||d}||j}|j||d}t || d S r   )r   r$   r%   valuesr&   )	r'   r#   r,   r(   r)   r*   expectedcaseresultr   r   r   test_union37   s   

z#TestDatetimeIndexSetOps.test_union3tzc                 C   s>  t ddd|d}t ddd|d}t ddd|d}tt|t| }t ddd|d}t ddd|d}t ddd|d}	tt|t|d d	  }
t ddd|d}tg |d
}t ddd|d}|}||||f|||	|
f||||ffD ]+\}}}}|j||d}t|| |j||d}|d u rt|| qqt|| qqd S )N1/1/2000Dr!   freqr   r2   1/6/2000r    1/4/2000   r   r2   r"   )r   r   listr%   r   r&   )r'   r2   r#   rng1other1	expected1expected1_notsortedrng2other2	expected2expected2_notsortedrng3other3	expected3expected3_notsortedrngotherexpexp_notsortedresult_unionr   r   r   
test_unionC   s.   


z"TestDatetimeIndexSetOps.test_unionc                 C   sl   t g d}t | dd}|j||d}t|| |d d j||d}t|| |j|jks4J d S )N)z
2000-01-03z
2000-01-01z
2000-01-02inferr6   r"   r   )r   sort_valuesr%   r   r&   r6   )r'   r#   idxorderedr0   r   r   r   test_union_coveragec   s   z+TestDatetimeIndexSetOps.test_union_coveragec                 C   sp   t dddd}t dddd}|j||d}t|t|dd   }|d u r,tt|}nt|}t|| d S )N1/1/2012   3Hr   r6   4Hr"   r   )r   r%   r;   r   sortedr   r&   )r'   r#   rng_arng_br0   rJ   r   r   r   test_union_bug_1730m   s   z+TestDatetimeIndexSetOps.test_union_bug_1730c                 C   sP   t dg}t g d}|j||d}t g d}|d u r | }t|| d S )N2012-05-11 15:19:49.695000)2012-05-29 13:04:21.3220002012-05-11 15:27:24.8730002012-05-11 15:31:05.350000r"   )r]   r^   r_   r`   )r   r%   rP   r   r&   )r'   r#   leftrightr0   rJ   r   r   r   test_union_bug_1745y   s   
z+TestDatetimeIndexSetOps.test_union_bug_1745c                 C   sp   ddl m} tdd}||dd }|j||d}t|t| }|d u r,tt|}nt|}t|| d S )Nr   
DateOffsetz
2013-01-01z
2013-02-01   )minutesr"   )	pandasre   r   r%   r;   r   rY   r   r&   )r'   r#   re   ra   rb   r0   rJ   r   r   r   test_union_bug_4564   s   
z+TestDatetimeIndexSetOps.test_union_bug_4564c                 C   s@   t ddd}d |j_|j||d}t|| |jd u sJ d S )N20150101r    r   r"   )r   _datar6   r%   r   r&   )r'   r#   r.   r0   r   r   r   test_union_freq_both_none   s
   z1TestDatetimeIndexSetOps.test_union_freq_both_nonec                 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 )Nr   r!   r   )r   r   r   rU   )   r   r   r4   )r   r6   r%   r   r&   )r'   r   ra   rb   r0   r   r   r   test_union_freq_infer   s   
z-TestDatetimeIndexSetOps.test_union_freq_inferc                 C   sv   t dddd}ttjt||}t dddd}ttjt||}t||d}t dddd}t|j	| d S )Nz1/1/1999rT   MSrO   z1/1/1980z	12/1/2001)s1s2)
r   r   nprandomrandnlenr   r   r&   index)r'   r<   rp   r@   rq   dfrJ   r   r   r   test_union_dataframe_index   s   z2TestDatetimeIndexSetOps.test_union_dataframe_indexc                 C   s@   t tddd}tdddd}|j||d |j||d d S )	Nr      rm   z2012-01-03 00:00:00r    r4   )startr   r6   r"   )r	   rr   aranger   r%   )r'   r#   i1i2r   r   r   test_union_with_DatetimeIndex   s   z5TestDatetimeIndexSetOps.test_union_with_DatetimeIndexc                    s   t d}|dd   | }t | sJ  fddtjttfD }|D ]}||}t | s6J q'tg d}||}tg t	d}t 
|| d S )Nr    r!   c                    s   g | ]}| j qS r   )r-   ).0klassr*   r   r   
<listcomp>   s    z>TestDatetimeIndexSetOps.test_intersection2.<locals>.<listcomp>)abc)dtype)r   r$   intersectionequalContentsrr   arrayr   r;   r   objectr&   )r'   r)   	intersectcasesr/   r0   thirdr.   r   r   r   test_intersection2   s   



z*TestDatetimeIndexSetOps.test_intersection2)Nr   r   r   c                 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 ]\}
}||
}t|| |j|jksYJ qBtg d|dd}tg d|dd}tddg|dd}tg d|dd}tddg|d d}t d	d
d|dd}tg |dd}	|	jd u sJ ||f||f||	ffD ]!\}
}|j|
|d}|d u r| }t|| |j|jksJ qd S )N6/1/2000z	6/30/2000r4   rQ   )r6   namez	5/15/2000z	6/20/2000rI   z7/1/2000z	7/31/2000)z
2011-01-05
2011-01-04
2011-01-02z
2011-01-03)r2   r   )r   r   z
2011-02-02z
2011-02-03r   r   )r6   r2   r   r"   )r   r   r   r   r&   r6   rP   )r'   r2   r#   baser@   rB   rD   rF   rng4	expected4rH   r.   r0   r   r   r   test_intersection   sP   


z)TestDatetimeIndexSetOps.test_intersectionr6   TBc                 C   s  |}t dd||d}|dd |}t|dksJ |j|jks#J ||dd }t|dks4J |j|jks<J |dk}|d d |dd  }t||d d  |ra|j|jksaJ |dd  |d d }t||d d  |r|j|jksJ d S d S )Nr   z	6/15/2000)r6   r2   r   r   r   )r   r   ru   r6   r   r&   )r'   tz_aware_fixturer6   r2   rH   r0   
check_freqr   r   r   test_intersection_empty  s&   z/TestDatetimeIndexSetOps.test_intersection_emptyc                 C   sn   ddl m} tdddd}||dd }tt ||@ }W d    n1 s(w   Y  t|dks5J d S )	Nr   rd   rT   rU   12HrW   r   )hours)rh   re   r   r   r   r   ru   )r'   re   index_1index_2r0   r   r   r   test_intersection_bug_17085  s   
z2TestDatetimeIndexSetOps.test_intersection_bug_1708c                 C   s   g d}t ||d}tddd|d}t ||d}t ||d}tddd|d}t |d d |d}	t ||d}
t g |d}t ||d}|||f|||	f|
||ffD ]\}}}|||}|d u rgt|rg| }t|| qPd S )	N)z1/2/2000z1/3/2000r3   r8   z1/5/2000r:   r7   r4   r!   r5   r8   r   )r   r   
differenceru   rP   r   r&   )r'   r2   r#   	rng_datesr<   r=   r>   r@   rA   rB   rD   rE   rF   rH   rI   r.   result_diffr   r   r   test_difference?  s&   z'TestDatetimeIndexSetOps.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 )	N2016092020160925r4   rO   2016092120160924r6   20160922)r   r   r   r   r&   assert_attr_equal)r'   r#   rv   rI   r.   idx_diffr   r   r   test_difference_freqZ  s   z,TestDatetimeIndexSetOps.test_difference_freqc                 C   sH   t dtddddd}t dtddddd}t|||dks"J d S )	NzQ-JANi        d   )r6   rz   r   b   rm   )r   r   ru   r   )r'   r#   dti1dti2r   r   r   test_datetimeindex_diffj  s   z/TestDatetimeIndexSetOps.test_datetimeindex_diff)Nr   r   c                 C   s  t ddd|d}|d d |dd }|j|jksJ |j|jks%J |j|jks-J |d d |dd }|j|jksBJ |j|jksJJ |j|jksRJ |d d |dd }|j|jksgJ |jd u snJ |j|jksvJ |d d |d	d
 }|j|jksJ |jdksJ |j|jksJ tt|d	d
 dd}|d d |}|jd u sJ |j|jksJ |j|jksJ |d d |}|jd u sJ |j|jksJ |j|jksJ d S )Nr3   z1/1/2002rQ   )r   r2   2   r      <      K   r4   rI   r   )	r   r%   r   r6   r2   r   freqstrr   r;   )r'   r2   rH   r0   nofreqr   r   r   test_setops_preserve_freqo  s4   z1TestDatetimeIndexSetOps.test_setops_preserve_freqc                 C   sJ   t g ddd}|d d d |dd d }|d d }t|| d S )N)z
2018-12-31z
2019-03-31z
2019-06-30z
2019-09-30z
2019-12-31z
2020-03-31zQ-DECrO   rm   r   r   )r   r   r   r&   )r'   r   r0   r.   r   r   r   &test_intersection_non_tick_no_fastpath  s   z>TestDatetimeIndexSetOps.test_intersection_non_tick_no_fastpathN)__name__
__module____qualname__r2   r+   pytestmarkparametrizerr   r   r   r;   r1   rM   rS   r\   rc   ri   rl   rn   rx   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   %   s<    



		
;



"r   c                   @   sd   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Ze	j
dd Zejdddgdd ZdS )TestBusinessDatetimeIndexc                 C   s   t tt}|d d }|dd }|j||d}t|tsJ |d d }|dd  }|j||d}t|ts9J |d d }|dd }|j||d}t|tsSJ |d u rct|j||d| ntt	|t	| }t|j||d| t
ttt d}|j||d}t|tsJ d S )Nr    r!   r"   rO   )r   STARTENDr%   
isinstancer   r   r   r&   r;   r   r
   )r'   r#   rH   ra   rb   	the_unionr.   r   r   r   rM     s(   
z$TestBusinessDatetimeIndex.test_unionc                 C   s   t ddt d}|dd  }|d d }|j||d}|d u r&t|| ntt|dd  t|d d  }t|| |dd  }|dd }|j||d}|dd  }t|| d S )	Nr3   r   rW   r    r   r"   rf   #   )r   r   r%   r   r&   r   r;   )r'   r#   rH   r<   r@   r   r.   r   r   r   test_union_not_cacheable  s   $z2TestBusinessDatetimeIndex.test_union_not_cacheablec                 C   s   t ddt d}|dd  }|d d }||}|dd }t|| t|ts,J |j|jks4J ||t}t|| |d d |dd  }tg }t|| d S )Nr3   r   rW   r    r   )	r   r   r   r   r&   r   r   r6   view)r'   rH   r<   r@   the_intr.   r   r   r   r     s   
z+TestBusinessDatetimeIndex.test_intersectionc                 C   s>   t dd}t dd}||}t|| |j|jksJ d S )N
11/30/2011
12/31/2011
12/10/2011
12/20/2011r   r   r   r&   r6   r'   r   r   r0   r   r   r   test_intersection_bug  s
   


z/TestBusinessDatetimeIndex.test_intersection_bugc                 C   s:   t dt dg}t|dd}||}t|| d S )Nz
2020-01-01z
2020-02-01r   r   )pd	Timestampr   r   r   r&   )r'   r-   rQ   resr   r   r   test_intersection_list  s   
z0TestBusinessDatetimeIndex.test_intersection_listc           
      C   z   ddl m} |d}tddd}tddd}tddd}tddd}t|||t d}t|||t d}	|j|	|d	 d S )
Nr   )timezoner     r   r   r!   rz   endr2   r6   r"   )pytzr   r   r   r   r%   )
r'   r#   r   r2   early_start	early_end
late_startlate_endearly_drlate_drr   r   r   test_month_range_union_tz_pytz  s   z8TestBusinessDatetimeIndex.test_month_range_union_tz_pytzc           
      C   r   )
Nr   )dateutil_gettzr   r   r   r   r!   r   r"   )pandas._libs.tslibs.timezonesr   r   r   r   r%   )
r'   r#   r   r2   r   r   r   r   r   r   r   r   r   "test_month_range_union_tz_dateutil  s   z<TestBusinessDatetimeIndex.test_month_range_union_tz_dateutilr#   FNc                 C   sV   t tdtdtdg}|j||d}t tdtdg}t|| d S )Nz
2019-12-13z
2019-12-12r"   )r   r   r   r   r   r&   )r'   r#   idx1r0   r.   r   r   r   test_intersection_duplicates  s   z6TestBusinessDatetimeIndex.test_intersection_duplicates)r   r   r   rM   r   r   r   r   r   tdskip_if_windowsr   r   r   r   r   r   r   r   r   r     s    $
r   c                	   @   s@   e Zd Zdd Zdd Zejdddde	d	gd
d Z
dS )TestCustomDatetimeIndexc                 C   s   t ttdd}|d d }|dd }|j||d}t|ts!J |d d }|dd  }|||}t|ts:J |d d }|dd }|j||d}t|tsTJ |d u rct|j||d| t	ttt
 d}|j||d}t|tsyJ d S )NCrO   r    r!   r"   )r   r   r   r%   r   r   r   r   r&   r   r
   )r'   r#   rH   ra   rb   r   r   r   r   rM   -  s$   z"TestCustomDatetimeIndex.test_unionc                 C   sF   t dddd}t dddd}||}t|| |j|jks!J d S )Nr   r   r   rO   r   r   r   r   r   r   r   r   N  s
   
z-TestCustomDatetimeIndex.test_intersection_bugr2   Nr   zEurope/Berlinic                 C   sJ   t ddd|d}t ddd|d}||}t ddd|d}t|| d S )Nz
2020-03-27r!   r4   )r   r6   r2   z
2020-03-30rm   )r   r   r   r&   )r'   r2   r   idx2r0   r.   r   r   r    test_intersection_dst_transitionV  s
   
z8TestCustomDatetimeIndex.test_intersection_dst_transition)r   r   r   rM   r   r   r   r   r   FixedOffsetr   r   r   r   r   r   ,  s    !r   ) r   numpyrr   r   r   pandas.util._test_decoratorsutil_test_decoratorsr   rh   r   r   r   r   r   r   r   pandas._testing_testingr   pandas.core.apir	   pandas.tseries.offsetsr
   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s&         	