o
    _~#gd*                  	   @   s   d dl m Z mZmZ d dlmZ d dlZd dlZd dlZd dl	m
Z
mZmZmZmZmZ d dlmZ G dd dZG dd de Zejd	ed
ddeddfedded
ddfgdd ZdS )    )datetime	timedeltatimezone)gettzN)OutOfBoundsDatetimeOutOfBoundsTimedelta	Timedelta	Timestampoffsets	to_offsetc                   @   s  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d Zdd Zdd Zejdeddeddeddgdd Zejdedddfed dd fedd!d"fedd#d$fgd%d& Zejd'ed(ed(d)d*gejd+d,ed,ejd,d-gejd.ejdd/gejd.gd0d1 Zejd2d3d4gd5d6 Zejd2d3d4gd7d8 Zd9d: Zejd;e !d<e"d<d<d=gd>d? Z#d@S )ATestTimestampArithmeticc                 C   sX   t d}tdd }t d}|| |ksJ || |ksJ t d}|| |ks*J d S )N2000/1/1Dd   z
2000/04/10z
1999/09/23)r	   r   )selfstampoffset_no_overflowexpected r   /var/www/static.ux5.de/https/Moving-Object-Detection-with-OpenCV/env/lib/python3.10/site-packages/pandas/tests/scalar/timestamp/test_arithmetic.pytest_overflow_offset   s   z,TestTimestampArithmetic.test_overflow_offsetc                 C   s  t dd}dtd }d}tjt|d ||  W d    n1 s&w   Y  tjt|d ||  W d    n1 sAw   Y  tjt|d ||  W d    n1 s\w   Y  t dd}tdd	 }d
}tjt|d ||  W d    n1 sw   Y  tjt|d ||  W d    n1 sw   Y  tjt|d ||  W d    d S 1 sw   Y  d S )Nz2017-01-13 00:00:00nsi3   zECannot cast -?20169940 days \+?00:00:00 to unit='ns' without overflowmatchr   r   l    d(	 zHCannot cast -?10000000000 days \+?00:00:00 to unit='ns' without overflow)r	   as_unitr
   Daypytestraisesr   r   )r   r   offset_overflowlmsg2lmsg3r   r   r   test_overflow_offset_raises'   s2   





"z3TestTimestampArithmetic.test_overflow_offset_raisesc                 C   sv   d}t dd}t dd}tjt|d ||  W d    n1 s&w   Y  ||  | | ks9J d S )NzResult is too largez2101-01-01 00:00:00r   z1688-01-01 00:00:00r   )r	   r   r   r   r   to_pydatetime)r   msgabr   r   r   test_overflow_timestamp_raisesJ   s   
 z6TestTimestampArithmetic.test_overflow_timestamp_raisesc                 C   s(   t d}|td }|j|jksJ d S )Nl   { |%*x r   )r	   r   
nanosecond)r   valresultr   r   r   test_delta_preserve_nanosV   s   z1TestTimestampArithmetic.test_delta_preserve_nanosc                 C   s   t d}td|d}|| }|| |ksJ | | |ks J |d u r0| | |ks.J d S d}tjt|d | |  W d    d S 1 sKw   Y  d S )Nl   @~z
2021-01-01tzz;Cannot subtract tz-naive and tz-aware datetime-like objectsr   )r   r	   r#   to_datetime64r   r   	TypeError)r   tz_naive_fixturetdtsotherr$   r   r   r   test_rsub_dtscalars[   s   "z+TestTimestampArithmetic.test_rsub_dtscalarsc                 C   sD   t ddd}tt ddd}|| jdksJ || jdks J d S )N  
         r   )r   r	   days)r   dtr2   r   r   r   test_timestamp_sub_datetimej   s   z3TestTimestampArithmetic.test_timestamp_sub_datetimec                 C   sF   t d}tddddtjd}|| }t|tsJ |tdks!J d S )Nz2020-10-22T22:00:00+00:00i  r6      tzinfoz0 days)r	   r   r   utc
isinstancer   r   t1t2r*   r   r   r   test_subtract_tzaware_datetimep   s
   z6TestTimestampArithmetic.test_subtract_tzaware_datetimec                 C   sF   t dd}t dd}|| }t|tsJ |tdks!J d S )N20130101
US/EasternCET0 days 06:00:00)r	   tz_localizerA   r   rB   r   r   r   /test_subtract_timestamp_from_different_timezoney   s
   zGTestTimestampArithmetic.test_subtract_timestamp_from_different_timezonec                 C   sx   t dddttddd}tdd}|| }t|tsJ |tdks'J || }t|ts2J |td	ks:J d S )
Nr5   r   hoursr>   rF   rH   rI   z-1 days +18:00:00)r   r   r   r	   rJ   rA   r   rB   r   r   r   5test_subtracting_involving_datetime_with_different_tz   s   zMTestTimestampArithmetic.test_subtracting_involving_datetime_with_different_tzc                 C   sN   t d}|d}||td }|| }t|tsJ |tdks%J d S )NrF   UTCz0 days 05:00:00)r	   rJ   
tz_convertr   rA   )r   tz_aware_fixturet_rawt_UTCt_diffr*   r   r   r   $test_subtracting_different_timezones   s   
z<TestTimestampArithmetic.test_subtracting_different_timezonesc                 C   s  t ddd}tdd}t|}d}tjt|d |d  W d    n1 s'w   Y  tjt|d |d  W d    n1 sBw   Y  t|| tksQJ t|| tks[J t|| tkseJ t	dd}t|| tksuJ t|| tksJ d S )	Ni        r   )secondsz Addition/subtraction of integersr   r   )
r   r   r	   r   r   r/   typer   nptimedelta64)r   r;   r1   r2   r$   td64r   r   r   test_addition_subtraction_types   s    


z7TestTimestampArithmetic.test_addition_subtraction_typesr1   rW   rM   hc                 C   s   |}|| || ksJ d S )Nr   )r   r1   fixed_now_tsr2   r   r   r   test_radd_tdscalar   s   z*TestTimestampArithmetic.test_radd_tdscalarzother,expected_differenceir   iIusimsi@+c                 C   sV   t tj}t|d}|| }|j|j }||ksJ t|}|| |ks)J d S )Nr   )r   nowr   r@   r	   r   _value)r   r3   expected_differencerd   r2   r*   valdiffts2r   r   r   #test_timestamp_add_timedelta64_unit   s   
z;TestTimestampArithmetic.test_timestamp_add_timedelta64_unitr2   z
1776-07-04rP   r,   r3   r      dtyperX   c                 C   s   d}t jt|d ||  W d    n1 sw   Y  t jt|d ||  W d    n1 s3w   Y  t jt|d ||  W d    n1 sNw   Y  d}t jt|d ||  W d    d S 1 slw   Y  d S )Nz3Addition/subtraction of integers and integer-arraysr   zunsupported operand type)r   r   r/   )r   r2   r3   r$   r   r   r   test_add_int_with_freq   s   



"z.TestTimestampArithmetic.test_add_int_with_freqshape)   )rj   rW   c                    s  t dd tdd|} | } fddtdD }tjdd |D dd	|}t	|| |  }t	||  | } fd
dtdD }tjdd |D dd	|}t	|| d}t
jt|d |   W d    d S 1 s}w   Y  d S )N2020-04-04 15:45r   ro   m8[h]c                       g | ]	} t |d  qS rM   r   .0nr2   r   r   
<listcomp>       zATestTimestampArithmetic.test_addsub_m8ndarray.<locals>.<listcomp>c                 S      g | ]}|j qS r   asm8rv   xr   r   r   ry          zM8[ns]rk   c                       g | ]	} t |d  qS rs   rt   ru   rx   r   r   ry      rz   c                 S   r{   r   r|   r~   r   r   r   ry      r   Dunsupported operand type\(s\) for -: 'numpy.ndarray' and 'Timestamp'r   )r	   r   r[   arangeastypereshaperangearraytmassert_numpy_array_equalr   r   r/   r   rn   r3   r*   	ex_stampsr   r$   r   rx   r   test_addsub_m8ndarray   s    
"z-TestTimestampArithmetic.test_addsub_m8ndarrayc                    s   t ddd tdd|} | } fddtdD }t||}t|| |  }t||  | } fddtdD }t||}t|| d	}t	j
t|d
 |   W d    d S 1 snw   Y  d S )Nrp   z
US/Pacificr,   ro   rq   c                    rr   rs   rt   ru   rx   r   r   ry     rz   zITestTimestampArithmetic.test_addsub_m8ndarray_tzaware.<locals>.<listcomp>c                    r   rs   rt   ru   rx   r   r   ry     rz   r   r   )r	   r[   r   r   r   r   r   r   r   r   r   r/   r   r   rx   r   test_addsub_m8ndarray_tzaware  s    
"z5TestTimestampArithmetic.test_addsub_m8ndarray_tzawarec                 C   sD   t ddd}t||d}t||d}|| }td}||ks J d S )Ni  r   r,   r   )r   r	   r   )r   utc_fixtureutc_fixture2r;   ts1rh   r*   r   r   r   r   #test_subtract_different_utc_objects  s   z;TestTimestampArithmetic.test_subtract_different_utc_objectsr-   rG   zdateutil/US/Easternc                 C   s6   t d|d}|tdd }t d|d}||ksJ d S )Nz3/10/2012 22:00r,   ro   rM   z3/11/2012 05:00)r	   r   )r   r-   r   r*   r   r   r   r   3test_timestamp_add_timedelta_push_over_dst_boundary&  s   zKTestTimestampArithmetic.test_timestamp_add_timedelta_push_over_dst_boundaryN)$__name__
__module____qualname__r   r"   r'   r+   r4   r<   rE   rK   rO   rV   r^   r   markparametrizer   r[   r\   r   ra   ri   r	   int64r   int32uint64rm   r   r   r   pytzr   r   r   r   r   r   r   r      sl    #		


	

	

		r   c                   @   s   e Zd ZdS )SubDatetimeN)r   r   r   r   r   r   r   r   =  s    r   zlh,rh  r   rM   c                 C   s&   | | }t dddd}||ksJ d S )Nr   r   )r   )lhrhr*   r   r   r   r   test_dt_subclass_add_timedeltaA  s   r   )r   r   r   dateutil.tzr   numpyr[   r   r   pandas._libs.tslibsr   r   r   r	   r
   r   pandas._testing_testingr   r   r   r   r   r   r   r   r   r   <module>   s$     	  '