o
    i&                     @   sv   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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/d0efd1efd2efd3efd4efd5efd6d7d8d9g
d:d; Zd<d= Zd>d? Zd@dA ZejdBejejgdCdD Z dEdF Z!dGdH Z"dIdJ Z#ejdKe$ddLdgdMdMggdNdO Z%ejdPg dQejdRej&e'gdSdT Z(dUdV Z)dMS )W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   _/var/www/edux/Edux_v2/venv/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htimedelta64[s]ztimedelta64[D]Dc                 C   sF   t jdgd |d}t||d}tt d|gd }t|| d S )Nr      r   r1   )r   r   r   r   r!   r   r   )r   r   r2   r   r   r   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   r8   r   zQCannot convert -9223372036854775807 seconds to timedelta64\[ns\] 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_nanoJ   s   

"z-TestTimedeltas.test_to_timedelta_oob_non_nanoargr/      r:   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_dataframeZ   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_errorsc   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, warning1Mz1 M1Yz1 Y1yz1 y)1mN)z1 mN)rY   N)2dayNc                 C   sB   d}t j||dd t| W d    d S 1 sw   Y  d S )Nz=Units 'M', 'Y' and 'y' do not represent unambiguous timedeltaF)r=   check_stacklevel)r   assert_produces_warningr   )r   valwarningrC   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 )Nrj   r   )r(   )r"   r>   r   rf   r   r   	Timedeltar   )r   valsr   r   r   r   r   +test_to_timedelta_inference_without_warning   s   

z:TestTimedeltas.test_to_timedelta_inference_without_warningc                 C   s   t d}ttdt jg}tt dd|gtj dd}t|| tjt	dd tdt
jg}W d    n1 s=w   Y  |jdksIJ t|}t|| d S )	Nr>   rj    ʚ;r.   r0   r   zInferring timedelta64r<   )r   r!   r   r   nanr   ENDIANr+   rf   FutureWarningr"   r>   r   )r   timedelta_NaTactualr   serr   r   r   #test_to_timedelta_on_missing_values   s   

z2TestTimedeltas.test_to_timedelta_on_missing_valuesrg   c                 C   s&   t |}|jtddksJ d S )Nr>   r5   )r   r?   r   r!   r3   )r   rg   ru   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;rp   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 )Nr}   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"   rm   )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"   rm   r?   )r   fixed_now_tsdt64rE   rC   arg2r   r   r   r   test_to_timedelta_zerodim	  s   


z(TestTimedeltas.test_to_timedelta_zerodim)*__name__
__module____qualname__r@   markparametrizer   r   r%   r-   r4   r;   rD   r   ry   reshaper"   	DataFramerM   rS   rT   rV   rX   r[   r_   rs   ri   rl   ro   rw   rq   r>   rx   r|   r   r   r   r   rm   r   r   r   r   r   r   r   r
      s    
	

*
	
	



r
   )datetimer   r   numpyr   r@   pandas.errorsr   pandasr"   r   r   r   r   pandas._testing_testingr   pandas.core.arraysr	   r
   r   r   r   r   <module>   s    