o
    7?e),                     @   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ejd
ddg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ejgd:d; Z ejd9ejejejgd<d= Z!d>d? Z"d@dA Z#dBdC Z$ejdDe%ddEdgdFdFggdGdH Z&ejdIg dJejdKej'e(gdLdM Z)dNdO Z*dPdQ Z+dRdS Z,dFS )TTestTimedeltasreadonlyTFc                 C   s>   t jg td}|r|jdd t|}tg }t|| d S )NdtypeF)write)nparrayobjectZsetflagsr   tmassert_index_equal)selfr   arrresultexpected r   e/home/www/facesmatcher.com/pyenv/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&   secondsZ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   r/   r3   r.   zm8[s])r   r   r   r   r    r   r   )r   r   r0   r   r   Z	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	   Z_from_sequence)r   r   msgr   r   r   test_to_timedelta_oob_non_nanoK   s   

"z-TestTimedeltas.test_to_timedelta_oob_non_nanoargr-      r7   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 arrayr9   rC   )r=   r>   	TypeErrorr   )r   rA   rC   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 ofr9   fooneverrG   r=   r>   
ValueErrorr   r   r?   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: foor9   rJ   r/   rL   )r   rA   r?   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 convertibler9   r   )secondrF   rG   )r=   r>   rM   r   r   r!   r;   rN   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 timedeltar9   rJ   barrL   rN   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 )NrJ   rS   rF   rG   1 day1 min)rU   rS   rV   )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applerD   rG   z1 daysr   )r   r   assert_numpy_array_equalr   r   r   r!   r"   r   r   r)   )r   Zinvalid_datar   r   r   'test_to_timedelta_invalid_errors_ignore   s   
z6TestTimedeltas.test_to_timedelta_invalid_errors_ignorezval, errors)
)Z1MT)z1 MT)Z1YT)z1 YT)Z1yT)z1 yT)Z1mF)z1 mF)rU   F)Z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 timedeltar9   rL   )r   valrC   r?   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 )Nr]   r   )r'   )r!   r;   r   Z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;   r]    ʚ;r,   r.   r   )
r   r    r   r   nanr   ZENDIANr)   r!   r;   )r   Ztimedelta_NaTactualr   serr   r   r   #test_to_timedelta_on_missing_values   s   

z2TestTimedeltas.test_to_timedelta_on_missing_valuesr[   c                 C   s&   t |}|jtddksJ d S )Nr;   r3   r   r<   r   r    r1   r   r[   re   r   r   r   *test_to_timedelta_on_missing_values_scalar   s   z9TestTimedeltas.test_to_timedelta_on_missing_values_scalarc                 C   s,   t |g}|d jtddksJ d S )Nr   r;   r3   rh   ri   r   r   r   (test_to_timedelta_on_missing_values_list   s   
"z7TestTimedeltas.test_to_timedelta_on_missing_values_listc                 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   r/   i;rc   i  r3   r   )r   aranger   r   rY   Zasi8)r   r   r   Z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   rB   errorr   r,   rF   r0   rC   r   rB   r/   )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 )Nrn   r   r,   rD   rp   )r   r   r   r   r   rY   )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%   ZInt64r   r&   r/   r(   )r   Zexpected_valZ
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.718001ru   )8:53:08.7180000001rv   )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!   r`   )r   rt   r   rw   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 datetime64r9   r.   i8)Zto_datetime64r   r   r=   r>   rM   r   view
isinstancer!   r`   r<   )r   Zfixed_now_tsZdt64rA   r?   Z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,   r/   )r   r!   NAr   r`   r;   r   r)   )r   any_numeric_ea_dtyperf   r   r   r   r   r   test_to_timedelta_numeric_ea!  s   z+TestTimedeltas.test_to_timedelta_numeric_eac                 C   s&   t ddd}td}||ksJ d S )NgUUUUUU?r5   r/   z0 days 00:19:59.999999998)r   r!   r`   r#   r   r   r   test_to_timedelta_fraction(  s   
z)TestTimedeltas.test_to_timedelta_fraction)-__name__
__module____qualname__r=   markparametrizer   r   r$   r+   r2   r8   r@   r   rl   Zreshaper!   Z	DataFramerI   rO   rP   rR   rT   rW   rZ   r\   r_   rb   rg   rd   r;   r}   rj   rk   rm   rq   rr   r   rs   r`   r   rx   r|   r   r   r   r   r   r   r
      st    
	

*
	
	




r
   c                 C   sL   t d tddg|   dd}t|}tddgdd}t|| d S )Npyarrowr   rB   z	[pyarrow]r   ztimedelta64[ns])r=   importorskipr   lowerr   r   r)   )r~   rf   r   r   r   r   r   test_from_numeric_arrow_dtype.  s
   
r   r0   r,   msc                 C   s<   t d ttdgd|  dd}t|}t|| d S )Nr   r   z	duration[z
][pyarrow]r   )r=   r   r   r   r   r   r)   )r0   r   r   r   r   r   test_from_timedelta_arrow_dtype7  s   
r   )datetimer   r   numpyr   r=   Zpandas.errorsr   Zpandasr!   r   r   r   r   Zpandas._testingZ_testingr   Zpandas.core.arraysr	   r
   r   r   r   r   r   r   r   r   <module>   s      	