a
    DBìj¬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s0J ‚|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Úint8Zasarray)ÚselfÚfactorZsubf© r!   úl/mnt/bigstor/www/usecases/.venv/lib/python3.9/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s0J ‚d|d< |d dksHJ ‚| ¡ }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   Z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   sd   t ddgddgd�}t ddg¡}d}tjt|d�� || ||< W d   ƒ n1 sV0    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+   r.   r/   Úmsgr!   r!   r"   Ú'test_setitem_different_unordered_raisesB   s
    zITestCategoricalIndexingWithFactor.test_setitem_different_unordered_raisesT©r-   r   c                 C   sf   t ddgddgdd�}t ddg¡}d}tjt|d�� || ||< W d   ƒ n1 sX0    Y  d S )Nr   r   Tr<   Fr2   r3   r5   r9   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   r>   r   r   r>   )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   Zadd_categoriesr   Úint64Úcodesr   r   )r   r@   r(   Úresultr!   r!   r"   Útest_setitem_listlikek   s    ÿþz7TestCategoricalIndexingWithFactor.test_setitem_listlikeN)Ú__name__Ú
__module__Ú__qualname__r#   r*   r6   ÚmarkÚparametrizer   r0   r;   r=   rA   rN   r!   r!   r!   r"   r      s4   þ
üþ	

ýþ
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   é   rU   rB   r   )r   r   r   rU   r,   )r   r   r'   )r   r@   Z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   rB   rC   rD   rF   )r   r   rG   rH   rI   rJ   r   rL   r   rK   r   r   )r   r   rM   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-01rY   ú2014-02rZ   ú2014-03r[   ÚM©Úfreq)r   r   r   r   r   r   r   )rY   rZ   r[   )r[   r[   rZ   rY   r[   rY   Tr   )r   r   r   r   r   r   )ú2013-12ú2013-11ú2013-10ú2013-09ú2013-08ú2013-07ú2013-05)é   rB   é   rV   r   r   r   )re   rd   rc   rb   ra   r`   r_   )r	   r   Ústrr   r   r   r   r   r   Úassert_index_equalr-   )
r   Zidx1Zcat1Zexp_arrZexp_idxZidx2Úcat2Zexp_idx2Zidx3Zcat3r!   r!   r"   Útest_periodindex�   s@    þþ	ö	öz(TestCategoricalIndexing.test_periodindexÚnull_valNr   ZnatZNATÚnanÚNaNZNANc                 C   sB   t dd|gdd�}t g d¢dd�}|d tu s2J ‚t ||¡ d S )	Nú
2022-04-06ú
2022-04-07ÚDr]   )ro   rp   r   z	period[D]r   r   )r	   r   r   ri   )r   rl   rM   r)   r!   r!   r"   Útest_periodindex_on_null_typesÅ   s    z6TestCategoricalIndexing.test_periodindex_on_null_typesÚnew_categories)r   r   rV   rg   r   r   c                 C   sL   t g d¢ƒ}d}tjt|d�� | |¡ W d   ƒ n1 s>0    Y  d S )N)r   r   r   r   zKnew categories need to have the same number of items as the old categories!r3   )r   r6   r7   Ú
ValueErrorZrename_categories)r   rs   r@   r:   r!   r!   r"   Ú/test_categories_assignments_wrong_length_raisesÐ   s
    ÿzGTestCategoricalIndexing.test_categories_assignments_wrong_length_raisesÚ
idx_values)r   rV   r   rg   )r   rV   rV   rg   )r   r   r   rg   Ú
key_valuesrB   Ú	key_classr   )NÚcategoryÚkeyc                 C   sŒ   ||t ddƒd�}|dkr |j}t||d�}| |¡\}}| |¡\}	}
t ||	¡ t ||
¡ | ¡  |¡}| ¡  |¡}t ||¡ d S )Nr   rB   r,   rz   r   )Úranger   r   Zget_indexer_non_uniquer   r   ÚuniqueZget_indexer)r   rv   rw   rx   r   rz   Úidxr)   Zexp_missrM   Zres_missZ
exp_uniqueZ
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   ÚserrM   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 )Nr1   ©rU   r   r   r   r,   )TTFr   )r+   )r   r   r   )r
   r   r   r@   r-   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 )	Nr1   r„   r,   ©r   r   r   ©r   r   r   rU   ©TFT)r   r   r   r   )r
   r   r   r   r   r€   )r   r‚   r+   rM   r)   r!   r!   r"   Útest_where_other_categorical  s
    z4TestCategoricalIndexing.test_where_other_categoricalc                 C   sV   t tg d¢ƒƒ}d}tjt|d��  | g d¢d¡ W d   ƒ n1 sH0    Y  d S )Nr1   z3Cannot setitem on a Categorical with a new categoryr3   rˆ   rU   ©r
   r   r6   r7   r8   r   )r   r‚   r:   r!   r!   r"   Útest_where_new_category_raises  s    z6TestCategoricalIndexing.test_where_new_category_raisesc                 C   sr   t tg d¢g d¢dd�ƒ}tg d¢g d¢dd�}tjtdd��  | g d	¢|¡ W d   ƒ n1 sd0    Y  d S )
Nr1   r„   Tr<   r†   r‡   zwithout identical categoriesr3   rˆ   rŠ   )r   r‚   r+   r!   r!   r"   Ú!test_where_ordered_differs_rasies  s    ÿÿz9TestCategoricalIndexing.test_where_ordered_differs_rasies)rO   rP   rQ   rW   rX   rk   r6   rR   rS   r   rm   r   r   Úmathrr   ru   r   r   r~   rƒ   r…   r‰   r‹   rŒ   r!   r!   r!   r"   rT   {   s,   	5þ


ÿ$rT   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 sXJ ‚W d   ƒ n1 sl0    Y  d	|vs‚J ‚d|vsŽJ ‚t tdƒtjg tdƒd�}tj|v s¸J ‚d S )
NZaabbcaZcabr,   r   Úzzunhashable type: 'list'r3   r   r   )r   Úlistr   rm   r6   r7   r8   r?   r!   r!   r"   Útest_contains   s    ,zTestContains.test_containszitem, expectedr   r   T)ç      ø?Tg      à?r’   F)r   F)Zidsc                 C   s*   t t tdƒ¡ƒ}||v }||u s&J ‚d S )NrV   )r   r   Zfrom_breaksr{   )r   Úitemr)   r@   rM   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 sF0    Y  tjtdd�� ddg|v  W d   ƒ n1 s€0    Y  d S )N)r   r   rV   r   zunhashable typer3   r   )r   r6   r7   r8   r?   r!   r!   r"   Útest_contains_listC  s    (zTestContains.test_contains_listN)rO   rP   rQ   r‘   r6   rR   rS   r   r   r   rh   r”   r•   r!   r!   r!   r"   rŽ     s   

úö
rŽ   ÚindexTFc                 C   sX   t tdƒƒ}tg d¢ƒ}| r$t|ƒ}t |¡s2J ‚|| }|| d¡ }t ||¡ d S )NrV   rˆ   Úobject)	r
   r{   r   r   ÚcomZis_bool_indexerrJ   r   r€   ©r–   r‚   r}   rM   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 )NrV   )TFNF)r
   r{   r   r   Zfillnar   r€   r™   r!   r!   r"   Ú*test_mask_with_boolean_na_treated_as_false]  s    r›   c                 c   sJ   ddd„}|   ¡ �$}| td|¡ dV  W d  ƒ n1 s<0    Y  dS )z¡
    Monkeypatch Categorical.__array__ to ensure no implicit conversion.

    Raises
    ------
    ValueError
        When Categorical.__array__ is called.
    Nc                 S   s   t dƒ‚d S )NzI cannot be converted.)rt   )r   r   r!   r!   r"   r   x  s    z(non_coercible_categorical.<locals>.arrayZ	__array__)N)ÚcontextÚsetattrr   )Zmonkeypatchr   Úmr!   r!   r"   Únon_coercible_categoricalk  s    

rŸ   c                  C   s.   t g d¢ƒ} t| ƒ}|jd }|dks*J ‚d S )Nr1   r   r   )r   r
   Úat)Zarrr‚   rM   r!   r!   r"   Útest_series_at€  s    
r¡   )!r�   Únumpyr   r6   Zpandasr   r   r   r   r   r   r   r	   r
   r   r   Zpandas._testingZ_testingr   Zpandas.core.commonÚcoreÚcommonr˜   r   rT   rŽ   rR   rS   rš   r›   ZfixturerŸ   r¡   r!   r!   r!   r"   Ú<module>   s    4d %1


