
    d,                     X   d Z ddlZddlZddlmZ ddlmZmZ ddl	m
Z
mZmZmZmZmZmZmZ ddlmZ  G d d          Z G d d	          Z G d
 d          Z G d d          Z G d d          Z G d d          Zej                            d eg d           eg d           eg d          g          d             Zej                            dej        dej        gej        g ej        ddgej                   fej        dej        gej        dg ej        g dej                   f ej        ej        dej        ge!          ej        g ej        ddgej                   f edeeg          eg ej        ddgej                   fdddej        gej        g ej        d gej                   f ej        dej         e"d!          dge!           eej        ge!           ej        ddgej                   fg          d"             Z#d# Z$dS )$aS  
test_indexing tests the following Index methods:
    __getitem__
    get_loc
    get_value
    __contains__
    take
    where
    get_indexer
    get_indexer_for
    slice_locs
    asof_locs

The corresponding tests.indexes.[index_type].test_indexing files
contain tests for the corresponding methods specific to those Index subclasses.
    N)InvalidIndexError)is_float_dtype	is_scalar)NADatetimeIndexIndexIntervalIndex
MultiIndexNaTPeriodIndexTimedeltaIndexc                   &    e Zd Zd Zd Zd Zd ZdS )TestTakec                    ddg}d}t          j        t          |          5  |                    |d           d d d            n# 1 swxY w Y   d}t          j        t          |          5  |                    ||           d d d            n# 1 swxY w Y   d}t          j        t          |          5  |                    |d	
           d d d            d S # 1 swxY w Y   d S )N      z1take\(\) got an unexpected keyword argument 'foo'match)fooz$the 'out' parameter is not supported)outz%the 'mode' parameter is not supportedclip)mode)pytestraises	TypeErrortake
ValueError)selfindexindicesmsgs       ^/var/www/html/t/fyr/venv311/lib/python3.11/site-packages/pandas/tests/indexes/test_indexing.pytest_take_invalid_kwargsz!TestTake.test_take_invalid_kwargs)   s   a&B]9C000 	' 	'JJwAJ&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 5]:S111 	- 	-JJwGJ,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 6]:S111 	- 	-JJwVJ,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s5   AA
A
.BBB:CC#&C#c                 b   g d}t          |          dk     rd S |                    |          }||         }|                    |          sJ t          |t          t
          t          f          s?d}t          j        t          |          5  |j
         d d d            d S # 1 swxY w Y   d S d S )N)      r   r      z*'(.*Index)' object has no attribute 'freq'r   )lenr   equals
isinstancer   r   r   r   r   AttributeErrorfreq)r   r   indexerresultexpectedr!   s         r"   	test_takezTestTake.test_take8   s    ,,u::>>FG$$>}}X&&&&&%-n!MNN 	?C~S999  

                 	 	s   B""B&)B&c                     t          g d          }d}d}t          j        t          |          5  |                    |           d d d            d S # 1 swxY w Y   d S )Nr   r   r   r&   r   z!Expected indices to be array-liker   )r   r   r   r   r   )r   integer_indexscalar_indexr!   s       r"   test_take_indexer_typezTestTake.test_take_indexer_typeH   s    lll++1]9C000 	- 	-|,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s   AAAc                     t          |          dk    rd S |                    g d          }|                    ddt          |          dz
  g          }t          j        ||           d S )Nr   )r   r   r   )r(   r   tmassert_index_equal)r   r   r.   r/   s       r"   test_take_minus1_without_fillz&TestTake.test_take_minus1_without_fillP   sf    u::??FJJJ''::q!SZZ!^455
fh/////    N)__name__
__module____qualname__r#   r0   r5   r:    r;   r"   r   r   (   sP        - - -   - - -	0 	0 	0 	0 	0r;   r   c                   f   e Zd Zej                            d eg d          df eg d          df edddej        dg          df edddej	        dg          df edddej        g          ej        f edddej	        g          ej	        fg          d	             Z
ej                            d eg d          df eg d          df edddej        g          df edddej	        g          df edddej        g          ej	        f edddej	        g          ej        f eg dej        
          ej        f eg dej        
          ej	        f eg dej        
          ej        f eg dej        
          ej	        fg
          d             Zej                            d eg d          df eg d          dfg          d             Zej                            d eg d          df eg d          dfg          d             Zd Zd ZdS )TestContainsz	index,val)r   r   r   r   )r   r   2rB   r   r   r%   c                     ||v sJ d S Nr?   r   r   vals      r"   test_index_containsz TestContains.test_index_contains]   s     e||||||r;   dtypec                     ||vsJ d S rD   r?   rE   s      r"   test_index_not_containsz$TestContains.test_index_not_containsk   s    $ %r;   c                     ||v sJ d S rD   r?   rE   s      r"   test_mixed_index_containsz&TestContains.test_mixed_index_contains   s    
 e||||||r;   1c                     ||vsJ d S rD   r?   rE   s      r"   test_mixed_index_not_containsz*TestContains.test_mixed_index_not_contains   s    
 %r;   c                     |}t          |          sg dng d}t          ||          }t          |j                  sd|vsJ d|v sJ d|v sJ d S d|v sJ d|vsJ d|vsJ d S )Nr2   )皙?皙?g@gffffff
@rH   rS         ?r   )r   r   rI   )r   any_real_numpy_dtyperI   datar   s        r"   test_contains_with_float_indexz+TestContains.test_contains_with_float_index   s    $#1%#8#8R||||>R>R>Rd%(((ek** 	"e####%<<<<::::::%<<<<e####E>>>>>>r;   c                 N   t          |t                    rd S d}t          j        t          |          5  g |v  d d d            n# 1 swxY w Y   d                    g d          }t          j        t          |          5  i |j        v  d d d            d S # 1 swxY w Y   d S )Nzunhashable type: 'list'r   |)zunhashable type: 'dict'zmust be real number, not dictzan integer is requiredz\{\}z6pandas\._libs\.interval\.IntervalTree' is not iterable)r*   r
   r   r   r   join_engine)r   r   r!   s      r"   &test_contains_requires_hashable_raisesz3TestContains.test_contains_requires_hashable_raises   s=   eZ(( 	F']9C000 	 	%KK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 hh  
 
 ]9C000 	  	 %-	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s#   AA
A

BB!BN)r<   r=   r>   r   markparametrizer   npinfnanrG   int64uint64rK   rM   rP   rW   r\   r?   r;   r"   rA   rA   \   s*       [U999q!U;;;%UAq!RVQ'((!,UAq!RVQ'((!,UAq!RV$%%rv.UAq!RV$%%rv.	

 
 
 
 [U999s#U;;;#UAq!RV$%%q)UAq!RV$%%q)UAq!RV$%%rv.UAq!RV$%%rv. U999BH---rv6U999BH---rv6U999BI...7U999BI...7	
 "   # "  [uu[[[))1-kkk0B0BC/HI    [uu[[[))3/%%2D2Da1HI      " " "         r;   rA   c                   &    e Zd Zd Zd Zd Zd ZdS )
TestGetLocc                     t          j        t          t          fd          5  |                    t          dd                     d d d            d S # 1 swxY w Y   d S )Nslicer   r   r   )r   r   r   r   get_locrg   )r   r   s     r"   test_get_loc_non_hashablez$TestGetLoc.test_get_loc_non_hashable   s     ]I'89III 	' 	'MM%1++&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	's   $AAAc                 `   ddl m}  G d d|          }t          |j                  rJ t          }d}t          |t          t          t          t          f          r	t          }d}t          j        ||          5  |                    |j                   d d d            d S # 1 swxY w Y   d S )Nr   )Enumc                       e Zd ZdZdS )6TestGetLoc.test_get_loc_non_scalar_hashable.<locals>.Ex1N)r<   r=   r>   X1r?   r;   r"   Erm      s        BBBr;   rp   z<E.X1: 'x1'>zE.X1r   )enumrk   r   ro   KeyErrorr*   r   r   r   r	   r   r   r   rh   )r   r   rk   rp   excr!   s         r"    test_get_loc_non_scalar_hashablez+TestGetLoc.test_get_loc_non_scalar_hashable   s   	 	 	 	 	 	 	 	 QT??"""	
 
 	 $CC]3c*** 	  	 MM!$	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s   ;B##B'*B'c                 4   t           }t          |t          t          t          t
          t          f          rt          }t          j	        |d          5  |
                    d t          d          D                        d d d            d S # 1 swxY w Y   d S )Nzgenerator objectr   c              3      K   | ]}|V  d S rD   r?   ).0xs     r"   	<genexpr>z4TestGetLoc.test_get_loc_generator.<locals>.<genexpr>   s"      ..!......r;   r'   )rr   r*   r   r   r   r	   r
   r   r   r   rh   range)r   r   rs   s      r"   test_get_loc_generatorz!TestGetLoc.test_get_loc_generator   s    	
 	
 	$ $C]3&8999 	/ 	/MM..U1XX......	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   -BBBc                     t          ddt          t          gd          }|                    t                    }t          j        g d          }t          j        ||           d S )Nr   r   Int64rH   )FFTT)r   r   rh   r_   arrayr8   assert_numpy_array_equalr   idxr.   r/   s       r"   !test_get_loc_masked_duplicated_naz,TestGetLoc.test_get_loc_masked_duplicated_na   sZ    Q2rN'222R866677
#FH55555r;   N)r<   r=   r>   ri   rt   r{   r   r?   r;   r"   re   re      sP        ' ' '     4/ / /$6 6 6 6 6r;   re   c                        e Zd Zd Zd Zd ZdS )TestGetIndexerc                    |j         rPt          j        |j        t          j                  }|                    |          }t          j        ||           nJd}t          j	        t          |          5  |                    |           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 )NrH   8Reindexing only valid with uniquely valued Index objectsr   zInvalid fill methodinvalid)method)_index_as_uniquer_   arangesizeintpget_indexerr8   r   r   r   r   r   )r   r   r/   actualr!   s        r"   test_get_indexer_basez$TestGetIndexer.test_get_indexer_base   sg   ! 	)y27;;;H&&u--F'&9999LC0<<< ) )!!%((() ) ) ) ) ) ) ) ) ) ) ) ) ) ) ]:-BCCC 	7 	7eI666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s$   5BBB=C""C&)C&c                     |j         rQ|                    |dd                   }t          |t          j                  sJ |j        t          j        k    sJ nRd}t          j        t          |          5  |                    |dd                    d d d            n# 1 swxY w Y   |
                    |dd                   \  }}t          |t          j                  sJ |j        t          j        k    sJ d S )Nr   r   r   r   )r   r   r*   r_   ndarrayrI   r   r   r   r   get_indexer_non_unique)r   r   r-   r!   _s        r"   test_get_indexer_consistencyz+TestGetIndexer.test_get_indexer_consistency   s:    ! 	.''ac
33Ggrz22222=BG+++++LC0<<< . .!!%!*---. . . . . . . . . . . . . . . 11%!*==
'2:.....}''''''s   6B  B$'B$c                     t          ddt          t          gd          }|                    t          dt          gd                    }t          j        g d|j                  }t          j        ||           d S )Nr   r   r}   rH   )r   r   r&   )r   r   get_indexer_forr_   r~   rI   r8   r   r   s       r"   %test_get_indexer_masked_duplicated_naz4TestGetIndexer.test_get_indexer_masked_duplicated_na
  ss    Q2rN'222$$UAr7'%B%B%BCC8IIIV\:::
#FH55555r;   N)r<   r=   r>   r   r   r   r?   r;   r"   r   r      sA        7 7 7( ( ( 6 6 6 6 6r;   r   c                       e Zd Zd ZdS )TestConvertSliceIndexerc                    t          d d d          }t          |t                    rNd}t          j        t
          |          5  |                    |d           d d d            d S # 1 swxY w Y   d S d}t          j        t          |          5  |                    |d           d d d            d S # 1 swxY w Y   d S )Nr   zClabel-based slicing with step!=1 is not supported for IntervalIndexr   locz7'>=' not supported between instances of 'str' and 'int')rg   r*   r	   r   r   r   _convert_slice_indexerr   )r   r   keyr!   s       r"   test_convert_almost_null_slicez6TestConvertSliceIndexer.test_convert_almost_null_slice  sR    D$&&e]++ 	9WCz555 9 9,,S%8889 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 LCy444 9 9,,S%8889 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9s$   A((A,/A,B66B:=B:N)r<   r=   r>   r   r?   r;   r"   r   r     s#        9 9 9 9 9r;   r   c                       e Zd Zd ZdS )TestPutmaskc                    t          |          sd S |d         }d}t          j        t          |          5  |                    t          j        t          |          dz   t
          j                  |           d d d            n# 1 swxY w Y   t          j        t          |          5  |                    t          j        t          |          dz
  t
          j                  |           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 )Nr   z,putmask: mask and data must be the same sizer   r   r   )r(   r   r   r   putmaskr_   onesbool_)r   r   fillr!   s       r"   test_putmask_with_wrong_maskz(TestPutmask.test_putmask_with_wrong_mask#  s   5zz 	FQx<]:S111 	C 	CMM"'#e**q."(;;TBBB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C ]:S111 	C 	CMM"'#e**q."(;;TBBB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C ]:S111 	' 	'MM%&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	's7   ABBB-AC==DD#EEEN)r<   r=   r>   r   r?   r;   r"   r   r   "  s#        ' ' ' ' 'r;   r   r   )r   r   r&   )rR   g?g333333?)abcc                     d}t          j        t          |          5  | d          d d d            d S # 1 swxY w Y   d S )Nz,Indexing with a float is no longer supportedr   rT   )r   r   
IndexError)r   r!   s     r"   test_getitem_deprecated_floatr   5  s     9C	z	-	-	-  C                 s   	488zidx,target,expectedvar1r   rH   )r   r   r   z
2020-08-05r   r   r   r&   NaNc                 x    t          |           }|                    |          }t          j        ||           d S rD   )r   r   r8   r   )r   targetr/   axisr   s        r"   )test_get_indexer_non_unique_multiple_nansr   @  s;    : ::D!!&))F11111r;   c                 P   t          ddg          }t          d| gd          }|                    |          \  }}t          j        |t	          j        ddgt          j                             t          j        |t	          j        dgt          j                             d S )NrT   g       @r   objectrH   r   r7   )r   r   r8   r   r_   r~   r   )nulls_fixturer   r   
result_idxresult_missings        r"   7test_get_indexer_non_unique_nans_in_object_dtype_targetr   b  s    
c


CA}%X666F!$!;!;F!C!CJ
BHaWBG,L,L,LMMM!BG0L0L0LMMMMMr;   )%__doc__numpyr_   r   pandas.errorsr   pandas.core.dtypes.commonr   r   pandasr   r   r   r	   r
   r   r   r   pandas._testing_testingr8   r   rA   re   r   r   r   r]   r^   r   ra   r~   r   r   floatr   r   r?   r;   r"   <module>r      s          + + + + + +       
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	      10 10 10 10 10 10 10 10hR  R  R  R  R  R  R  R j86 86 86 86 86 86 86 86v#6 #6 #6 #6 #6 #6 #6 #6L9 9 9 9 9 9 9 9 ' ' ' ' ' ' ' '& 	EE)))eeOOO44eeOOO6L6LM    
&&"&	!BF8XRXq!fBG-L-L-LMVVRV$VVBHYYYbg...	
 BHbffbf-V<<<VHBHaV27+++	
 M<c233EBHaV27+++	

 sC	 26(HBHaS,H,H,HIBHc2655<<5VDDDE26(&)))BHaV27+++	
% 62 27 62N N N N Nr;   