o
    �¨Êh¬2  ã                   @   sâ   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mZmZmZmZ d dlmZ d dlm  mZ G dd„ dƒZG dd„ dƒZG dd„ dƒZej d	d
dg¡dd„ ƒZej d	d
dg¡dd„ ƒZejdd„ ƒZdd„ Z dS )é    N)ÚNAÚCategoricalÚCategoricalIndexÚIndexÚIntervalÚIntervalIndexÚNaTÚPeriodIndexÚSeriesÚ	TimedeltaÚ	Timestampc                
   @   s   e Zd Zdd„ Zdd„ Zej deddgƒeddgddgd�g¡d	d
„ ƒZ	ej deddgg d¢d�eddgg d¢d�eddgdgd�eddgdgd�g¡dd„ ƒZ
ej deddgƒeddgddgdd�eddgg d¢dd�g¡dd„ ƒZdd„ Zdd„ ZdS )Ú!TestCategoricalIndexingWithFactorc                 C   sŽ   t g d¢dd�}|d dksJ ‚|d dksJ ‚|g d¢ }t |jtjg d	¢tjd
�¡ |t |¡dk }t |jtjg d¢tjd
�¡ d S )N©ÚaÚbr   r   r   Úcr   r   T©Úorderedr   r   éÿÿÿÿr   )r   é   é   )r   r   r   ©Údtype)r   r   r   )r   ÚtmÚassert_numpy_array_equalÚ_codesÚnpÚarrayÚint8Úasarray)ÚselfÚfactorÚsubf© r#   ú_/var/www/html/env/lib/python3.10/site-packages/pandas/tests/arrays/categorical/test_indexing.pyÚtest_getitem   s   "z.TestCategoricalIndexingWithFactor.test_getitemc                 C   sš   t g d¢dd�}| ¡ }d|d< |d dksJ ‚d|d< |d dks$J ‚| ¡ }tjt|ƒdd	�}d|d< d|d< d
||< t g d¢dd�}t ||¡ d S )Nr   Tr   r   r   r   r   Úboolr   r   )r   r   r   r   r   r   r   r   )r   Úcopyr   ÚzerosÚlenr   Úassert_categorical_equal)r    r!   r   ÚindexerÚexpectedr#   r#   r$   Útest_setitem#   s   z.TestCategoricalIndexingWithFactor.test_setitemÚotherr   r   ©Ú
categoriesc                 C   sR   t ddgddgd�}t ddg¡}|| ||< t ddgddgd�}t ||¡ d S )Nr   r   r/   TF)r   r   r   r   r*   )r    r.   ÚtargetÚmaskr,   r#   r#   r$   Útest_setitem_same_but_unordered6   s
   zATestCategoricalIndexingWithFactor.test_setitem_same_but_unordered)r   r   r   ©r   r   r   c                 C   sf   t ddgddgd�}t ddg¡}d}tjt|d�� || ||< W d   ƒ d S 1 s,w   Y  d S )Nr   r   r/   TFúCCannot set a Categorical with another, without identical categories©Úmatch©r   r   r   ÚpytestÚraisesÚ	TypeError©r    r.   r1   r2   Úmsgr#   r#   r$   Ú'test_setitem_different_unordered_raisesB   s   "ÿzITestCategoricalIndexingWithFactor.test_setitem_different_unordered_raisesT©r0   r   c                 C   sh   t ddgddgdd�}t ddg¡}d}tjt|d�� || ||< W d   ƒ d S 1 s-w   Y  d S )Nr   r   Tr?   Fr5   r6   r8   r<   r#   r#   r$   Ú test_setitem_same_ordered_raisesS   s   
"ÿzBTestCategoricalIndexingWithFactor.test_setitem_same_ordered_raisesc                 C   s,   t g d¢ƒ}|d |d< |d dksJ ‚d S )N)©r   r   )r   r   rA   r   r   rA   )r   ©r    Úcatr#   r#   r$   Útest_setitem_tuplec   s   z4TestCategoricalIndexingWithFactor.test_setitem_tuplec                 C   s~   t tj d¡jdddd� tj¡ƒ dg¡}t dg¡ tj	¡}d||< |j
t dg¡ tj	¡ }t |tjdgdd	�¡ d S )
Nr   r   é   éðI ©Úsizeiüÿÿé † r   r   )r   r   ÚrandomÚdefault_rngÚintegersÚastyper   Úadd_categoriesr   Úint64Úcodesr   r   )r    rC   r+   Úresultr#   r#   r$   Útest_setitem_listlikek   s   ÿþz7TestCategoricalIndexingWithFactor.test_setitem_listlikeN)Ú__name__Ú
__module__Ú__qualname__r%   r-   r9   ÚmarkÚparametrizer   r3   r>   r@   rD   rR   r#   r#   r#   r$   r      s6    þ
üþ
	
ýþ
r   c                   @   s  e Zd Zdd„ Zdd„ Zdd„ Zej dde	j
eeej
d	d
ddddg¡dd„ ƒZej dg d¢ddgg¡dd„ ƒZej dg d¢g d¢g d¢g d¢g¡ej dddgddgddgddgg¡ej deeg¡ej dg d¢¡d d!„ ƒƒƒƒZd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ ZdS ),ÚTestCategoricalIndexingc                 C   sP   t g d¢ƒ}|d }|dksJ ‚|dd… }t ddgg d¢d�}t ||¡ d S )N)r   r   r   Údr   r   r   é   rY   rE   r   )r   r   r   rY   r/   )r   r   r*   )r    rC   Úslicedr,   r#   r#   r$   Útest_getitem_slice|   s   z*TestCategoricalIndexing.test_getitem_slicec                 C   sh   t tj d¡jdddd� tj¡ƒ}|jt dg¡ tj	¡ }|t dg¡ tj	¡ j}t
 ||¡ d S )Nr   r   rE   rF   rG   rI   )r   r   rJ   rK   rL   rM   r   rP   r   rO   r   r   )r    r   rQ   r,   r#   r#   r$   Útest_getitem_listlike…   s   ÿz-TestCategoricalIndexing.test_getitem_listlikec           
      C   s$  t g d¢dd�}t|ƒ}t|ƒ tjg d¢tjd�}t g d¢dd�}t |j|¡ t 	|j
|¡ t g d¢dd�}t|dd	�}t|ƒ tjg d
¢tjd�}t g d¢dd�}t |j|¡ t 	|j
|¡ t g d¢dd�}t|dd	�}	tjg d¢tjd�}t g d¢dd�}t |	j|¡ t 	|	j
|¡ d S )N)ú2014-01r^   ú2014-02r_   ú2014-03r`   ÚM©Úfreq)r   r   r   r   r   r   r   )r^   r_   r`   )r`   r`   r_   r^   r`   r^   Tr   )r   r   r   r   r   r   )ú2013-12ú2013-11ú2013-10ú2013-09ú2013-08ú2013-07ú2013-05)é   rE   é   rZ   r   r   r   )rj   ri   rh   rg   rf   re   rd   )r	   r   Ústrr   r   r   r   r   r   Úassert_index_equalr0   )
r    Úidx1Úcat1Úexp_arrÚexp_idxÚidx2Úcat2Úexp_idx2Úidx3Úcat3r#   r#   r$   Útest_periodindex�   s@   þþ	ö	öz(TestCategoricalIndexing.test_periodindexÚnull_valNr   ÚnatÚNATÚnanÚNaNÚNANc                 C   sB   t dd|gdd�}t g d¢dd�}|d tu sJ ‚t ||¡ d S )	Nú
2022-04-06ú
2022-04-07ÚDrb   )r   r€   r   z	period[D]r   r   )r	   r   r   rn   )r    ry   rQ   r,   r#   r#   r$   Útest_periodindex_on_null_typesÅ   s   z6TestCategoricalIndexing.test_periodindex_on_null_typesÚnew_categories)r   r   rZ   rl   r   r   c                 C   sN   t g d¢ƒ}d}tjt|d�� | |¡ W d   ƒ d S 1 s w   Y  d S )N)r   r   r   r   zKnew categories need to have the same number of items as the old categories!r6   )r   r9   r:   Ú
ValueErrorÚrename_categories)r    rƒ   rC   r=   r#   r#   r$   Ú/test_categories_assignments_wrong_length_raisesÐ   s   ÿ"ÿzGTestCategoricalIndexing.test_categories_assignments_wrong_length_raisesÚ
idx_values)r   rZ   r   rl   )r   rZ   rZ   rl   )r   r   r   rl   Ú
key_valuesrE   Ú	key_classr   )NÚcategoryÚkeyc                 C   sŒ   ||t ddƒd�}|dkr|j}t||d�}| |¡\}}| |¡\}	}
t ||	¡ t ||
¡ | ¡  |¡}| ¡  |¡}t ||¡ d S )Nr   rE   r/   r‹   r   )Úranger   r   Úget_indexer_non_uniquer   r   ÚuniqueÚget_indexer)r    r‡   rˆ   r‰   r   r‹   Úidxr,   Úexp_missrQ   Úres_missÚ
exp_uniqueÚ
res_uniquer#   r#   r$   Útest_get_indexer_non_uniqueÛ   s   	z3TestCategoricalIndexing.test_get_indexer_non_uniquec                 C   sˆ   t tddgƒƒ}| ddg¡}t tdd gddgd�ƒ}t ||¡ t tddgƒƒ}| ddg¡}t td d gddgd�ƒ}t ||¡ d S )Nr   r   TFr/   )r
   r   Úwherer   Úassert_series_equal©r    ÚserrQ   r,   r#   r#   r$   Útest_where_unobserved_nanõ   s   z1TestCategoricalIndexing.test_where_unobserved_nanc                 C   sR   t tg d¢g d¢d�ƒ}|jg d¢dd�}t tg d¢|jjd�ƒ}t ||¡ d S )Nr4   ©rY   r   r   r   r/   )TTFr   )r.   )r   r   r   )r
   r   r–   rC   r0   r   r—   r˜   r#   r#   r$   Ú test_where_unobserved_categories  s   z8TestCategoricalIndexing.test_where_unobserved_categoriesc                 C   sb   t tg d¢g d¢d�ƒ}tg d¢g d¢d�}| g d¢|¡}t tg d¢|jd�ƒ}t ||¡ d S )	Nr4   r›   r/   ©r   r   r   ©r   r   r   rY   ©TFT)r   r   r   r   )r
   r   r–   r   r   r—   )r    r™   r.   rQ   r,   r#   r#   r$   Útest_where_other_categorical  s
   z4TestCategoricalIndexing.test_where_other_categoricalc                 C   sX   t tg d¢ƒƒ}d}tjt|d�� | g d¢d¡ W d   ƒ d S 1 s%w   Y  d S )Nr4   z3Cannot setitem on a Categorical with a new categoryr6   rŸ   rY   ©r
   r   r9   r:   r;   r–   )r    r™   r=   r#   r#   r$   Útest_where_new_category_raises  s
   "ÿz6TestCategoricalIndexing.test_where_new_category_raisesc                 C   st   t tg d¢g d¢dd�ƒ}tg d¢g d¢dd�}tjtdd�� | g d	¢|¡ W d   ƒ d S 1 s3w   Y  d S )
Nr4   r›   Tr?   r�   rž   zwithout identical categoriesr6   rŸ   r¡   )r    r™   r.   r#   r#   r$   Ú!test_where_ordered_differs_rasies  s   ÿÿ"ÿz9TestCategoricalIndexing.test_where_ordered_differs_rasies)rS   rT   rU   r\   r]   rx   r9   rV   rW   r   r|   r   r   Úmathr‚   r†   r   r   r•   rš   rœ   r    r¢   r£   r#   r#   r#   r$   rX   {   s.    	5þ


ÿ$rX   c                	   @   sf   e Zd Zdd„ Zejjdeddƒdfdedd	ƒd
fdedƒd
fe	dƒd
fge
d�dd„ ƒZdd„ ZdS )ÚTestContainsc                 C   s¼   t tdƒtdƒd�}d|v sJ ‚d|vsJ ‚tj|vsJ ‚tjtdd�� dg|v s,J ‚W d   ƒ n1 s6w   Y  d	|vsAJ ‚d|vsGJ ‚t tdƒtjg tdƒd�}tj|v s\J ‚d S )
NÚaabbcaÚcabr/   r   Úzzunhashable type: 'list'r6   r   r   )r   Úlistr   r|   r9   r:   r;   rB   r#   r#   r$   Útest_contains   s   ÿzTestContains.test_containszitem, expectedr   r   T)ç      ø?Tg      à?r«   F)r   F)Úidsc                 C   s*   t t tdƒ¡ƒ}||v }||u sJ ‚d S )NrZ   )r   r   Úfrom_breaksrŒ   )r    Úitemr,   rC   rQ   r#   r#   r$   Útest_contains_interval1  s   z#TestContains.test_contains_intervalc                 C   s�   t g d¢ƒ}d|vsJ ‚tjtdd�� dg|v  W d   ƒ n1 s#w   Y  tjtdd�� ddg|v  W d   ƒ d S 1 sAw   Y  d S )N)r   r   rZ   r   zunhashable typer6   r   )r   r9   r:   r;   rB   r#   r#   r$   Útest_contains_listC  s   ÿ"ÿzTestContains.test_contains_listN)rS   rT   rU   rª   r9   rV   rW   r   r   r   rm   r¯   r°   r#   r#   r#   r$   r¥     s    

úö
r¥   ÚindexTFc                 C   sX   t tdƒƒ}tg d¢ƒ}| rt|ƒ}t |¡sJ ‚|| }|| d¡ }t ||¡ d S )NrZ   rŸ   Úobject)	r
   rŒ   r   r   ÚcomÚis_bool_indexerrM   r   r—   ©r±   r™   r�   rQ   r,   r#   r#   r$   Útest_mask_with_booleanP  s   r¶   c                 C   sJ   t tdƒƒ}tg d¢ƒ}| rt|ƒ}|| }|| d¡ }t ||¡ d S )NrZ   )TFNF)r
   rŒ   r   r   Úfillnar   r—   rµ   r#   r#   r$   Ú*test_mask_with_boolean_na_treated_as_false]  s   r¸   c                 c   sN   � ddd„}|   ¡ �}| td|¡ dV  W d  ƒ dS 1 s w   Y  dS )z¡
    Monkeypatch Categorical.__array__ to ensure no implicit conversion.

    Raises
    ------
    ValueError
        When Categorical.__array__ is called.
    Nc                 S   s   t dƒ‚)NzI cannot be converted.)r„   )r    r   r#   r#   r$   r   x  s   z(non_coercible_categorical.<locals>.arrayÚ	__array__)N)ÚcontextÚsetattrr   )Úmonkeypatchr   Úmr#   r#   r$   Únon_coercible_categoricalk  s   €

"þr¾   c                  C   s.   t g d¢ƒ} t| ƒ}|jd }|dksJ ‚d S )Nr4   r   r   )r   r
   Úat)Úarrr™   rQ   r#   r#   r$   Útest_series_at€  s   
rÁ   )!r¤   Únumpyr   r9   Úpandasr   r   r   r   r   r   r   r	   r
   r   r   Úpandas._testingÚ_testingr   Úpandas.core.commonÚcoreÚcommonr³   r   rX   r¥   rV   rW   r¶   r¸   Úfixturer¾   rÁ   r#   r#   r#   r$   Ú<module>   s"    4d %1


