
    i$                     x    d dl 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      Zy)    	timedeltaN)Pandas4Warning)	TimedeltaTimedeltaIndextimedelta_rangeto_timedelta)TimedeltaArrayc                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zej*                  j-                  dg d      d        Zy)TestTimedeltaIndexc                    t        j                  dd      }t        j                  |gt              }d}t	        j
                  t        |      5  t        |       d d d        t	        j
                  t        |      5  t        j                  |d       d d d        t	        j
                  t        |      5  t        |       d d d        y # 1 sw Y   txY w# 1 sw Y   ExY w# 1 sw Y   y xY w)NNaTnsdtypez!Invalid type for timedelta scalarmatchm8[ns])np
datetime64arrayobjectpytestraises	TypeErrorr   r
   _from_sequencer	   )selfnatarrmsgs       n/app/cer_product_mecsu/.venv/lib/python3.12/site-packages/pandas/tests/indexes/timedeltas/test_constructors.pytest_array_of_dt64_nat_raisesz0TestTimedeltaIndex.test_array_of_dt64_nat_raises   s    mmE4(hhuF+1]]9C0 	 3	  ]]9C0 	?))#X>	? ]]9C0 		 		  	 	? 	?	 	s$   C?C:C'CC$'C0c                     t        j                  dt         j                        }t        |d      }|j                  j
                  j                  |u sJ y )N
   r   F)copy)r   arangeint64r   _data_ndarraybase)r   r   tdis      r!   test_int64_nocopyz$TestTimedeltaIndex.test_int64_nocopy#   sB     ii"((+Su-yy!!&&#---    c                     t        ddd      }t        |d      }|j                  |j                  k(  sJ dt        |di       vsJ y )	N1 secondi 1speriodsfreqinferr3   inferred_freq_cache)r   r   r3   getattrr   r+   results      r!   test_infer_from_tdiz&TestTimedeltaIndex.test_infer_from_tdi*   sM     j%dC'2{{chh&&& gfh&CCCCr-   c                 ,   t        ddd      }d}t        j                  t        |      5  t	        |d       d d d        t        j                  t        |      5  t	        |j
                  d       d d d        y # 1 sw Y   ExY w# 1 sw Y   y xY w)	Nr/   d   r0   r1   zMInferred frequency .* from passed values does not conform to passed frequencyr   Dr5   )r   r   r   
ValueErrorr   r(   )r   r+   r    s      r!   test_infer_from_tdi_mismatchz/TestTimedeltaIndex.test_infer_from_tdi_mismatch7   s     j#DA. 	 ]]:S1 	*3S)	* ]]:S1 	03993/	0 	0	* 	*	0 	0s   A>B
>B
Bc                    t        j                  dd      }d}t        j                  t        |      5  t        |j                  d             d d d        t        j                  t        |      5  t        |       d d d        t        j                  t        |      5  t        t        j                  |             d d d        y # 1 sw Y   {xY w# 1 sw Y   XxY w# 1 sw Y   y xY w)Nz
2016-01-01   r2   z"cannot be converted to timedelta64r   zEurope/Brussels)	pd
date_ranger   r   r   r   tz_localizer   asarray)r   dtir    s      r!   test_dt64_data_invalidz)TestTimedeltaIndex.test_dt64_data_invalidG   s     mmL!42]]9C0 	?3??+<=>	? ]]9C0 	 3	  ]]9C0 	,2::c?+	, 	,	? 	?	  	 	, 	,s#   C
3C"C"
CC"C+c                 p   t        ddg      }t        ddg      }t        j                  ||       t        ddg      }t        ddg      }t        j                  ||       t        dt        j                  g      }t        t        d      t        j                  g      }t        j                  ||       y )Ngffffff@gffffff#@   	   g       @g      "@)nanoseconds)r   tmassert_index_equalr   nanr   rD   r   r   r+   expecteds      r!   test_float64_ns_roundedz*TestTimedeltaIndex.test_float64_ns_roundedW   s     c3Z(!1a&)
c8, c3Z(!1a&)
c8, c266]+!9#;RVV"DE
c8,r-   c                     t        ddgd      }t        t        d      t        d      gd      }t        j                  ||       y )Ng      ?g      @r>   unit)daysr   r   )r	   r   r   rN   rO   rQ   s      r!   test_float64_unit_conversionz/TestTimedeltaIndex.test_float64_unit_conversionh   sB    C;S1!C )"67x
 	c8,r-   c                    t        d      t        j                  t        d      g}t        j                  t        j
                  |      t        |             t        j                  t        j
                  t        j                  |            t        t        j                  |                   t        j                  t        j                  t        d      g}t        j                  t        j
                  |      t        |             t        j                  t        j
                  t        j                  |            t        t        j                  |                   y )N1 days3 days)
r   rD   r   rN   rO   Indexr   r   r   rP   )r   r   s     r!   "test_construction_base_constructorz5TestTimedeltaIndex.test_construction_base_constructorp   s    "BFFIh,?@
bhhsm^C-@A
bhhrxx}5~bhhsm7TUvvrvvy23
bhhsm^C-@A
bhhrxx}5~bhhsm7TUr-   c           	          t        g d      }t        ddt        j                  dd      t        dd      t        j
                  j                  d      g      }t        j                  ||       y )N)rZ   z1 days 00:00:052 daysz2 days 00:00:02z0 days 00:00:03rZ   z1 days, 00:00:05rK   r>   )rW   secondsrB   )	r   r   timedelta64r   rD   offsetsSecondrN   rO   )r   rR   r:   s      r!   test_constructorz#TestTimedeltaIndex.test_constructory   sd    !
  "q#&q!,

!!!$
 	fh/r-   c                     t        ddd      }t        dd      D cg c]  }d| d
 }}t        |      }t        j                  ||       y c c}w )	Nr0   rL   sr1      r$   P0DT0H0MS)r   ranger	   rN   rO   )r   rR   i	durationsr:   s        r!   test_constructor_isoz'TestTimedeltaIndex.test_constructor_iso   sP    "4=.3Arl;xs!_;	;i(
fh/ <s   Ac                     d}t        j                  t        |      5  t        dd       d d d        y # 1 sw Y   y xY w)Nzperiods must be an integerr   rZ   g      %@rC   )r   r   r   r   r   r    s     r!   &test_timedelta_range_fractional_periodz9TestTimedeltaIndex.test_timedelta_range_fractional_period   s4    *]]9C0 	4Hd3	4 	4 	4s   5>c                    d}t        j                  t        |      5  t        ddd       d d d        d}t        j                  t        |      5  t	        d       d d d        d t        d	      D        }t	        |      }t	        t        d	      D cg c]  }t        |       c}      }t        j                  ||       t        j                  g d
      }t	        |      }t        g dd      j                  d      }t        j                  ||       t	        |j                  d      j                        }t        j                  ||j                  d             d}t        j                  t        |      5  t	        g dd       d d d        d}t        j                  t        |      5  t        d	d       d d d        y # 1 sw Y   xY w# 1 sw Y   }xY wc c}w # 1 sw Y   \xY w# 1 sw Y   y xY w)Nz#periods must be an integer, got foor   rZ   foor>   )startr2   r3   z[TimedeltaIndex\(\.\.\.\) must be called with a collection of some kind, '1 days' was passedc              3   2   K   | ]  }t        |        y w)Nr   ).0rk   s     r!   	<genexpr>z?TestTimedeltaIndex.test_constructor_coverage.<locals>.<genexpr>   s     /y|/s   r$   )rZ   r_   r[   )rg   rK   rB   rU   usr   zQInferred frequency None from passed values does not conform to passed frequency D)rZ   r_   z4 daysr5   zVOf the four parameters: start, end, periods, and freq, exactly three must be specifiedr1   )r   r   r   r   r   rj   r   rN   rO   r   r   r	   as_unitasi8r?   )r   r    genr:   rk   rR   strings	from_intss           r!   test_constructor_coveragez,TestTimedeltaIndex.test_constructor_coverage   s   3]]9C0 	E(ED	E" 	 ]]9C0 	%8$	% 0U2Y/$!r"CA9Q<"CD
fh/ ((9:(	4<<TB
fh/"8#3#3D#9#>#>?	
i)9)9$)?@! 	 ]]:S1 	E9D	E& 	 ]]:S1 	2BS1	2 	2K	E 	E	% 	% #D"	E 	E	2 	2s5   GGG& G+5G7GG#+G47H c                     t        dddd      }|j                  dk(  sJ t        |d      }|j                  dk(  sJ y )NrZ   rg   r>   TEST)rs   r2   r3   namezsomething else)r   )r   r   r   )r   idxidx2s      r!   test_constructor_namez(TestTimedeltaIndex.test_constructor_name   sF    HacOxx6!!! c(89yy,,,,r-   c                    d}t        j                  t        |      5  t        dgd       d d d        d}t        j                  t        |      5  t	        j
                  dgd       d d d        y # 1 sw Y   HxY w# 1 sw Y   y xY w)Nz with no precision is not allowedr   2000ra   r   z3The 'timedelta64' dtype has no unit. Please pass in)r   r   r?   r   rD   r\   ro   s     r!   $test_constructor_no_precision_raisesz7TestTimedeltaIndex.test_constructor_no_precision_raises   sx     1]]:S1 	:F8=9	: D]]:S1 	4HHfX]3	4 	4		: 	:	4 	4s   A4B 4A= B	c                     d}t        j                  t        |      5  t        dgd       d d d        t        dgd      }|j                  dk(  sJ y # 1 sw Y   )xY w)Nz;Supported timedelta64 resolutions are 's', 'ms', 'us', 'ns'r   r   ztimedelta64[D]r   ztimedelta64[us]zm8[us])r   r   r?   r   r   )r   r    r+   s      r!   'test_constructor_wrong_precision_raisesz:TestTimedeltaIndex.test_constructor_wrong_precision_raises   sZ    K]]:S1 	=F8+;<	= fX->?yyH$$$	= 	=s   AAc                     t        dd      }|j                  J t        |d       }|j                  J t        |j                  d       }|j                  J y )Nrg      rC   r5   )r   r3   r   r(   r9   s      r!   test_explicit_none_freqz*TestTimedeltaIndex.test_explicit_none_freq   sZ    a+xx###$/{{"""		5{{"""r-   c                     t        dd      }t        j                  |      }t        |      }t	        j
                  ||       t        j                  |      }t        |      }t	        j
                  ||       y )Nrg   r   rC   )r   rD   Categoricalr   rN   rO   CategoricalIndex)r   r+   catr:   cis        r!   test_from_categoricalz(TestTimedeltaIndex.test_from_categorical   s`    a+nnS!$
fc*  %#
fc*r-   zunit,unit_depr))Ww)r>   d)minMIN)rf   ri   )hH)msMS)rw   USc                    d| d}t        d| d| g      }t        j                  t        |      5  t        d| d| g      }d d d        t        j                  |       t        j                  t        |      5  t        ddg|      }d d d        |d	v r|nd
}t        j                  |j                  |             y # 1 sw Y   xY w# 1 sw Y   CxY w)N'z8' is deprecated and will be removed in a future version.12r   rg   rK   rU   )rf   r   rw   rf   )r   rN   assert_produces_warningr   rO   r	   rx   )r   rV   	unit_deprr    rR   r:   r+   exp_units           r!   test_unit_deprecatedz'TestTimedeltaIndex.test_unit_deprecated   s     )TU!Qtf:4&z":;''cB 	H#q_)o$FGF	H
fh/''cB 	71vI6C	7#444#
c8#3#3H#=>	H 	H	7 	7s   CCCCN)__name__
__module____qualname__r"   r,   r;   r@   rI   rS   rX   r]   rd   rm   rp   r}   r   r   r   r   r   r   markparametrizer    r-   r!   r   r      s    .D0 , -"-V0*04
(2T-	4%	#
+ [[	
??r-   r   )datetimer   numpyr   r   pandas.errorsr   pandasrD   r   r   r   r	   pandas._testing_testingrN   pandas.core.arrays.timedeltasr
   r   r   r-   r!   <module>r      s2       (    8|? |?r-   