
    bMh-,                     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       b/var/www/html/test/jupyter/venv/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                    g d}t          |          dk     rt          j        d           |                    |          }||         }|                    |          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      z1Test doesn't make sense since not enough elementsz*'(.*Index)' object has no attribute 'freq'r   )lenr   skipr   equals
isinstancer   r   r   r   AttributeErrorfreq)r   r   indexerresultexpectedr!   s         r"   	test_takezTestTake.test_take8   s   ,,u::>>KKLLLG$$>}}X&&&&&%-n!MNN 	?C~S999  

                 	 	s   B44B8;B8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_typeG   s    lll++1]9C000 	- 	-|,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s   AAAc                     t          |          dk    rt          j        d           |                    g d          }|                    ddt          |          dz
  g          }t	          j        ||           d S )Nr   'Test doesn't make sense for empty index)r   r   r   )r(   r   r)   r   tmassert_index_equal)r   r   r/   r0   s       r"   test_take_minus1_without_fillz&TestTake.test_take_minus1_without_fillO   sr    u::??KABBBJJJ''::q!SZZ!^455
fh/////    N)__name__
__module____qualname__r#   r1   r6   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   2rD   r   r   r%   c                     ||v sJ d S NrA   r   r   vals      r"   test_index_containsz TestContains.test_index_contains\   s     e||||||r=   dtypec                     ||vsJ d S rF   rA   rG   s      r"   test_index_not_containsz$TestContains.test_index_not_containsj   s    $ %r=   c                     ||v sJ d S rF   rA   rG   s      r"   test_mixed_index_containsz&TestContains.test_mixed_index_contains~   s    
 e||||||r=   1c                     ||vsJ d S rF   rA   rG   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 )Nr3   )皙?皙?g@gffffff
@rJ   rU         ?r   )r   r   rK   )r   any_real_numpy_dtyperK   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nanrI   int64uint64rM   rO   rR   rY   r^   rA   r=   r"   rC   rC   [   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=   rC   c                   &    e Zd Zd Zd Zd Zd ZdS )
TestGetLocc                     t          j        t          d          5  |                    ddg           d d d            d S # 1 swxY w Y   d S )Nz[0, 1]r   r   r   )r   r   r   get_loc)r   r   s     r"   test_get_loc_non_hashablez$TestGetLoc.test_get_loc_non_hashable   s    ],H=== 	" 	"MM1a&!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"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@   X1rA   r=   r"   Ern      s        BBBr=   rq   z<E.X1: 'x1'>zE.X1r   )enumrl   r   rp   KeyErrorr+   r   r   r   r	   r   r   r   ri   )r   r   rl   rq   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 rF   rA   ).0xs     r"   	<genexpr>z4TestGetLoc.test_get_loc_generator.<locals>.<genexpr>   s"      ..!......r=   r'   )rs   r+   r   r   r   r	   r
   r   r   r   ri   range)r   r   rt   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   Int64rJ   )FFTT)r   r   ri   ra   arrayr:   assert_numpy_array_equalr   idxr/   r0   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@   rj   ru   r|   r   rA   r=   r"   rg   rg      sP        " " "     4/ / /$6 6 6 6 6r=   rg   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 )NrJ   8Reindexing only valid with uniquely valued Index objectsr   zInvalid fill methodinvalid)method)_index_as_uniquera   arangesizeintpget_indexerr:   r   r   r   r   r   )r   r   r0   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+   ra   ndarrayrK   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~   rJ   )r   r   r&   )r   r   get_indexer_forra   r   rK   r:   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   rA   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')slicer+   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   rA   r=   r"   r   r     s#        9 9 9 9 9r=   r   c                       e Zd Zd ZdS )TestPutmaskc                    t          |          st          j        d           |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 )Nr8   r   z,putmask: mask and data must be the same sizer   r   r   )	r(   r   r)   r   r   putmaskra   onesbool_)r   r   fillr!   s       r"   test_putmask_with_wrong_maskz(TestPutmask.test_putmask_with_wrong_mask   s   5zz 	CKABBB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%&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	's8   	ABB B?ADDD5EE EN)r>   r?   r@   r   rA   r=   r"   r   r     s#        ' ' ' ' 'r=   r   r   )r   r   r&   )rT   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   rV   )r   r   
IndexError)r   r!   s     r"   test_getitem_deprecated_floatr   2  s     9C	z	-	-	-  C                 s   	488zidx,target,expectedvar1r   rJ   )r   r   r   z
2020-08-05r   r   r   r&   NaNc                 x    t          |           }|                    |          }t          j        ||           d S rF   )r   r   r:   r   )r   targetr0   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 )NrV   g       @r   objectrJ   r   r9   )r   r   r:   r   ra   r   r   )nulls_fixturer   r   
result_idxresult_missings        r"   7test_get_indexer_non_unique_nans_in_object_dtype_targetr   _  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__numpyra   r   pandas.errorsr   pandas.core.dtypes.commonr   r   pandasr   r   r   r	   r
   r   r   r   pandas._testing_testingr:   r   rC   rg   r   r   r   r_   r`   r   rc   r   r   r   floatr   r   rA   r=   r"   <module>r      s          + + + + + +       
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	      00 00 00 00 00 00 00 00fR  R  R  R  R  R  R  R j66 66 66 66 66 66 66 66r#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=   