a
    Gb/                     @   s  d dl mZ d dlmZ d dlZd dlZd dlmZ d dl	m
Z
mZmZ dd Zejded	d
dddddd ejdejejejejejejgdd Zejdg ddd Zdd Zejdg ddd Zejdde
d d!d"d#d#d$d%fd&e
d'd!d"d#d#d$d%fd(e
d)d$d*d+d,fd-e
d.d/fd0e
d#d1fd2e
d3d4fd5e
d3d6fd7e
d3d8d9d9d,fd:e
d3d;fd<e
d d;fd=e
d>d d?fd@e
d3dAfdBe
d3d3dCfdDe
d>dAfdEe
dFd;fdGe
d3dAfdHe
d'd"dIfdJe
d'dKdIfdLe
d dKdIfgdMdN ZejdOg dPdQdR ZejdSe
dTd/dUfe
d3d3d3d3d3d3d3d3dVdWfe
d3d1e
d3d/ dXfe
d3d1e
d3d/ dYfe
d3d1d+e
dZd/  d[fgd\d] Zd^d_ Zd`da Z ejdbe
dcde!ddffedcde!ddffeg ded
e!ddffgdfdg Z"ejdhdidj dkD dldm Z#dS )n    )	timedelta)productN)OutOfBoundsTimedelta)	Timedeltaoffsetsto_timedeltac                  C   s  t dddd} tdddj| ks.J tdddj| ksDJ tdj| ksVJ tdd	j| ksjJ tdd	j| ks~J | t dd
dd7 } tdj| ksJ tdddj| ksJ tdddj| ksJ tdddj| ksJ tdjdksJ dttdv sJ tdjdks,J dttdv sBJ tdtddksZJ tdtddksrJ tdtdd ksJ tdtdd ksJ tdtddksJ tdtddksJ tdtddksJ tdtddksJ td tdd ks J td!tdd"ks8J td#td$d%ksPJ td&tdd"kshJ td'tdd"ksJ td(tdd%ksJ td)tdd%ksJ td*tdd%ksJ td+tdd,ksJ td-tdd,ksJ td.tdd,ksJ td/tdd0ks(J td1tdd0ks@J td2tdd0ksXJ td3tdd0kspJ td4td5ksJ td6td7ksJ td8td7ksJ td9td7ksJ td:tddd;ksJ td<tddd;ksJ td=tddddd>ksJ td?tddddd> ks:J td?tddddd> ksZJ td@tdddddAdB ks|J tdCtddddDdAdB ksJ dE}tj	t
|dF tdG W d    n1 s0    Y  tj	t
|dF tdH W d    n1 s0    Y  dI}tj	t
|dF tdJ W d    n1 sD0    Y  dK}tj	t
|dF t  W d    n1 s~0    Y  dL}tj	t
|dF tdM W d    n1 s0    Y  dN}tj	t
|dF tddO W d    n1 s0    Y  t dd
ddt dPdQdd } tdRd
dj| ksJJ ttdStdSdkshJ ttdStdSdksJ ttdStdSd%ksJ tdT} tdT}|| ksJ ttdStdUksJ dL}tj	t
|dF tdV W d    n1 s0    Y  d S )WN
   Dm8[ns]i8dunitg      $@z10 daysdayssz10 days 00:00:10r   secondsi'  )r   millisecondsi )r   microsecondsl   >P- z0 days 22:58:59.999850l   @B]? z1 days 10:11:12.001z0:00:00r   )hoursz00:00:00z-1:00:00   z	-01:00:00z1 hz1 hourz1 hrz1 hoursz-1 hoursz1 mminutesz1.5 mZ   r   z1 minutez	1 minutesz1 sz1 secondz	1 secondsz1 msr   z1 milliz1 millisecondz1 usr   u   1 µsz1 microsz1 microsecondz1.5 microsecondz00:00:00.000001500z1 nsz00:00:00.000000001z1 nanoz1 nanosecondz10 days 1 hourr   r   z10 days 1 hz10 days 1 h 1m 1sr   r   r   r   z-10 days 1 h 1m 1sz-10 days 1 h 1m 1s 3us   )r   r   r   r   r   z-10 days 1 h 1.5m 1s 3us   'only leading negative signs are allowedmatchz-10 days -1 h 1.5m 1s 3usz10 days -1 h 1.5m 1s 3uszno units specifiedz3.1415zcannot construct a Timedeltazunit abbreviation w/o a numberZfoozMcannot construct a Timedelta from the passed arguments, allowed keywords are )Zdayi  msg      %@   Z1Hz0 days, 02:00:00zfoo bar)nptimedelta64astypeviewr   valuestrr   pytestraises
ValueErrorr   r   ZHourZSecond)expectedmsgresult r3   Nlib/python3.9/site-packages/pandas/tests/scalar/timedelta/test_constructors.pytest_construction   s    

(((&(*r5   itemr	   r   usr%   mhW)r   r   r   r   r   r   weeksnpdtypec                 C   sD   |\}}t d|dd}tf i || dij|ks@J d S )Nr   r
   r   )r'   r(   r)   r*   r   r+   )r<   r6   ZpykwargZnpkwargr0   r3   r3   r4   #test_td_construction_with_np_dtypes   s    r=   val)Z1sz-1sZ1usz-1usz1 dayz-1 dayz-23:59:59.999999z-1 days +23:59:59.999999z-1nsZ1nsz-23:59:59.999999999c                 C   s^   t | }t |j|ksJ t t||ks.J t |jdd|ksFJ t | |ksZJ d S )Nall)format)r   r+   r,   Z
_repr_base)r>   Ztdr3   r3   r4   test_td_from_repr_roundtrip   s
    rA   c                  C   s   d} t djd }tjt| d t | W d    n1 s>0    Y  tjt| d t ddd W d    n1 sx0    Y  tjt| d t tdd	 W d    n1 s0    Y  d S )
Nzint too (large|big) to convertZ1dayi3r#   i" r	   r   i r   )r   r+   r-   r.   OverflowErrorr   r   )r1   r+   r3   r3   r4   test_overflow_on_construction   s    &*rC   zval, unit, name))i  Mz months)i;  r:   z weeks)i  r	   z days)i ' r9   z hours)i)	r8   z minutes)l   }K r   z secondsc                 C   s   t | |}|dddk s$J t| | }tjt|d t| W d    n1 s\0    Y  t|d |d ks~J |d9 }|dddksJ tjtd| d t| W d    n1 s0    Y  t|d |d ksJ d S )Nr
   r   r   r#   r   -)	r'   r(   r)   r*   r,   r-   r.   r   r   )r>   r   nameZtd64r1   r3   r3   r4   $test_construction_out_of_bounds_td64   s    &&rH   zfmt,expzP6DT0H50M3.010010012S   2   r    r      )r   r   r   r   r   nanosecondszP-6DT0H50M3.010010012SiZP4DT12H30M5S         r   zP0DT0H0M0.000000123S{   rL   zP0DT0H0M0.00001Sr   zP0DT0H0M0.001Sr   r   Z
P0DT0H1M0Sr   ZP1DT25H61M61S   =   ZPT1Sr   ZPT0SZP1WT0S   r   ZP1Dr   ZP1DT1Hr   ZP1WZPT300Si,  ZP1DT0H0M00000000000SzPT-6H3M)r   r   z-PT6H3Mz	-PT-6H+3Mc                 C   s   t | |ksJ d S Nr   )fmtexpr3   r3   r4   test_iso_constructor   s    -rZ   rX   )ZPPPPPPPPPPPPZPDTHMSZP0DT999H999M999SzP1DT0H0M0.0000000000000SzP1DT0H0M0.SPz-Pc                 C   sD   d|  }t jt|d t|  W d    n1 s60    Y  d S )Nz#Invalid ISO 8601 Duration format - r#   r-   r.   r/   r   )rX   r1   r3   r3   r4   test_iso_constructor_raises#  s    
r]   zconstructed_td, conversiond   Z100ns)r   r   r   r;   r   r   r   rL   l   )D^_ Z1us1nsZ999nsZ990nsc                 C   s   | t |ksJ d S rV   rW   )Zconstructed_td
conversionr3   r3   r4   "test_td_constructor_on_nanoseconds5  s    ra   c                  C   s@   d} t jt| d tdd W d    n1 s20    Y  d S )Nz1Invalid type <class 'str'>. Must be int or float.r#   abcrQ   )r-   r.   	TypeErrorr   )r1   r3   r3   r4   test_td_constructor_value_errorP  s    rd   c                  C   s(   t tdd} t | }|| u s$J d S )Nr   r   )r   r'   r(   )r0   r2   r3   r3   r4   #test_timedelta_constructor_identityV  s    re   z%constructor, value, unit, expectationZ10szunit must not be specified)1r&   r    c                 C   sF   |\}}t j||d | ||d}W d    n1 s80    Y  d S )Nr#   r   )r-   r.   )constructorr+   r   ZexpectationrY   r$   _r3   r3   r4   test_string_with_unit]  s    	ri   r+   c                 C   s(   g | ] }t d |dD ]}d|qqS )z+-, )repeat )r   join).0Z
repetitionelementsr3   r3   r4   
<listcomp>m  s   ro   )r   r&   c                 C   sJ   | dkrdnd}t jt|d t|  W d    n1 s<0    Y  d S )Nz--zsymbols w/o a numberr"   r#   r\   )r+   r1   r3   r3   r4   test_string_without_numbersk  s    rp   )$Zdatetimer   	itertoolsr   Znumpyr'   r-   Zpandas._libs.tslibsr   Zpandasr   r   r   r5   ZmarkZparametrizelistitemsZint64Zint32Zint16Zfloat64Zfloat32Zfloat16r=   rA   rC   rH   rZ   r]   ra   rd   re   r/   ri   rp   r3   r3   r3   r4   <module>   s   }


,




