o
    LDi,                     @   s  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 dZG d	d
 d
ZG dd dZG dd dZG dd dZG dd dZejdeg deg deg dgdd Zejdej dej gej gej!ddgej"dfej dej gej dgej!g dej"dfej!ej dej ge#dej gej!ddgej"dfedeegegej!ddgej"dfd d!d ej gej gej!d"gej"dfej!d!ej e$d#d!ge#deej ge#dej!ddgej"dfgd$d% Z%d&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d Zdd Zdd Zdd Zd	S )
TestTakec                 C   s   ddg}d}t jt|d |j|dd W d    n1 sw   Y  d}t jt|d |j||d W d    n1 s?w   Y  d}t jt|d |j|d	d
 W d    d S 1 s`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msg r!   n/var/www/www-root/data/www/77.83.87.30/venv/lib/python3.10/site-packages/pandas/tests/indexes/test_indexing.pytest_take_invalid_kwargs*   s   "z!TestTake.test_take_invalid_kwargsc                 C   s   g d}t |dk rtd ||}|| }||sJ t|tttfsFd}tj	t
|d |j W d    d S 1 s?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    r!   r!   r"   	test_take9   s   

"zTestTake.test_takec                 C   sR   t g d}d}d}tjt|d || W d    d S 1 s"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    r!   r!   r"   test_take_indexer_typeH   s   "zTestTake.test_take_indexer_typec                 C   sL   t |dkrtd |g d}|ddt |d g}t|| 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.   r/   r!   r!   r"   test_take_minus1_without_fillP   s
   
z&TestTake.test_take_minus1_without_fillN)__name__
__module____qualname__r#   r0   r4   r9   r!   r!   r!   r"   r   )   s
    r   c                   @   s  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	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dejfeg dejdej	feg dejdejfeg dejdej	fg
dd Zejdeg ddfeg ddfgdd Zejdeg ddfeg ddfgdd Zdd Zdd ZdS )TestContainsz	index,val)r   r   r   r   )r   r   2r>   r   r   r$   c                 C      ||v sJ d S Nr!   r   r   valr!   r!   r"   test_index_contains]   s   z TestContains.test_index_containsdtypec                 C      ||vsJ d S r@   r!   rA   r!   r!   r"   test_index_not_containsk   s   z$TestContains.test_index_not_containsc                 C   r?   r@   r!   rA   r!   r!   r"   test_mixed_index_contains      z&TestContains.test_mixed_index_contains1c                 C   rF   r@   r!   rA   r!   r!   r"   test_mixed_index_not_contains   rI   z*TestContains.test_mixed_index_not_containsc                 C   s   |}t |s
g dng d}t||d}t |js-d|vsJ d|v s%J d|v s+J d S d|v s3J d|vs9J d|vs?J d S )Nr1   )皙?皙?g@gffffff
@rD   rM         ?r   )r   r   rE   )r   any_real_numpy_dtyperE   datar   r!   r!   r"   test_contains_with_float_index   s   
z+TestContains.test_contains_with_float_indexc                 C   s   t |trd S d}tjt|d g |v  W d    n1 sw   Y  tr)d}nd}ddddd	d
| g}tjt|d i |jv  W d    d S 1 sPw   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_iterabler!   r!   r"   &test_contains_requires_hashable_raises   s,   


"z3TestContains.test_contains_requires_hashable_raisesN)r:   r;   r<   r   markparametrizer   npinfnanrC   int64uint64rG   rH   rK   rQ   rW   r!   r!   r!   r"   r=   \   sJ    

 
 
r=   c                   @   r   )

TestGetLocc                 C   sB   t jtdd |ddg W d    d S 1 sw   Y  d S )Nz[0, 1]r   r   r   )r   r   r   get_loc)r   r   r!   r!   r"   test_get_loc_non_hashable   s   "z$TestGetLoc.test_get_loc_non_hashablec                 C   s   ddl m} G dd d|}t|jrJ t}d}t|tttt	fr&t
}d}tj||d ||j W d    d S 1 s?w   Y  d S )Nr   )Enumc                   @   s   e Zd ZdZdS )z6TestGetLoc.test_get_loc_non_scalar_hashable.<locals>.Ex1N)r:   r;   r<   X1r!   r!   r!   r"   E   s    re   z<E.X1: 'x1'>zE.X1r   )enumrb   r   rd   KeyErrorr*   r   r   r   r	   r   r   r   r`   )r   r   rb   re   excr    r!   r!   r"    test_get_loc_non_scalar_hashable   s$   
"z+TestGetLoc.test_get_loc_non_scalar_hashablec                 C   sh   t }t|tttttfrt}tj	|dd |
dd tdD  W d    d S 1 s-w   Y  d S )Nzgenerator objectr   c                 s   s    | ]}|V  qd S r@   r!   ).0xr!   r!   r"   	<genexpr>   s    z4TestGetLoc.test_get_loc_generator.<locals>.<genexpr>r&   )rg   r*   r   r   r   r	   r
   r   r   r   r`   range)r   r   rh   r!   r!   r"   test_get_loc_generator   s   "z!TestGetLoc.test_get_loc_generatorc                 C   s<   t ddttgdd}|t}tg d}t|| d S )Nr   r   Int64rD   )FFTT)r   r   r`   rZ   arrayr7   assert_numpy_array_equalr   idxr.   r/   r!   r!   r"   !test_get_loc_masked_duplicated_na   s   
z,TestGetLoc.test_get_loc_masked_duplicated_naN)r:   r;   r<   ra   ri   rn   rt   r!   r!   r!   r"   r_      s
    r_   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestGetIndexerc                 C   s   |j rtj|jtjd}||}t|| nd}tj	t
|d || W d    n1 s1w   Y  tj	tdd |j|dd W d    d S 1 sPw   Y  d S )NrD   8Reindexing only valid with uniquely valued Index objectsr   zInvalid fill methodinvalid)method)_index_as_uniquerZ   arangesizeintpget_indexerr7   rq   r   r   r   r   )r   r   r/   actualr    r!   r!   r"   test_get_indexer_base   s   
"z$TestGetIndexer.test_get_indexer_basec                 C   s   |j r||dd }t|tjsJ |jtjksJ n"d}tjt	|d ||dd  W d    n1 s:w   Y  |
|dd \}}t|tjsRJ |jtjksZJ d S )Nr   r   rv   r   )ry   r}   r*   rZ   ndarrayrE   r|   r   r   r   get_indexer_non_unique)r   r   r-   r    _r!   r!   r"   test_get_indexer_consistency   s   z+TestGetIndexer.test_get_indexer_consistencyc                 C   sN   t ddttgdd}|t dtgdd}tjg d|jd}t|| d S )Nr   r   ro   rD   )r   r   r%   )r   r   get_indexer_forrZ   rp   rE   r7   rq   rr   r!   r!   r"   %test_get_indexer_masked_duplicated_na  s   z4TestGetIndexer.test_get_indexer_masked_duplicated_naN)r:   r;   r<   r   r   r   r!   r!   r!   r"   ru      s    ru   c                   @      e Zd Zdd ZdS )TestConvertSliceIndexerc                 C   s   t d d d}t|tr-d}tjt|d ||d W d    d S 1 s&w   Y  d S d}tjt|d ||d W d    d S 1 sHw   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    r!   r!   r"   test_convert_almost_null_slice  s   
""z6TestConvertSliceIndexer.test_convert_almost_null_sliceN)r:   r;   r<   r   r!   r!   r!   r"   r         r   c                   @   r   )TestPutmaskc                 C   s   t |s	td |d }d}tjt|d |tt |d tj| W d    n1 s0w   Y  tjt|d |tt |d tj| W d    n1 sVw   Y  tjt|d |d| W d    d S 1 stw   Y  d S )Nr5   r   z,putmask: mask and data must be the same sizer   r   r   )	r'   r   r(   r   r   putmaskrZ   onesbool_)r   r   fillr    r!   r!   r"   test_putmask_with_wrong_mask'  s   
  "z(TestPutmask.test_putmask_with_wrong_maskN)r:   r;   r<   r   r!   r!   r!   r"   r   &  r   r   rs   )r   r   r%   )rL   g?g333333?)abcc                 C   s@   d}t jt|d | d  W d    d S 1 sw   Y  d S )Nz,Indexing with a float is no longer supportedr   rN   )r   r   
IndexError)rs   r    r!   r!   r"   test_getitem_deprecated_float9  s   
"r   zidx,target,expectedvar1r   rD   )r   r   r   z
2020-08-05r   r   r   r%   NaNc                 C   s"   t | }||}t|| d S r@   )r   r   r7   rq   )rs   targetr/   axisr~   r!   r!   r"   )test_get_indexer_non_unique_multiple_nansD  s   
r   c                 C   sd   t ddg}t d| gdd}||\}}t|tjddgtjd t|tjdgtjd d S )NrN   g       @r   objectrD   r   r6   )r   r   r7   rq   rZ   rp   r|   )nulls_fixturers   r   
result_idxresult_missingr!   r!   r"   7test_get_indexer_non_unique_nans_in_object_dtype_targetf  s
   r   )'__doc__numpyrZ   r   pandas.compatr   pandas.errorsr   pandas.core.dtypes.commonr   r   pandasr   r   r   r	   r
   r   r   r   pandas._testing_testingr7   r   r=   r_   ru   r   r   rX   rY   r   r\   rp   r|   r   floatr   r   r!   r!   r!   r"   <module>   sT    (
3[9&"
&$
