o
    5c3                     @   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~   |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 )	Nr   ac)r         )r   r   r   dtype)r   r   r   )tmassert_numpy_array_equal_codesnparrayint8asarray)selffactorsubf r   c/var/www/html/gps/gps/lib/python3.10/site-packages/pandas/tests/arrays/categorical/test_indexing.pytest_getitem   s   "z.TestCategoricalIndexingWithFactor.test_getitemc                 C   s   |  }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 )Nbr   r   r   boolr   Tr   )r   r"   r"   r   r   r   r   r   ordered)copyr   zeroslenr   r   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_unordered5   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.   TFCCannot set a Categorical with another, without identical categoriesmatchr   r   r   pytestraises	TypeErrorr   r-   r0   r1   msgr   r   r    'test_setitem_different_unordered_raisesA   s   "zITestCategoricalIndexingWithFactor.test_setitem_different_unordered_raisesTr/   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>   Fr4   r5   r7   r;   r   r   r     test_setitem_same_ordered_raisesR   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_tupleb   s   z4TestCategoricalIndexingWithFactor.test_setitem_tuplec                 C   s   t jd tt j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   randomseedr   randintastyper   add_categoriesr   int64codesr   r   )r   rB   r*   resultr   r   r    test_setitem_listlikej   s   z7TestCategoricalIndexingWithFactor.test_setitem_listlikeN)__name__
__module____qualname__r!   r,   r8   markparametrizer   r2   r=   r?   rC   rQ   r   r   r   r    r      s6    


	

r   c                   @   s  e Zd Zd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      rX   rD   r   )r   r"   r   rX   r.   )r   r   r)   )r   rB   slicedr+   r   r   r    test_getitem_slice|   s   z*TestCategoricalIndexing.test_getitem_slicec                 C   sn   t jd tt jjddddt j}|jt dgt j	 }|t dgt j	 j}t
|| d S )Nr   r   rD   rE   rF   rH   )r   rI   rJ   r   rK   rL   r   rO   r   rN   r   r   )r   r   rP   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)   rD      rY   r   r   r   )ri   rh   rg   rf   re   rd   rc   )r	   r   strr   r   r   r   r   r   assert_index_equalr/   )
r   idx1cat1exp_arrexp_idxidx2cat2exp_idx2idx3cat3r   r   r    test_periodindex   s<   		z(TestCategoricalIndexing.test_periodindexc                 C   s   t g d}tjg dtjd}tjtdd g d|_W d    n1 s'w   Y  t|	 | t
|jtg d d S )Nr   r"   r   r   )r   r   rY   r   r   Use rename_categoriesr5   r   r   rY   )r   r   r   rN   r   assert_produces_warningFutureWarningr/   r   	__array__rm   r   )r   rB   expr   r   r    test_categories_assignments   s   z3TestCategoricalIndexing.test_categories_assignments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Dra   )r   r   r   z	period[D]r   r   )r	   r   r   rm   )r   r   rP   r+   r   r   r    test_periodindex_on_null_types   s   z6TestCategoricalIndexing.test_periodindex_on_null_typesnew_categories)r   r   rY   rk   r   r   c              	   C   s   t g d}d}tjtdd+ tjt|d ||_W d    n1 s%w   Y  W d    d S W d    d S 1 s=w   Y  d S )Nrx   zKnew categories need to have the same number of items as the old categories!ry   r5   )r   r   r{   r|   r8   r9   
ValueErrorr/   )r   r   rB   r<   r   r   r    /test_categories_assignments_wrong_length_raises   s   "zGTestCategoricalIndexing.test_categories_assignments_wrong_length_raises
idx_values)r   rY   r   rk   )r   rY   rY   rk   )r   r   r   rk   
key_valuesrD   	key_classr   )Ncategorykeyc                 C   s   ||t ddd}|dkr|j}t||d}||\}}||\}	}
t||	 t||
 | |}| |}t|| d S )Nr   rD   r.   r   r   )ranger   r   get_indexer_non_uniquer   r   uniqueget_indexer)r   r   r   r   r   r   idxr+   exp_missrP   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   serrP   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 )Nr3   rX   r   r"   r   r.   )TTFr"   )r-   )r   r"   r"   )r
   r   r   rB   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 )	Nr3   r   r.   r"   r   r   r   r   r"   rX   TFT)r   r   r   r   )r
   r   r   r   r   r   )r   r   r-   rP   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 )Nr3   z3Cannot setitem on a Categorical with a new categoryr5   r   rX   r
   r   r8   r9   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 )
Nr3   r   Tr>   r   r   zwithout identical categoriesr5   r   r   )r   r   r-   r   r   r    !test_where_ordered_differs_rasies  s   "z9TestCategoricalIndexing.test_where_ordered_differs_rasies)rR   rS   rT   r[   r\   rw   r   r8   rU   rV   r   r   r   r   mathr   r   r   r   r   r   r   r   r   r   r   r   r   r    rW   {   s0    	
3

$rW   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'r5   r   r   )r   listr   r   r8   r9   r:   rA   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 )NrY   )r   r   from_breaksr   )r   itemr+   rB   rP   r   r   r    test_contains_interval7  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 )Nrz   r   zunhashable typer5   r"   )r   r8   r9   r:   rA   r   r   r    test_contains_listI  s   "zTestContains.test_contains_listN)rR   rS   rT   r   r8   rU   rV   r   r   r   rl   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 )NrY   r   object)	r
   r   r   r   comis_bool_indexerrL   r   r   r   r   r   rP   r+   r   r   r    test_mask_with_booleanV  s   r   c                 C   sJ   t td}tg d}| rt|}|| }||d }t|| d S )NrY   )TFNF)r
   r   r   r   fillnar   r   r   r   r   r    *test_mask_with_boolean_na_treated_as_falsec  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   }  s   z(non_coercible_categorical.<locals>.arrayr}   )N)contextsetattrr   )monkeypatchr   mr   r   r    non_coercible_categoricalq  s   

"r   c                  C   s.   t g d} t| }|jd }|dksJ d S )Nr3   r   r   )r   r
   at)arrr   rP   r   r   r    test_series_at  s   
r   )!r   numpyr   r8   pandasr   r   r   r   r   r   r   r	   r
   r   r   pandas._testing_testingr   pandas.core.commoncorecommonr   r   rW   r   rU   rV   r   r   fixturer   r   r   r   r   r    <module>   s"    4d +1


