o
    dU)                     @   s~   d dl mZmZ d dlZd dlZd dlmZ d dlZ	d dlm
Z
mZmZmZ d dlmZ d dlmZ G dd dZdd	 ZdS )
    )time	timedeltaN)OutOfBoundsTimedelta)SeriesTimedeltaIndexisnato_timedelta)TimedeltaArrayc                
   @   s  e Zd Zejdddgdd Zdd Zdd	 Zd
d Z	dd Z
ejdddgddgddgddgddggdd Zdd Zejdedddeedddgejdg dd d! Zd"d# Zejdd$dgd$gd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zejd/g d0d1d2 Zd3d4 Zd5d6 Zd7d8 Zejd9ejejgd:d; Zd<d= Z d>d? Z!d@dA Z"ejdBe#ddCdgdDdDggdEdF Z$ejdGg dHejdIej%e&gdJdK Z'dLdM Z(dNdO Z)dDS )PTestTimedeltasreadonlyTFc                 C   s>   t jg td}|r|jdd t|}tg }t|| d S )NdtypeF)write)nparrayobjectsetflagsr   tmassert_index_equal)selfr   arrresultexpected r   i/var/www/html/visualizacion-main/env/lib/python3.10/site-packages/pandas/tests/tools/test_to_timedelta.pytest_to_timedelta_readonly   s   z)TestTimedeltas.test_to_timedelta_readonlyc                 C   s    t ddg}t| sJ d S )N )r   r   all)r   r   r   r   r   test_to_timedelta_null!   s   z%TestTimedeltas.test_to_timedelta_nullc                 C   sB   t ttddg}tttddg}t|| d S )N   s)r   r   r   timedelta64pdIndexr   r   r   r   r   r   r   r   %test_to_timedelta_same_np_timedelta64%   s   z4TestTimedeltas.test_to_timedelta_same_np_timedelta64c                 C   s:   t tddtdddg}tt ddg}t|| d S )Nr   days)r'   seconds1dz1days 00:00:01r   r   r   r   assert_series_equalr   r   r   r   r   r   test_to_timedelta_series+   s   z'TestTimedeltas.test_to_timedelta_seriesc                 C   sB   t tddtdddg}tddgdd}t|| d S )Nr   ns
   r    m8[ns]unit)r   r   r!   astyper   r   r   r$   r   r   r   test_to_timedelta_units1   s
   z&TestTimedeltas.test_to_timedelta_unitszdtype, unitint64r    mhztimedelta64[s]ztimedelta64[D]Dc                 C   sZ   t jdgd |d}t||d}|dkrdnd}tt d|gd |d}t|| d S )Nr      r   r1   r5   r0   zm8[s])r   r   r   r   r!   r   r   )r   r   r2   r   r   	exp_dtyper   r   r   r   test_to_timedelta_units_dtypes9   s
   z-TestTimedeltas.test_to_timedelta_units_dtypesc                 C   s   t jtjjd gdd}d}tjt|d t| W d    n1 s$w   Y  tjt|d t	| W d    n1 s?w   Y  tjt|d t
| W d    d S 1 s\w   Y  d S )Nr   ztimedelta64[m]r   zPCannot convert -9223372036854775807 minutes to timedelta64\[s\] without overflowmatch)r   r   r"   NaT_valuepytestraisesr   r   r   r	   _from_sequence)r   r   msgr   r   r   test_to_timedelta_oob_non_nanoK   s   

"z-TestTimedeltas.test_to_timedelta_oob_non_nanoargr/      r9   errors)ignoreraisecoercec                 C   s@   t jtdd t||d W d    d S 1 sw   Y  d S )Nz	1-d arrayr<   rG   )r@   rA   	TypeErrorr   )r   rE   rG   r   r   r   test_to_timedelta_dataframe[   s   "z*TestTimedeltas.test_to_timedelta_dataframec                 C   sF   d}t jt|d tdgdd W d    d S 1 sw   Y  d S )Nzerrors must be one ofr<   fooneverrK   r@   rA   
ValueErrorr   r   rC   r   r   r    test_to_timedelta_invalid_errorsd   s   "z/TestTimedeltas.test_to_timedelta_invalid_errorsr   c                 C   sD   d}t jt|d t|dd W d    d S 1 sw   Y  d S )Nzinvalid unit abbreviation: foor<   rN   r1   rP   )r   rE   rC   r   r   r   test_to_timedelta_invalid_unitj   s   "z-TestTimedeltas.test_to_timedelta_invalid_unitc                 C   s`   d}t jt|d ttdd W d    n1 sw   Y  ttddddtju s.J d S )NzIValue must be Timedelta, string, integer, float, timedelta or convertibler<   r   )secondrJ   rK   )r@   rA   rQ   r   r   r"   r>   rR   r   r   r   test_to_timedelta_timeq   s    z%TestTimedeltas.test_to_timedelta_timec                 C   sD   d}t jt|d tddg W d    d S 1 sw   Y  d S )Nz*Could not convert 'foo' to NumPy timedeltar<   rN   barrP   rR   r   r   r   test_to_timedelta_bad_valuez   s   "z*TestTimedeltas.test_to_timedelta_bad_valuec                 C   sL   t ttjtjgtddgdd t tdtjdgtg ddd d S )NrN   rW   rJ   rK   1 day1 min)rY   rW   rZ   )r   r   r   r"   r>   r   )r   r   r   r   "test_to_timedelta_bad_value_coerce   s   z1TestTimedeltas.test_to_timedelta_bad_value_coercec                 C   s   d}|t |ddksJ ddg}ttj|tdt |dd tddg}t|t |dd t	ddg}t
|t |dd d S )NapplerH   rK   z1 daysr   )r   r   assert_numpy_array_equalr   r   r   r"   r#   r   r   r+   )r   invalid_datar   r   r   'test_to_timedelta_invalid_errors_ignore   s   
z6TestTimedeltas.test_to_timedelta_invalid_errors_ignorezval, errors)
)1MT)z1 MT)1YT)z1 YT)1yT)z1 yT)1mF)z1 mF)rY   F)2dayFc                 C   sP   d}|r"t jt|d t| W d    d S 1 sw   Y  d S t| d S )Nz=Units 'M', 'Y' and 'y' do not represent unambiguous timedeltar<   rP   )r   valrG   rC   r   r   r   !test_unambiguous_timedelta_values   s   
"z0TestTimedeltas.test_unambiguous_timedelta_valuesc                 C   sL   t tddg}t dgt}t|| t tdg}t|| d S )Nr   r    00:00:01)r   r   r!   applyr   r   r+   r,   r   r   r   test_to_timedelta_via_apply   s
   z*TestTimedeltas.test_to_timedelta_via_applyc                 C   sb   dt jg}td  t|}W d    n1 sw   Y  tt jddt jg}t|| d S )Nrg   r   )r(   )r"   r>   r   assert_produces_warningr   r   	Timedeltar   )r   valsr   r   r   r   r   +test_to_timedelta_inference_without_warning   s   

z:TestTimedeltas.test_to_timedelta_inference_without_warningc                 C   sr   t d}ttdt jg}tt dd|gtj dd}t|| tdtj	gdd}t|}t|| d S )Nr>   rg    ʚ;r.   r0   r   )
r   r!   r   r   nanr   ENDIANr+   r"   r>   )r   timedelta_NaTactualr   serr   r   r   #test_to_timedelta_on_missing_values   s   

z2TestTimedeltas.test_to_timedelta_on_missing_valuesre   c                 C   s&   t |}|jtddksJ d S )Nr>   r5   )r   r?   r   r!   r3   )r   re   rr   r   r   r   *test_to_timedelta_on_missing_values_scalar   s   z9TestTimedeltas.test_to_timedelta_on_missing_values_scalarc                 C   sF   t ddddd  }t|dd}t jddd	d
d}t|j| d S )Nr   r   gư>ir    r1   i;rn   i  r5   r   )r   aranger   r   r]   asi8)r   r   r   expected_asi8r   r   r   test_to_timedelta_float   s   z&TestTimedeltas.test_to_timedelta_floatc                 C   sD   t jg dtd}t|ddd}tddtjgdd}t|| d S )	Nr   rF   errorr   r.   rJ   r2   rG   r   rF   r1   )r   r   r   r   r"   r>   r   r   )r   r   r   r   r   r   r   %test_to_timedelta_coerce_strings_unit   s   z4TestTimedeltas.test_to_timedelta_coerce_strings_unitc                 C   s0   t jg dtd}t|ddd}t|| d S )Nrz   r   r.   rH   r|   )r   r   r   r   r   r]   )r   r   r   r   r   r   %test_to_timedelta_ignore_strings_unit   s   z4TestTimedeltas.test_to_timedelta_ignore_strings_unitzexpected_val, result_valr&   Nc                 C   s:   t tdd|g}tt d|gdddd}t|| d S )Nr   r&   Int64r   r'   r1   r*   )r   expected_val
result_valr   r   r   r   r   &test_to_timedelta_nullable_int64_dtype   s   z5TestTimedeltas.test_to_timedelta_nullable_int64_dtype)inputr   ))z8:53:08.71800000001z8:53:08.718)8:53:08.718001r   )8:53:08.7180000001r   )z-8:53:08.71800000001z-8:53:08.718)z8:53:08.7180000089z8:53:08.718000008funcc                 C   s"   t |}||}||ksJ d S )N)r"   rk   )r   r   r   r   r   r   r   r   &test_to_timedelta_precision_over_nanos   s   
z5TestTimedeltas.test_to_timedelta_precision_over_nanosc                 C   s   |  }t|}d}tjt|d t| W d    n1 s!w   Y  |d}t|}t|t	j
s7J |j|dksAJ d S )NzYValue must be Timedelta, string, integer, float, timedelta or convertible, not datetime64r<   r0   i8)to_datetime64r   r   r@   rA   rQ   r   view
isinstancer"   rk   r?   )r   fixed_now_tsdt64rE   rC   arg2r   r   r   r   test_to_timedelta_zerodim  s   


z(TestTimedeltas.test_to_timedelta_zerodimc                 C   sB   t dtjg|d}t|}t tjdddtjg}t|| d S )Nr   r   r.   r1   )r   r"   NAr   rk   r>   r   r+   )r   any_numeric_ea_dtypers   r   r   r   r   r   test_to_timedelta_numeric_ea  s   z+TestTimedeltas.test_to_timedelta_numeric_ea)*__name__
__module____qualname__r@   markparametrizer   r   r%   r-   r4   r;   rD   r   rv   reshaper"   	DataFramerM   rS   rT   rV   rX   r[   r_   rf   ri   rm   rt   ro   r>   ru   ry   r}   r~   r   r   rk   r   r   r   r   r   r   r   r   r
      sn    
	

*
	
	



r
   c                 C   sL   t d tddg|   dd}t|}tddgdd}t|| d S )Npyarrowr   rF   z	[pyarrow]r   ztimedelta64[ns])r@   importorskipr   lowerr   r   r+   )r   rs   r   r   r   r   r   test_from_numeric_arrow_dtype$  s
   
r   )datetimer   r   numpyr   r@   pandas.errorsr   pandasr"   r   r   r   r   pandas._testing_testingr   pandas.core.arraysr	   r
   r   r   r   r   r   <module>   s      