
    i1                         d dl mZmZ d dlZd dlZd dlmZ d dl	m
Z
mZmZmZmZmZ d dlmZ d dlmZ d dlmZ  G d d      Zy)	    )given
strategiesN)lib)NaTOutOfBoundsDatetime	Timedelta	TimestampiNaT	to_offset)NpyDatetimeUnit)INVALID_FREQ_ERR_MSGc                      e Zd Zd Zej
                  j                  dg d      d        Zd Zd Z	d Z
d Zd	 Zej
                  j                  d
g d      d        Zej
                  j                  dg d      ej
                  j                  dg d      d               Zd Zd Zej
                  j                  dg d      d        Zej
                  j                  dg dg dg dg      d        Zej
                  j                  dg d      ej
                  j                  dg d      d                Zd! Zej
                  j*                   e ej0                  ed"z   ej6                        #      ej
                  j                  dej:                  ej<                  ej>                  g      d$                      Z y%)&TestTimestampRoundc                     t        d      }d}t        j                  t        |      5  |j	                  d       d d d        y # 1 sw Y   y xY w)Nz
2016-01-01zDivision by zero in roundingmatch0ns)r	   pytestraises
ValueErrorround)selftsmsgs      m/app/cer_product_mecsu/.venv/lib/python3.12/site-packages/pandas/tests/scalar/timestamp/methods/test_round.py"test_round_division_by_zero_raisesz5TestTimestampRound.test_round_division_by_zero_raises   s?    |$,]]:S1 	HHUO	 	 	s   AAztimestamp, freq, expected))20130101 09:10:11D20130101)z20130101 19:10:11r   20130102)z20130201 12:00:00r   20130202)z20130104 12:00:00r   20130105)2000-01-05 05:09:15.13r   z2000-01-05 00:00:00)r#   hz2000-01-05 05:00:00)r#   sz2000-01-05 05:09:15c                 `    t        |      }|j                  |      }t        |      }||k(  sJ y Nr	   r   )r   	timestampfreqexpecteddtresults         r   test_round_frequenciesz)TestTimestampRound.test_round_frequencies   s3     y!$X&!!!    c                     t        dd      }|j                  d      }t        dd      }||k(  sJ t        dd      }|j                  d      }||k(  sJ y )Nr   z
US/Easterntzr   r   r%   r(   r   r,   r-   r+   s       r   test_round_tzawarez%TestTimestampRound.test_round_tzaware1   s\    *|<#ZL9!!!*|<#||r/   c                 `    t        d      }|j                  d      }t        d      }||k(  sJ y )Nz20130104 12:32:0030Minz20130104 12:30:00r(   r3   s       r   test_round_30minz#TestTimestampRound.test_round_30min;   s4    *+'"01!!!r/   c                 \   t        d      j                  d      }t        d      }||k(  sJ t        d      j                  d      }t        d      }||k(  sJ t        d      }dD ]  }||j                  |      k(  rJ  t        d      j                  d      }t        d	      }||k(  sJ y )
Nz2016-10-17 12:00:00.0015msz2016-10-17 12:00:00.002000z2016-10-17 12:00:00.00149z2016-10-17 12:00:00.001000)usns2016-10-17 12:00:00.00150103110nsz2016-10-17 12:00:00.001501030r(   )r   r-   r+   r   r*   s        r   test_round_subsecondz'TestTimestampRound.test_round_subsecondB   s    56<<TB9:!!!67==dC9:!!!12  	(D$'''	( :;AA&I<=!!!r/   c                     t        j                  d      5  t        d      j                  d       d d d        y # 1 sw Y   y xY w)NFr<   1010ns)tmassert_produces_warningr	   r   )r   s    r   test_round_nonstandard_freqz.TestTimestampRound.test_round_nonstandard_freqT   s=    ''. 	G56<<XF	G 	G 	Gs	   :Ac                     t        d      }t        j                  t        t              5  |j                  d       d d d        y # 1 sw Y   y xY w)Nr#   r   foo)r	   r   r   r   r   r   )r   stamps     r   test_round_invalid_argz)TestTimestampRound.test_round_invalid_argX   s=    23]]:-AB 	KK	 	 	s   AAz#test_input, rounder, freq, expected))2117-01-01 00:00:45floor15srH   )rH   ceilrJ   rH   )z2117-01-01 00:00:45.000000012rI   r=   z2117-01-01 00:00:45.000000010)z1823-01-01 00:00:01.000000012rK   r=   z1823-01-01 00:00:01.000000020)1823-01-01 00:00:01rI   1srL   )rL   rK   rM   rL   )r   rI   rM   r   )r   rK   rM   r   c                     t        |      }t        ||      } ||      }|t        u r|t        u sJ y t        |      }||k(  sJ y r'   )r	   getattrr   )r   
test_inputrounderr*   r+   r,   funcr-   s           r   test_ceil_floor_edgez'TestTimestampRound.test_ceil_floor_edge]   sN    0 z"r7#d9S= = *HX%%%r/   ztest_input, freq, expected))2018-01-01 00:02:062srT   )2018-01-01 00:02:002minrV   )2018-01-01 00:04:004minrX   )2018-01-01 00:15:0015minrZ   )2018-01-01 00:20:0020minr\   )2018-01-01 03:00:003hr^   rQ   )rK   rI   r   c                 f    t        |      }t        |      }t        ||      } ||      }||k(  sJ y r'   )r	   rO   )r   rP   r*   r+   rQ   r,   rR   r-   s           r   test_round_minute_freqz)TestTimestampRound.test_round_minute_freq   s;      z"X&r7#d!!!r/   c                     t        d      j                  |      }|j                  d      }t        d      }||k(  sJ |j                  |j                  k(  sJ y )Nr   r   r    )r	   as_unitrK   _cresor   unitr,   r-   r+   s        r   	test_ceilzTestTimestampRound.test_ceil   sS    *+33D9Z(!!!}}		)))r/   c                     t        d      j                  |      }|j                  d      }t        d      }||k(  sJ |j                  |j                  k(  sJ y )Nr   r   r   )r	   rc   rI   rd   re   s        r   
test_floorzTestTimestampRound.test_floor   sS    *+33D9#Z(!!!}}		)))r/   method)rK   r   rI   c                 z   t        dd      j                  d      }|j                  |      } t        ||      dd      }||k(  sJ |j                  t        t
        d|       j                  k(  sJ  t        ||      dd	      }t        d
d      j                  d      }||k(  sJ |j                  t        t
        d|       j                  k(  sJ  t        ||      dd      }|t        u sJ d}t        j                  t        |      5   t        ||      dd       d d d        y # 1 sw Y   y xY w)Nz2017-10-29 00:00:00UTCr1   zEurope/Madridr$   T)	ambiguousNPY_FR_Fz2017-10-29 01:00:00r   zCannot infer dst timer   raise)r	   
tz_convertrc   rO   rd   r   valuer   r   r   r   )r   rj   rf   r   r-   r+   r   s          r   test_round_dst_border_ambiguousz2TestTimestampRound.test_round_dst_border_ambiguous   s3    ,7BB?SZZ$V$SD9||}}74&9I J P PPPP$V$SE:2u=HH
 !!!}}74&9I J P PPPP$V$SE:}}%]]:S1 	8GBw7	8 	8 	8s   D11D:zmethod, ts_str, freq)rK   2018-03-11 01:59:00-06005min)r   rs   rt   )rI   z2018-03-11 03:01:00-05002hc                    t        |d      j                  |      } t        ||      |d      }t        dd      }||k(  sJ |j                  t        t        d|       j
                  k(  sJ  t        ||      |d      }|t        u sJ d}t        j                  t        |	      5   t        ||      |d
       d d d        y # 1 sw Y   y xY w)NzAmerica/Chicagor1   shift_forward)nonexistentz2018-03-11 03:00:00rn   r   z2018-03-11 02:00:00r   ro   )
r	   rc   rO   rd   r   rq   r   r   r   r   )	r   rj   ts_strr*   rf   r   r-   r+   r   s	            r   !test_round_dst_border_nonexistentz4TestTimestampRound.test_round_dst_border_nonexistent   s     v"34<<TB$V$TG27HI!!!}}74&9I J P PPPP$V$Tu=}}#]]:S1 	;GB':	; 	; 	;s   ,C

Cr)   )z2018-01-01 0:0:0.124999360z2018-01-01 0:0:0.125000367z2018-01-01 0:0:0.125500z2018-01-01 0:0:0.126500z2018-01-01 12:00:00z2019-01-01 12:00:00r*   )2ns3ns4ns5ns6ns7ns250ns500ns750ns1us19us250us500us750usrM   rU   3s1Dc                 4   t        |      j                  d      }t        |      j                  }|j	                  |      }|j
                  |z  dk(  sJ d| d       d|j
                  |j
                  z
  cxk  r|k  sJ d        J d       |j                  |      }|j
                  |z  dk(  sJ d| d       d|j
                  |j
                  z
  cxk  r|k  sJ d        J d       |j                  |      }|j
                  |z  dk(  sJ d| d       t        |j
                  |j
                  z
        |d	z  k  sJ d
       |d	z  dk(  rFt        |j
                  |j
                  z
        |d	z  k(  r|j
                  |z  d	z  dk(  sJ d       y y y )Nr;   r   zfloor not a z	 multiplezfloor errorzceil not a z
ceil errorzround not a    zround errorzround half to even error)	r	   rc   r   nanosrI   _valuerK   r   abs)r   r)   r*   r,   rf   r-   s         r   test_round_int64z#TestTimestampRound.test_round_int64   s   J y!))$/$$ $}}t#q(HLi*HH(BII-44CmC4CmC4 }}t#q(GKvY*GG(FMMBII-44BlB4BlB4 $}}t#q(HLi*HH(6==299,-:IMI:!8q=S!:;tqyH==D(1,1M3MM1 I=r/   c                 t   t         j                  j                  d      }t        dddddd      }||k(  sJ t         j                  j	                  d      }t         j                  t        d      z
  }||k(  sJ d	}t        j                  t        |
      5  t         j                  j	                  d       d d d        t        j                  t        |
      5  t         j                  j                  d       d d d        d}t        j                  t        |
      5  t         j                  j                  d       d d d        t        j                  t        |
      5  t         j                  j                  d       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   exY w# 1 sw Y   y xY w)Nr%   i  	      r      ,   i2z;Cannot round 1677-09-21 00:12:43.145224193 to freq=<Second>r   z;Cannot round 2262-04-11 23:47:16.854775807 to freq=<Second>)
r	   minrK   maxrI   r   r   r   r   r   )r   r-   r+   r   s       r    test_round_implementation_boundsz3TestTimestampRound.test_round_implementation_bounds  s[   ##C(T1b!R4!!!$$S)==9Y#77!!!K]].c: 	%MM$	% ]].c: 	%MM$	% L]].c: 	$MMs#	$ ]].c: 	%MM$	% 	%	% 	%	% 	%	$ 	$	% 	%s0    F
 F F"! F.
FF"F+.F7   )valc                    t         t        t        j                  |      } |      }fd}d} |||d       d} |||d       d} |||d       d} |||d	       d
} |||d       d} |||d       d} |||d       y )Nc                    |dk(  rnt        | j                  |      \  }}t        ||z
        }| j                  |z
  }|| j                  k  sJ | j                  |z   }|| j                  kD  sJ d}|dk(  rn.j                  u rD|j                  j                  kD  rt        j                  |      5   | |       d d d        y j                  u rC|j                  j                  k  rt        j                  |      5   | |       d d d        y ||k\  rC|j                  j                  kD  rmt        j                  |      5   | |       d d d        y |j                  j                  k  r*t        j                  |      5   | |       d d d        y  | |      }	|	| z
  }
t        |
j                        }||k  sJ |	j                  |z  dk(  sJ j                  u r||dz  k  sJ y j                  u r|	| k  sJ y j                  u r|	| k\  sJ y y # 1 sw Y   y xY w# 1 sw Y   y xY w# 1 sw Y   y xY w# 1 sw Y   y xY w)Nr   zwithout overflowr   r   r   )divmodr   intrK   r   r   r   rI   r   r   r   )r   r   rf   divmoddifflbubr   restdclserr_clsrj   s              r   checkerz5TestTimestampRound.test_round_sanity.<locals>.checker/  s(   z!"))U3S53;'YY_RYY&YY%BII~%~(!8sxx'CGGNN*#]]7#> -"2t,-syy(CGGNN*#]]7#> -"2t,-D[CGGNN*#]]7#> -"2t,-#''..(wc: )r4()T"CrBryy>D%<<::%***"uqy(((399$by y388#by y $;---)s0   8
H+	
H7
I
I+H47I IIr   r;   i  r:   i@B r9   i ʚ;r%   l    Xp7 r   l     qar$   l     "R: r   )r	   r   npint64)r   r   rj   r   r   r   r   r   s     `   @@r   test_round_sanityz$TestTimestampRound.test_round_sanity#  s     %hhsmX0	!d E4 E4 E4 E3"E5!'E3,E3r/   N)!__name__
__module____qualname__r   r   markparametrizer.   r4   r7   r>   rC   rG   rS   ra   rg   ri   rr   rz   r   r   slowr   stintegersr
   r   i8maxr	   r   rI   rK   r    r/   r   r   r      s    [[#	
""""$G
 [[-	
.	&/.	& [[$	

 [[Y(BC" D
"** [[X'AB8 C8, [[897	
;; [[	

 [[	
.N/
DN0%0 [[
{r{{4!8SYY/0[[9??IOOY^^DL  1 
L r/   r   )
hypothesisr   r   r   numpyr   r   pandas._libsr   pandas._libs.tslibsr   r   r   r	   r
   r   pandas._libs.tslibs.dtypesr   pandas._libs.tslibs.periodr   pandas._testing_testingrA   r   r   r/   r   <module>r      s6        7 ; ]  ] r/   