
    o[we6                     B   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
mZ d dlmZ d dlmZ  ej         eg d           eg d          f eg d           eg d          f edd	
           edd	
          f e
dd	
           e
dd	
          f e
dd	d           e
dd	d          fgd           d             Z G d d          Z G d d          Z G d d          Zd Z G d d          Zd Zd Zd Zej                            dg d  e
d!d"d#$          gd%d&g'          d(             Zej                            dg d  e
d!d"d#$          gd%d&g'          d)             Zd* Zej                            d+g d,          d-             Z dS ).    N)IndexIntervalIntervalIndex	Timedelta	Timestamp
date_rangetimedelta_range)IntervalArray)r         )         )              ?       @)r   r         @0 daysr   periods1 day2017010120170102
US/Easternr   tzc                 6    t          | d         j                  S )Nr   )strdtype)xs    Jlib/python3.11/site-packages/pandas/tests/arrays/interval/test_interval.py<lambda>r"      s    #adj//     )paramsidsc                     | j         S )zC
    Fixture for building an IntervalArray from various dtypes
    )param)requests    r!   left_right_dtypesr)      s    " =r#   c                   $   e Zd Zej                            dd ed           ed          f ed           ed          f edd           edd          fg          ej                            d	ee	g          d
                         Z
dS )TestAttributeszleft, rightr   r   r   r   z
2018-01-01z
2018-01-02r   )r   constructorc                     ||f||ft           j        g}t          j        |dk    ddg          }|                    ||          j        }t          j        ||           d S )NbothFclosed)npnanarrayfrom_tuplesis_emptytmassert_numpy_array_equal)selfr-   leftrightr1   tuplesexpectedresults           r!   test_is_emptyzTestAttributes.test_is_empty'   si     ,urv68Vv-ue<==(((??H
#FH55555r#   N)__name__
__module____qualname__pytestmarkparametrizer   r   r
   r   r?    r#   r!   r+   r+   &   s        [Yx  ))G"4"45Y|$$ii&=&=>	,<888	,<888		
  []]M,JKK6 6 LK 6 6 6r#   r+   c                       e Zd Zej                            dg d          d             Zej                            d eddd           ej	        g d	d          g          d
             Z
d Zd ZdS )TestMethods
new_closed)r:   r;   r/   neitherc                     t          j        t          d          |          }|                    |          }t          j        t          d          |          }t	          j        ||           d S )N
   r0   )r
   from_breaksrange
set_closedr7   assert_extension_array_equal)r9   r1   rI   r4   r>   r=   s         r!   test_set_closedzTestMethods.test_set_closed=   sf     )%))FCCC!!*-- ,U2YYzJJJ
'99999r#   otherr   r   r;   r0   r   r   r   r   c                    t          j        t          j        g dd                    }t	          j        g d          }d}t          j        t          |          5  |j        	                    ||           d d d            n# 1 swxY w Y   |
                    ||          }|                    t                    
                    ||          }t          j        ||           d S )NrS   r:   r0   )TFTz+'value.closed' is 'right', expected 'left'.match)rR   )pdSeriesr
   rM   r2   r4   rC   raises
ValueError_wherewhereastypeobjectr7   assert_series_equal)r9   rR   sermaskrV   resr=   s          r!   test_where_raiseszTestMethods.test_where_raisesE   s    i1,,,vNNNOOx+++,,=]:U333 	* 	*IT5)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* iiEi**::f%%++D%88
sH-----s   BB
B
c                    t          j        g d          }|                                }t          j        t          j        t          j        fdg          }t          j        ||           d}t          j	        t          |          5  |                    dt          j                   d d d            d S # 1 swxY w Y   d S )N)r   r   r   )r   r   =can only insert Interval objects and NA into an IntervalArrayrU   r   
fill_value)r
   rM   shiftr5   r2   r3   r7   assert_interval_array_equalrC   rY   	TypeErrorrW   NaTr9   ar>   r=   msgs        r!   
test_shiftzTestMethods.test_shiftX   s    %iii00 ,rvrv.>
-KLL
&vx888M]9C000 	* 	*GGA"&G)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s   	"B88B<?B<c                    t          j        t          dd                    }|                    d          }|                    g dd          }t          j        ||           |                    d          }|                    g d	d          }t          j        ||           d
}t          j        t          |          5  |                    dt          j        dd                     d d d            d S # 1 swxY w Y   d S )N2000r   r   r   )rr   r   T)
allow_fillrr   )r   r   rr   re   rU   r   rk   nsrf   )r
   rM   r   rh   taker7   ri   rC   rY   rj   r2   timedelta64rl   s        r!   test_shift_datetimezTestMethods.test_shift_datetimed   s5   %j&C&C&CDD66+++$677
&vx88866***666
&vx888M]9C000 	? 	?GGA"."="=G>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?s   +C??DDN)r@   rA   rB   rC   rD   rE   rQ   r   r
   rM   rc   ro   rw   rF   r#   r!   rH   rH   <   s        [\+O+O+OPP: : QP: [HQ'***%M%lll7CCC	
 
. 
. 
.
* 
* 
*? ? ? ? ?r#   rH   c                       e Zd Zd Zd ZdS )TestSetitemc                    |\  }}|                     d          }|                     d          }t          j        ||          }|j        j        j        dvrDd}t          j        t          |          5  t          j
        |d<   d d d            n# 1 swxY w Y   |j        j        j        dv rFd}t          j        t          |          5  t          j        |d<   d d d            n# 1 swxY w Y   d S t          j        |d<   t          |j        gt          |d	d                    z             }t          |j        gt          |d	d                    z             }t          j        ||          }t!          j        ||           d S )
NTdeep)mMz='value' should be an interval type, got <.*NaTType'> instead.rU   r   )iuz4Cannot set float NaN to integer-backed IntervalArrayr   )copyr
   from_arraysr   subtypekindrC   rY   rj   rW   rk   r2   r3   r   	_na_valuelistr7   rP   )	r9   r)   r:   r;   r>   rn   expected_leftexpected_rightr=   s	            r!   test_set_nazTestSetitem.test_set_nau   s   'eyydy##


%%*477<$J66QCy444 # #Fq	# # # # # # # # # # # # # # #<$
22HC y444 # #Fq	# # # # # # # # # # # # # # #FFq	t~.d122h?@@04abb	??BCC ,]NKK
'99999s$   7BBBC**C.1C.c                    t          j        t          d                    }|                                }|                    d          }d}t          j        t          |          5  |d         |d<   d d d            n# 1 swxY w Y   t          j        t          |          5  |d d         |d d<   d d d            n# 1 swxY w Y   t          j        t          |          5  |d d         |d d<   d d d            n# 1 swxY w Y   t          j        t          |          5  |d d d         |d d <   d d d            n# 1 swxY w Y   t          j        t          |          5  t          |d d d                   |d d <   d d d            n# 1 swxY w Y   t          j        t          |          5  |d d d         	                    t                    |d d <   d d d            n# 1 swxY w Y   t          j        t          |          5  |d d d         	                    d          |d d <   d d d            n# 1 swxY w Y   g |d d<   t          j        ||           d S )	Nr   r/   z*'value.closed' is 'both', expected 'right'rU   r   r   rr   category)r
   rM   rN   r   rO   rC   rY   rZ   r   r]   r^   r7   ri   )r9   arrorigrR   rn   s        r!   test_setitem_mismatched_closedz*TestSetitem.test_setitem_mismatched_closed   s    'a11xxzzv&&:]:S111 	 	1XCF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]:S111 	  	 BQBiCG	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 ]:S111 	  	 BQBiCG	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 ]:S111 	! 	!44R4[CF	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!]:S111 	' 	'%"+&&CF	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	']:S111 	0 	044R4[''//CF	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0]:S111 	4 	444R4[''
33CF	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 BQB
&sD11111s~   (B  BB&CC	C(DDD*EEE-FFF=)G22G69G6$IIIN)r@   rA   rB   r   r   rF   r#   r!   ry   ry   t   s2        : : :42 2 2 2 2r#   ry   c                  d    t          j        ddg          } t          |           }d}||k    sJ d S )Nr,   )r   r   zI<IntervalArray>
[(0, 1], (1, 2]]
Length: 2, dtype: interval[int64, right])r
   r5   repr)r   r>   r=   s      r!   	test_reprr      sE    

#VV$4
5
5C#YYF	3 
 Xr#   c                       e Zd Zd Zd ZdS )TestReductionsc                    |\  }}|                     d          }|                     d          }t          j        ||          }d}dD ]}t          j        t
          |          5  |                    |           d d d            n# 1 swxY w Y   t          j        t
          |          5  |                    |           d d d            n# 1 swxY w Y   d}t          j        t          |          5  |                    d           d d d            n# 1 swxY w Y   t          j        t          |          5  |                    d           d d d            d S # 1 swxY w Y   d S )	NTr{   z2`axis` must be fewer than the number of dimensions)r   rU   )axisz'>=' not supported betweenfoo)	r   r
   r   rC   rY   rZ   minmaxrj   )r9   r)   r:   r;   r   rn   r   s          r!   test_min_max_invalid_axisz(TestReductions.test_min_max_invalid_axis   sf   'eyydy##


%%'e44B 	# 	#Dz555 # #T"""# # # # # # # # # # # # # # #z555 # #T"""# # # # # # # # # # # # # # # +]9C000 	  	 GGG	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 ]9C000 	  	 GGG	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 sH   (BB	B	1CC	C	=D  D$'D$E**E.1E.c                    |\  }}|                     d          }|                     d          }t          j        ||          }|j        sJ t	          |          j        sJ |d         }|d         }t          j        t          |                    }t
          j        	                    d          
                    |           |                    |          }|                    dt
          j                  }	 ||          } ||	          }	dD ]}
|                    |
          }||k    sJ t          |          t          |          k    sJ |                    |
          }||k    sJ t          |          t          |          k    sJ |	                    d          }t          j        |          sJ |	                    d          }t          j        |          sJ |	                    d          }||k    sJ t          |          t          |          k    sJ |	                    d          }||k    sJ t          |          t          |          k    sJ d S )	NTr{   r   rr   r   )TF)skipnaF)r   r
   r   is_monotonic_increasingr   r2   arangelenrandomdefault_rngshuffleru   insertr3   r   typer   isnan)r9   r)   index_or_series_or_arrayr:   r;   r   MINMAXindexerarr_nar   rb   s               r!   test_min_maxzTestReductions.test_min_max   sT   'eyydy##


%%'e44 ++++Szz1111!f"g)CHH%%
	a  ((111hhwArv&&&&s++))&11# 	* 	*F'''((C#::::99S		))))'''((C#::::99S		)))))jjj&&x}}jjj&&x}}jjj%%czzzzCyyDII%%%%jjj%%czzzzCyyDII%%%%%%r#   N)r@   rA   rB   r   r   rF   r#   r!   r   r      s2             &*& *& *& *& *&r#   r   c                     t          j        d          } ddlm}  ||                                 d          } ||                                 d          } ||                                 d          }|j        dk    sJ ||k    sJ ||k    sJ t          |          t          |          k    sJ t          |          t          |          k    sJ d S )Npyarrowr   ArrowIntervalTyper:   r;   )rC   importorskip(pandas.core.arrays.arrow.extension_typesr   int64r1   hash)par   p1p2p3s        r!   test_arrow_extension_typer      s    		Y	'	'BJJJJJJ		288::v	.	.B		288::v	.	.B		288::w	/	/B98888888888tBxx88tBxxr#   c                     t          j        d          } ddlm} t	          j        ddd          j        }|                     |          }t          |j        |          sJ |j        j	        |j	        k    sJ |j        j
        |                                 k    sJ |j                            d                              |                     g dd	
                    sJ |j                            d                              |                     g dd	
                    sJ |                     d t          dd          D                       }|j                            |          sJ |                     ||j        
          }|                    |          sJ t          j        t"          d          5  |                     |d
           d d d            n# 1 swxY w Y   t          j        t"          d          5  |                     | ||                                 d          
           d d d            d S # 1 swxY w Y   d S )Nr   r   r   r   r   )freqr:   rS   r   r   r;   )r   r   r   r   c                     g | ]
}||d z   dS )r   r:   r;   rF   ).0r   s     r!   
<listcomp>z$test_arrow_array.<locals>.<listcomp>  s$    JJJ!a!e44JJJr#   z&Not supported to convert IntervalArrayrU   float64)rC   r   r   r   rW   interval_ranger4   
isinstancer   r1   r   r   storagefieldequalsrN   rY   rj   r   )r   r   	intervalsr>   r=   s        r!   test_arrow_arrayr   
  s   		Y	'	'BJJJJJJ!!QQ///5IXXi  Ffk#455555;!11111;"((**,,,,>''..rxx7x/S/STTTTT>((//G0T0TUUUUUxxJJeAqkkJJJKKH>  ***** XXihmX44F==""""" 
y(P	Q	Q	Q , ,
+++, , , , , , , , , , , , , , , 
y(P	Q	Q	Q J J
!2!22::<<!H!HIIIJ J J J J J J J J J J J J J J J J Js$   G%%G),G)4IIIc                     t          j        d          } ddlm} t	          j        g d          }d |d<   |                     |          }t          |j        |          sJ |j        j	        |j	        k    sJ |j        j
        |                                 k    sJ |                     g dd          }|                     g d	d          }|j                            d
                              |          sJ |j                            d                              |          sJ dddd d ddddg}| j                            |t#          j        g d                    }|j                            |          sJ d S )Nr   r   r   r   r   r   r   r   )r   Nr   r   r   )r   Nr   r:   r;   r   r   r   r   r   )FTF)ra   )rC   r   r   r   r
   rM   r4   r   r   r1   r   r   r   r   r   StructArrayfrom_pandasr2   )r   r   r   r>   r:   r;   valsr=   s           r!   test_arrow_array_missingr   '  s   		Y	'	'BJJJJJJ

#$8$8$8
9
9CCFXXc]]Ffk#455555;++++;"**,,.... 88$$$9855DHH%%%IH66E>''..t44444>((//66666 s##%%s##D
 ~))$RX>R>R>R5S5S)TTH>  *******r#   breaksr   2017r   D)r   r   floatzdatetime64[ns])r%   c                 \   t          j        d          }ddlm} t	          j        |           }d |d<   t          j        d|i          }|                    |          }t          |
                    d          j        |          sJ |                                }t          |d         j        t          j                  sJ t          j        ||           |                    ||g          }|                                }t          j        ||gd          }t          j        ||           |                    |                    g |                    d          j                  g|j        	          }|                                }t          j        ||dd                    d S )
Nr   r   r   r   rm   T)ignore_indexr   )schema)rC   r   r   r   r
   rM   rW   	DataFrametabler   r   r   	to_pandasr   IntervalDtyper7   assert_frame_equalconcat_tablesconcatchunked_arraycolumnr   )	r   r   r   r   dfr   r>   table2r=   s	            r!   test_arrow_table_roundtripr   D  s    
	Y	'	'BJJJJJJ

#F
+
+CCF	sCj	!	!BHHRLLEekk#&&+->?????__FfSk')9:::::&"%%%uen--FFy"b555H&(+++ HH			"5<<??#7		8	89%,   E __F&(1Q3-00000r#   c                    t          j        d          }t          j        |           }d |d<   t	          j        d|i          }|                    |          }|                                }|j        j	        J |
                                }t          |d         j        t          j                  sJ t          j        ||           d S )Nr   r   rm   )rC   r   r
   rM   rW   r   r   replace_schema_metadatar   metadatar   r   r   r   r7   r   )r   r   r   r   r   r>   s         r!   +test_arrow_table_roundtrip_without_metadatar   e  s     
	Y	'	'B

#F
+
+CCF	sCj	!	!BHHRLLE))++E< (((__FfSk')9:::::&"%%%%%r#   c                     t          j        d          } |                     ddddddg          }t          j        t          j        d          d          }|                    |          }t          j	        t          j        g d	d
          d          }t          j        ||           |                    |                     |g                    }t          j        ||           d S )Nr   r   r   r   r   r   rJ   r0   )r   r   r   )r   )rC   r   r4   rW   r   r2   r   __from_arrow__r
   rM   r7   rP   r   )r   r   r   r>   r=   s        r!   %test_from_arrow_from_raw_struct_arrayr   {  s     
	Y	'	'B
((Q++a!-D-DE
F
FCRXg..yAAAE!!#&&F(
'***9  H #FH555!!""2"2C5"9"9::F#FH55555r#   timezone)UTCz
US/PacificGMTc                     t          dd|           }d|  d| d}t          j        ddgdd	g||
          }t          j        |d d         |dd          |          }t          j        ||           d S )N2022r   r   zinterval[datetime64[ns, z], ]z
2022-01-01z
2022-01-02z
2022-01-03)r1   r   rr   r   r0   )r   r   r   r7   assert_index_equal)r   inclusive_endpoints_fixturedatesr   r>   r=   s         r!   test_interval_index_subtyper     s     vqX666ERxRR4ORRRE&	|$	|$*	  F (crc
E!""I&A  H &(+++++r#   )!numpyr2   rC   pandasrW   r   r   r   r   r   r   r	   pandas._testing_testingr7   pandas.core.arraysr
   fixturer)   r+   rH   ry   r   r   r   r   r   rD   rE   r   r   r   r   rF   r#   r!   <module>r      s                                   , , , , , , 	yyy		55++,			!7!78	1	-	-	-wPQ/R/R/RS	J	*	*	*JJz1,M,M,MNJz1>>>Jz1>>>	
	 	"!    6 6 6 6 6 6 6 6,5? 5? 5? 5? 5? 5? 5? 5?p22 22 22 22 22 22 22 22j	 	 	>& >& >& >& >& >& >& >&J      J J J:+ + +: ::facBBBC	"#   
1 1 
18 ::facBBBC	"#   
& & 
&"6 6 6& %A%A%ABB, , CB, , ,r#   