
    zhh,                     d   d Z ddlZddlZddlm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)PY314)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       Y/var/www/histauto/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_take9   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_typeH   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    r0   r1   s       r#   test_take_minus1_without_fillz&TestTake.test_take_minus1_without_fillP   sr    u::??KABBBJJJ''::q!SZZ!^455
fh/////    N)__name__
__module____qualname__r$   r2   r7   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   2rE   r   r   r&   c                     ||v sJ d S NrB   r   r    vals      r#   test_index_containsz TestContains.test_index_contains]   s     e||||||r>   dtypec                     ||vsJ d S rG   rB   rH   s      r#   test_index_not_containsz$TestContains.test_index_not_containsk   s    $ %r>   c                     ||v sJ d S rG   rB   rH   s      r#   test_mixed_index_containsz&TestContains.test_mixed_index_contains   s    
 e||||||r>   1c                     ||vsJ d S rG   rB   rH   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 )Nr4   )皙?皙?g@gffffff
@rK   rV         ?r   )r   r	   rL   )r   any_real_numpy_dtyperL   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                 r   t          |t                    rd S d}t          j        t          |          5  g |v  d d d            n# 1 swxY w Y   t
          rd}nd}d                    dddd	d
| g          }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a container or iterableiterable|zunhashable type: 'dict'zmust be real number, not dictzan integer is requiredz\{\}z.pandas\._libs\.interval\.IntervalTree' is not )r,   r   r   r   r   r   join_engine)r   r    r"   container_or_iterables       r#   &test_contains_requires_hashable_raisesz3TestContains.test_contains_requires_hashable_raises   sh   eZ(( 	F']9C000 	 	%KK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  	/$=!!$.!hh*0)+(+ +	
 	
 ]9C000 	  	 %-	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s#   AA
A

B,,B03B0N)r?   r@   rA   r   markparametrizer	   npinfnanrJ   int64uint64rN   rP   rS   rZ   ra   rB   r>   r#   rD   rD   \   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>   rD   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@   rA   X1rB   r>   r#   Erq      s        BBBr>   rt   z<E.X1: 'x1'>zE.X1r   )enumro   r   rs   KeyErrorr,   r   r   r   r
   r   r   r   rl   )r   r    ro   rt   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 rG   rB   ).0xs     r#   	<genexpr>z4TestGetLoc.test_get_loc_generator.<locals>.<genexpr>   s"      ..!......r>   r(   )rv   r,   r   r   r   r
   r   r   r   r   rl   range)r   r    rw   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   Int64rK   )FFTT)r	   r   rl   rd   arrayr;   assert_numpy_array_equalr   idxr0   r1   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@   rA   rm   rx   r   r   rB   r>   r#   rj   rj      sP        " " "     4/ / /$6 6 6 6 6r>   rj   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 )NrK   8Reindexing only valid with uniquely valued Index objectsr   zInvalid fill methodinvalid)method)_index_as_uniquerd   arangesizeintpget_indexerr;   r   r   r   r   r   )r   r    r1   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,   rd   ndarrayrL   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   rK   )r   r   r'   )r	   r   get_indexer_forrd   r   rL   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@   rA   r   r   r   rB   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@   rA   r   rB   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 )Nr9   r   z,putmask: mask and data must be the same sizer   r   r   )	r)   r   r*   r   r   putmaskrd   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@   rA   r   rB   r>   r#   r   r   &  s#        ' ' ' ' 'r>   r   r   )r   r   r'   )rU   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   rW   )r   r   
IndexError)r   r"   s     r#   test_getitem_deprecated_floatr   9  s     9C	z	-	-	-  C                 s   	488zidx,target,expectedvar1r   rK   )r   r   r   z
2020-08-05r   r   r   r'   NaNc                 x    t          |           }|                    |          }t          j        ||           d S rG   )r	   r   r;   r   )r   targetr1   axisr   s        r#   )test_get_indexer_non_unique_multiple_nansr   D  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 )NrW   g       @r   objectrK   r   r:   )r	   r   r;   r   rd   r   r   )nulls_fixturer   r   
result_idxresult_missings        r#   7test_get_indexer_non_unique_nans_in_object_dtype_targetr   f  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__numpyrd   r   pandas.compatr   pandas.errorsr   pandas.core.dtypes.commonr   r   pandasr   r   r	   r
   r   r   r   r   pandas._testing_testingr;   r   rD   rj   r   r   r   rb   rc   r   rf   r   r   r   floatr   r   rB   r>   r#   <module>r      s                + + + + + +       
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	      00 00 00 00 00 00 00 00fX  X  X  X  X  X  X  X v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>   