a
    Pf                     @   s:   d dl Zd dlZd dlmZ d dlmZ G dd dZdS )    N)TimedeltaArrayc                   @   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 )TestTimedeltaArrayConstructorc              	   C   s   t jg dddd}d}tjt|dP tjtdd" t	|
ddd	 W d    n1 sb0    Y  W d    n1 s0    Y  tjt|dP tjtdd" t	|d
g   W d    n1 s0    Y  W d    n1 s0    Y  d S )N)r            zm8[h]dtypem8[ns]%TimedeltaArray.__init__ is deprecatedmatchzOnly 1-dimensionalr   r   r   )nparrayZastypetmassert_produces_warningFutureWarningpytestraises
ValueErrorr   ZreshapeZsqueeze)selfarrdepr_msg r   i/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/tests/arrays/timedeltas/test_constructors.pytest_only_1dim_accepted	   s    Nz5TestTimedeltaArrayConstructor.test_only_1dim_acceptedc              	   C   s   t jg dt jdd d }d}d}tjt|dP tjt|d" t	|
dd	d
 W d    n1 sj0    Y  W d    n1 s0    Y  d S )N)r   r   r   r   i  i ʚ;zQInferred frequency None from passed values does not conform to passed frequency Dr
   r   ztimedelta64[ns]D)freq)r   r   int64r   r   r   r   r   r   r   view)r   r   msgr   r   r   r   test_freq_validation   s    z2TestTimedeltaArrayConstructor.test_freq_validationc              	   C   sp   d}t jt|dJ tjtdd tg d W d    n1 sD0    Y  W d    n1 sb0    Y  d S )Nr
   r   listr   r   r   )r   r   r   r   r   r   r   )r   r   r   r   r   test_non_array_raises%   s    z3TestTimedeltaArrayConstructor.test_non_array_raisesc                 C   sN   d}t jt|d( ttjg ddd W d    n1 s@0    Y  d S )Nz3dtype bool cannot be converted to timedelta64\[ns\]r   r"   boolr   )r   r   	TypeErrorr   _from_sequencer   r   r   r   r   r   r   test_other_type_raises+   s    z4TestTimedeltaArrayConstructor.test_other_type_raisesc                 C   s  d}t jt|d, tjtjg ddddd W d    n1 sD0    Y  d}t jt|d2 tjtjg dddtdd W d    n1 s0    Y  d	}t jt|d2 tjtjg dddtd
d W d    n1 s0    Y  d}t jt|d, tjtjg ddddd W d    n1 s<0    Y  d}t jt|d2 tjtjg dddtdd W d    n1 s0    Y  d S )Nz;dtype 'category' is invalid, should be np.timedelta64 dtyper   r"   i8r   categoryz8dtype 'int64' is invalid, should be np.timedelta64 dtyper   zCdtype 'datetime64\[ns\]' is invalid, should be np.timedelta64 dtypezM8[ns]zHdtype 'datetime64\[us, UTC\]' is invalid, should be np.timedelta64 dtypezM8[us, UTC]z;Supported timedelta64 resolutions are 's', 'ms', 'us', 'ns'zm8[Y])r   r   r   r   r&   r   r   r   r'   r   r   r   test_incorrect_dtype_raises0   s4    $$$&z9TestTimedeltaArrayConstructor.test_incorrect_dtype_raisesc              	   C   s   t jg ddd}t d}d}d}tjt|dJ tjt|d t	||d W d    n1 sd0    Y  W d    n1 s0    Y  d S )Nr"   zm8[s]r   r	   z&Values resolution does not match dtyper
   r   )
r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   "test_mismatched_values_dtype_unitsQ   s    
z@TestTimedeltaArrayConstructor.test_mismatched_values_dtype_unitsc                 C   s^   t jg ddd}tj|dd}|j|u s.J tj|dd}|j|usJJ |jj|usZJ d S )Nr"   r	   r   F)copyT)r   r   r   r&   Z_ndarraybase)r   datar   r   r   r   	test_copy[   s    z'TestTimedeltaArrayConstructor.test_copyc                 C   sD   d}t jt|d tjg td W d    n1 s60    Y  d S )Nz9dtype 'object' is invalid, should be np.timedelta64 dtyper   r   )r   r   r   r   r&   objectr'   r   r   r   test_from_sequence_dtyped   s    z6TestTimedeltaArrayConstructor.test_from_sequence_dtypeN)__name__
__module____qualname__r   r    r#   r(   r+   r,   r0   r2   r   r   r   r   r      s   !
	r   )	numpyr   r   Zpandas._testingZ_testingr   Zpandas.core.arraysr   r   r   r   r   r   <module>   s   