
    Owgh)                     l    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
 d dlmZ d dlmZ  G d d      Zy)    	timedeltaN)	TimedeltaTimedeltaIndextimedelta_rangeto_timedelta)TimedeltaArrayc                       e Zd Zd Zd Zej                  j                  dg d      d        Zd Z	d Z
d Zd	 Zd
 Zd Zd Zej                  j!                  d      d        Zd Zd Zd Zd Zd Zd Zd Zd Zy)TestTimedeltaIndexc                     d}t        j                  t        |      5  t        g d       d d d        y # 1 sw Y   y xY w)NzThe 'closed' keywordmatchT)closed)tmassert_produces_warningFutureWarningr   selfmsgs     h/var/www/horilla/myenv/lib/python3.12/site-packages/pandas/tests/indexes/timedeltas/test_constructors.pytest_closed_deprecatedz)TestTimedeltaIndex.test_closed_deprecated   s6    $''SA 	,2d+	, 	, 	,s   5>c                    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 scalarr   zm8[ns])np
datetime64arrayobjectpytestraises	TypeErrorr   r	   _from_sequencer   )r   natarrr   s       r   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unit)YyMc                     d}d}t        j                  t        |      5  t        j                  t
        |      5  t        g d|       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nz/Units 'M', 'Y', and 'y' are no longer supportedz?The 'unit' keyword in TimedeltaIndex construction is deprecatedr   )         )r!   r"   
ValueErrorr   r   r   r   )r   r(   r   depr_msgs       r   test_unit_m_y_raisesz'TestTimedeltaIndex.test_unit_m_y_raises'   sc    ?T]]:S1 	0++MJ 0y$/0	0 	00 0	0 	0s"   A(AA(A%	!A((A1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rC   inferred_freq_cache)r   r   rC   getattr)r   r;   results      r   test_infer_from_tdiz&TestTimedeltaIndex.test_infer_from_tdi6   sM     j%dC'2{{chh&&& gfh&CCCCr=   c                    t        ddd      }d}d}t        j                  t        |      5  t	        |d	       d d d        t        j                  t        |      5  t        j                  t        |      5  t        |d	       d d d        d d d        t        j                  t        |      5  t	        |j                  d	       d d d        t        j                  t        |      5  t        j                  t        |      5  t        |j                  d	       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   BxY w# 1 sw Y   y xY w)
Nr?   d   r@   rA   %TimedeltaArray.__init__ is deprecatedzMInferred frequency .* from passed values does not conform to passed frequencyr   DrE   )
r   r!   r"   r0   r   r   r   r   r	   r8   )r   r;   r1   r   s       r   test_infer_from_tdi_mismatchz/TestTimedeltaIndex.test_infer_from_tdi_mismatchC   s4    j#DA:. 	 ]]:S1 	*3S)	* ]]:S1 	.++MJ .s-.	.
 ]]:S1 	03993/	0 ]]:S1 	4++MJ 4syys34	4 	4	* 	*
. .	. 	.
	0 	04 4	4 	4s_   D4E;E 	E4E/E0E$#E04D= E		EEE!$E-	)E00E9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-01r.   rB   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_invalid]   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   r   assert_index_equalr   nanr   rR   r   r   r;   expecteds      r   test_float64_ns_roundedz*TestTimedeltaIndex.test_float64_ns_roundedm   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      }t        j                  ||       y )Ng      ?g      @rN   r(   )days)r   r   r   r   r\   r^   s      r   test_float64_unit_conversionz/TestTimedeltaIndex.test_float64_unit_conversion~   s;    C;S1!9##6	t8L"MN
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   rR   r   r   r\   Indexr   r   r   r]   )r   r&   s     r   "test_construction_base_constructorz5TestTimedeltaIndex.test_construction_base_constructor   s    "BFFIh,?@
bhhsm^C-@A
bhhrxx}5~bhhsm7TUvvrvvy23
bhhsm^C-@A
bhhrxx}5~bhhsm7TUr=   zFignore:The 'unit' keyword in TimedeltaIndex construction:FutureWarningc           	         t        g d      }t        ddt        j                  dd      t        dd      t        j
                  j                  d      g      }t        j                  ||       t        g d      }t        t        d      d	
      }t        j                  ||       t        g d      }t        g dd	
      }t        j                  ||       t        g d      }t        g dd
      }t        j                  ||       y )N)rf   z1 days 00:00:052 daysz2 days 00:00:02z0 days 00:00:03rf   z1 days, 00:00:05rY   rN   )rc   secondsr.   )0 days 00:00:00z0 days 00:00:01z0 days 00:00:02srb   )rm   z0 days 00:00:05z0 days 00:00:09)r      rZ   )z0 days 00:00:00.400z0 days 00:00:00.450z0 days 00:00:01.200)i  i  i  ms)
r   r   timedelta64r   rR   offsetsSecondr   r\   range)r   r_   rI   s      r   test_constructorz#TestTimedeltaIndex.test_constructor   s     "
  "q#&q!,

!!!$
 	fh/!E
  as3
fh/!E
  	4
fh/!Q
   0t<
fh/r=   c                     t        ddd      }t        dd      D cg c]  }d| d
 }}t        |      }t        j                  ||       y c c}w )	Nr@   rZ   rn   rA   r-   r4   P0DT0H0MS)r   rt   r   r   r\   )r   r_   i	durationsrI   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        t        dd      }t        j                  |       y # 1 sw Y   -xY w)Nz:Non-integer 'periods' in pd.date_range, pd.timedelta_ranger   rf   g      %@rQ   r4   )r   r   r   r   r\   )r   r   rngexps       r   &test_timedelta_range_fractional_periodz9TestTimedeltaIndex.test_timedelta_range_fractional_period   sT    J''SA 	:!(D9C	:h3
c3'	: 	:s   AA!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      }t        j                  ||       t	        |j                        }t        j                  ||       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   txY w# 1 sw Y   PxY wc c}w # 1 sw Y   \xY w# 1 sw Y   y xY w)Nz!periods must be a number, got foor   rf   foorN   )startrB   rC   z[TimedeltaIndex\(\.\.\.\) must be called with a collection of some kind, '1 days' was passedc              3   2   K   | ]  }t        |        y w)Nr   ).0ry   s     r   	<genexpr>z?TestTimedeltaIndex.test_constructor_coverage.<locals>.<genexpr>   s     /y|/s   r4   )rf   rk   rg   )r-   rY   r.   drb   zQInferred frequency None from passed values does not conform to passed frequency D)rf   rk   z4 daysrE   zVOf the four parameters: start, end, periods, and freq, exactly three must be specifiedrA   )r!   r"   r#   r   r   rt   r   r   r\   r   r   r   asi8r0   )r   r   genrI   ry   r_   strings	from_intss           r   test_constructor_coveragez,TestTimedeltaIndex.test_constructor_coverage   s   1]]9C0 	E(ED	E" 	 ]]9C0 	%8$	% 0U2Y/$!r"CA9Q<"CD
fh/ ((9:(	4
fh/"8==1	
i2! 	 ]]:S1 	E9D	E& 	 ]]:S1 	2BS1	2 	2K	E 	E	% 	% #D"	E 	E	2 	2s5   FF,F9F>G
F),F6>G
Gc                     t        dddd      }|j                  dk(  sJ t        |d      }|j                  dk(  sJ y )Nrf   r-   rN   TEST)r   rB   rC   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   2000rq   r   z3The 'timedelta64' dtype has no unit. Please pass in)r!   r"   r0   r   rR   rh   r   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"   r0   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   t        dd      }|j                  J t        |d       }|j                  J t        |j                  d       }|j                  J d}t	        j
                  t        |      5  t        |d       }d d d        j                  J y # 1 sw Y   xY w)Nr-   ro   rQ   rE   rM   r   )r   rC   r   r8   r   r   r   r	   )r   r;   rI   r   tdas        r   test_explicit_none_freqz*TestTimedeltaIndex.test_explicit_none_freq	  s    a+xx###$/{{"""		5{{"""5''SA 	1 40C	1xx	1 	1s   9BB'c                     t        dd      }t        j                  |      }t        |      }t	        j
                  ||       t        j                  |      }t        |      }t	        j
                  ||       y )Nr-   ro   rQ   )r   rR   Categoricalr   r   r\   CategoricalIndex)r   r;   catrI   cis        r   test_from_categoricalz(TestTimedeltaIndex.test_from_categorical  s`    a+nnS!$
fc*  %#
fc*r=   N)__name__
__module____qualname__r   r'   r!   markparametrizer2   r<   rJ   rO   rW   r`   rd   ri   filterwarningsru   r{   r   r   r   r   r   r   r    r=   r   r   r      s    , [[V_50 60.D44, -"-V [[P#0#0J0((2T-	4%  
+r=   r   )datetimer   numpyr   r!   pandasrR   r   r   r   r   pandas._testing_testingr   pandas.core.arrays.timedeltasr	   r   r   r=   r   <module>r      s/          8R+ R+r=   