o
    Eh6                     @   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	m
Z
 d dlmZ ejdedddfe	dd	d
fe	dd	 d
fe	dddfe	dddddfe	ddddddfe
ddfgdd Zdd Zdd Zejdddgd d! Zd"d# Zejd$d%diddd&d'd(igd)d* ZG d+d, d,Zejdg d-d.d/ Zejdg d0d1d2 ZdS )3    N)array_to_timedelta64delta_to_nanosecondsints_to_pytimedelta)	Timedeltaoffsetszobj,expected   Dg  H0Ci)Zminutesg   |rXgBY>)seconds  g&.>gh㈵>g?)r	   millisecondsmicrosecondso      )Zdaysr	   r   r   gS$B}   c                 C   s   t | }||ks
J d S )N)r   )objexpectedresult r   Clib/python3.10/site-packages/pandas/tests/tslibs/test_timedeltas.pytest_delta_to_nanoseconds   s   r   c                  C   s0  t jdgdd} tjtdd t|  W d    n1 sw   Y  tjtdd td W d    n1 s9w   Y  tjtdd td	 W d    n1 sTw   Y  tjtdd tt d
 W d    n1 srw   Y  tjtdd tt d W d    d S 1 sw   Y  d S )Ni[zm8[ns]Zdtypez<class 'numpy.ndarray'>matchfloatg      ?intr         )nparraypytestraises	TypeErrorr   int64Zint32)r   r   r   r   test_delta_to_nanoseconds_error*   s    


"r#   c                  C   s   d} t dd}tjt| d t| W d    n1 sw   Y  t dd}tjt| d t| W d    d S 1 s@w   Y  d S )Nzadelta_to_nanoseconds does not support Y or M units, as their duration in nanoseconds is ambiguousr
   Yr   M)r   timedelta64r   r    
ValueErrorr   )msgZtdr   r   r   (test_delta_to_nanoseconds_td64_MY_raises:   s   

"r)   unitr$   r%   c                 C   sL   t jtd|  dd ttd|  W d    d S 1 sw   Y  d S )NzUnit z is not supported. Only unambiguous timedelta values durations are supported. Allowed units are 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns'r   r   )r   r    r'   r   r   r&   r*   r   r   r   !test_unsupported_td64_unit_raisesK   s   
"r,   c                   C   s.   t tddks
J t tdddksJ d S )Ng    _B)Znanoseconds)r   r   r   r   r   r   test_huge_nanoseconds_overflowW   s   r-   kwargsZSeconds)r	   ZNanosecondsZFoor   c                 C   sL   d}t jtt|d tdi |  W d    d S 1 sw   Y  d S )Nzcannot construct a Timedelta from the passed arguments, allowed keywords are [weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds]r   r   )r   r    r'   reescaper   )r.   Zerr_messager   r   r   test_kwarg_assertion]   s
   "r1   c                   @   s   e Zd Zdd Zdd ZdS )TestArrayToTimedelta64c                 C   sZ   t jddgddggtd}tjtdd t|dd	 W d    d S 1 s&w   Y  d S )
N1r   r   4r   zunit must not be specifiedr   sr+   )r   r   objectr   r    r'   r   )selfvaluesr   r   r   4test_array_to_timedelta64_string_with_unit_2d_raisesm   s   "zKTestArrayToTimedelta64.test_array_to_timedelta64_string_with_unit_2d_raisesc                 C   sJ   t d}d}tjt|d t| W d    d S 1 sw   Y  d S )N   z'values' must have object dtyper   )r   aranger   r    r!   r   )r7   r8   r(   r   r   r   +test_array_to_timedelta64_non_object_raisest   s
   

"zBTestArrayToTimedelta64.test_array_to_timedelta64_non_object_raisesN)__name__
__module____qualname__r9   r<   r   r   r   r   r2   l   s    r2   )r5   msusc                 C   st   t jdt jdd|  d}t|dd}|t}t|| t|dd}t j	dd	 |D td}t|| d S )
N   r   m8[]FZboxTc                 S   s   g | ]}t |qS r   )r   ).0xr   r   r   
<listcomp>   s    z,test_ints_to_pytimedelta.<locals>.<listcomp>)
r   r;   r"   viewr   Zastyper6   tmZassert_numpy_array_equalr   )r*   arrresr   r   r   r   test_ints_to_pytimedelta}   s   
rM   )r$   r%   ZpsZfsasc                 C   s   t jdt jdd|  d}tjtdd t|dd W d    n1 s'w   Y  d	}tjt|d t|d
d W d    d S 1 sGw   Y  d S )NrB   r   rC   rD   z\d{1,2}r   FrE   z4Only resolutions 's', 'ms', 'us', 'ns' are supportedT)r   r;   r"   rI   r   r    NotImplementedErrorr   )r*   rK   r(   r   r   r   $test_ints_to_pytimedelta_unsupported   s   "rP   )r/   Znumpyr   r   Zpandas._libs.tslibs.timedeltasr   r   r   Zpandasr   r   Zpandas._testingZ_testingrJ   ZmarkZparametrizer&   Zto_pytimedeltaZNanor   r#   r)   r,   r-   r1   r2   rM   rP   r   r   r   r   <module>   sH    



