o
    dJ                     @   s   d dl Z d dlZd dlZd dlmZ d dl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 d dlmZ ejdd Zejdd ZG d	d
 d
ZdS )    N)is_categorical_dtype)CategoricalCategoricalIndex	DataFrameIndexIntervalSeries	Timedelta	Timestamp)CategoricalDtypec                   C   0   t dtjdddittdttdddd	S )
NA   int64dtypeaabbcacabBr   nameindexr   nparanger   listCDT r   r   k/var/www/html/visualizacion-main/env/lib/python3.10/site-packages/pandas/tests/indexing/test_categorical.pydf   
   r    c                   C   r   )
Nr   r   r   r   r   caber   r   r   r   r   r   r   r   df2!   r!   r#   c                
   @   s  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zejd'g d(g d)g d*g d+gd,d- ejD d.d- ejD ejg d/ed0ed1d2ed2d3ed3d4ge d5d1d1e d5d6d1e d5d7d1ge!d1d8e!d6d8e!d7d9gd:d- ej"D e#j$%g d;je#j&d<d7d=je#j'd>d7d?jd@dA Z(dBdC Z)dDS )ETestCategoricalIndexc                 C   s2  t td}|jd }ttddd|}|j|ksJ tdg dit|d}t	|| |
 }d	|jd< ttd
dd|}|j|ksJJ tdg dit|d}t	|| tjtdd |jd  W d    n1 ssw   Y  |
 }|
 }|jt|_d|jd< d|jd< t	|| d S )Nr   aaaar   r   r   )r         r      r   )r*   r*            r*   z^'d'$matchd
   )r   r   locr   astyper   r   r   tmassert_frame_equalcopypytestraisesKeyErrorr   object)selfr    r   resultbidxexpectedbidx2r#   r   r   r   test_loc_scalar,   s2   



z$TestCategoricalIndex.test_loc_scalarc              	   C   s   d|j d< | }d|j d< ttddd}tdg d	it|d
}t|| | }d|j d< tddddddtjgtjtjtjtjtjtjdgdt|d
}t|| d S )Nr*   r%   r1   )r0   r   aabbcadr   r'   r   )r*   r*   r+   r,   r-   r*   g      $@r   )r0   Cr+   r,   r-   )r   rB   )	r2   r6   r   r   r   r4   r5   r   nan)r;   r    df3bidx3	expected3df4r   r   r   ,test_loc_setitem_with_expansion_non_categoryL   s&   


zATestCategoricalIndex.test_loc_setitem_with_expansion_non_categoryc                 C   >   t jtdd |jd  W d    d S 1 sw   Y  d S )Nz^1$r.   r(   r7   r8   r9   r2   )r;   r    r   r   r   $test_loc_getitem_scalar_non_categoryh   s   "z9TestCategoricalIndex.test_loc_getitem_scalar_non_categoryc                 C   s<  t tg d}|d d d }tjg dtjd}t| | tdt	dd 
di}tj|jg d	d
|d< t dtddgddgdd}|jd }t|| tdt	dd
dit	dd
dd}tj|jg d	d
|d< |jdd }t|| t dtddgddgdd}|jd }t|| d S )Nr(   r+   r,   r-   )r-   r,   r+   r(   r   valued   r(   r   )r      2   K   rO   )binsD   r   rP   r1   r   r      r*   r   	      )r   r   r   arrayr   r4   assert_numpy_array_equal	__array__r   r   r3   pdcutrN   r   ilocassert_series_equalr5   r2   )r;   catreverseexpr    r>   r<   r   r   r   test_slicingl   s&   

z!TestCategoricalIndex.test_slicingc                 C   s  t g dg dd}tg d}g d}t||d|d}t dd	gg dd}td
dg}ddg}t||d|d}t||dd}	tddgddgdd
d}
d}|jddd d f }t|| t|d jsiJ |jdd d f }t	||
 t
|d tsJ |jd d df }t	||	 t|jsJ |jd }||ksJ |jd
dd d f }t|| t|d jsJ |jd
d d f }t	||
 t
|d tsJ |jd d df }t	||	 t|jsJ |jd }||ksJ |jd
|jd f }||ksJ |jd }||ksJ |jd }||ksJ |jdg }||d dk }t|| ||d dk }t|| |jd }||ksLJ |jd }t	||
 t
|d tsaJ |jtdd }t|| t|d jsyJ |jddg }t|| t|d jsJ |jd d df }t	||	 t|jsJ |jd d tddf }t|| t|d jsJ |jd d ddgf }t|| t|d jsJ d S )N)r%   cbre   re   re   re   r%   rf   re   
categorieshijklmn)r(   r+   r,   r-   r)   r      catsvaluesr   rf   re   rm   rn   r,   r-   rt   rV   ru   r:   )r   r   r   r+   r   )r+   r   )rm   rt   r(   )r   r   r   r   r_   r4   r5   r   r   r`   
isinstancestrr2   columnsiatatslice)r;   rt   idxru   r    cats2idx2values2exp_dfexp_colexp_rowexp_valres_dfres_rowres_colres_val	exp_fancy	res_fancyr   r   r   test_slicing_and_getting_ops   s   





z1TestCategoricalIndex.test_slicing_and_getting_opsc                 C   sL  t g dg dd}tg d}g d}t||d|d}|jdd	d d f }tt d
d
gg ddddgdddgd}t|| |jdd	d d f j}tddgddg}t|| |j	dddf }tt g dg ddg ddd}t|| |j	dd|j
dd f }tdt g dg ddig dd}t|| d S )N)r%   rf   rf   rf   re   re   re   rg   rh   rj   )r(   r+   r+   r+   r,   r-   r)   rs   r   r+   r-   rf   rm   rn   categoryr   rt   ru   rk   )r%   rf   rf   )rk   rl   rm   rV   r   r(   )r   r   r   r_   r4   r5   dtypesr   r`   r2   rx   )r;   rt   r|   ru   r    r<   r>   r   r   r   test_slicing_doc_examples   s<   z.TestCategoricalIndex.test_slicing_doc_examplesc                 C   s0   |j ddg }|jg d }tj||dd d S )Nre   r%   )r-   r   r(   r)   Tcheck_index_type)r2   r_   r4   r5   )r;   r    r<   r>   r   r   r    test_loc_getitem_listlike_labels$  s   z5TestCategoricalIndex.test_loc_getitem_listlike_labelsc                 C   sH   t jttdd |jg d  W d    d S 1 sw   Y  d S )N['e'] not in indexr.   r%   rf   er7   r8   r9   reescaper2   r;   r#   r   r   r   )test_loc_getitem_listlike_unused_category*  s   "z>TestCategoricalIndex.test_loc_getitem_listlike_unused_categoryc                 C   rI   )Nz^'e'$r.   r   rJ   r   r   r   r   &test_loc_getitem_label_unused_category0  s   "z;TestCategoricalIndex.test_loc_getitem_label_unused_categoryc                 C   sH   t jttdd |jddg  W d    d S 1 sw   Y  d S )Nz['d'] not in indexr.   r%   r0   r   r   r   r   r   test_loc_getitem_non_category5  s   "z2TestCategoricalIndex.test_loc_getitem_non_categoryc                 C   sZ   |  }d|jd< |jg d }ttdtddd}tdg d	i|d
}t|| d S )Nr*   r   r   aaabber"   r   )ri   r   r   )r   r(   r)   r+   r,   r*   r   )r6   r2   r   r   r   r4   r5   )r;   r#   r    r<   	exp_indexr>   r   r   r   0test_loc_setitem_expansion_label_unused_category:  s   
zETestCategoricalIndex.test_loc_setitem_expansion_label_unused_categoryc                 C   s  t g d}tg dg dd|d}|jddg }t ddg|jd}td	d
gddgd|d}tj||dd |jg d }t g d|jd}tg dg dd|d}tj||dd tjtt	
dd |jddg  W d    d S 1 szw   Y  d S )Nrg   r(   r+   r,   r-   r)   r   r   r   r   r%   rf   rh   r(   r+   r-   r)   Tr   r%   r%   rf   )r(   r(   r+   )r-   r-   r)   ['x'] not in indexr.   x)r   r   r2   ri   r4   r5   r7   r8   r9   r   r   )r;   r   r    resr   rc   r   r   r   test_loc_listlike_dtypesC  s   "z-TestCategoricalIndex.test_loc_listlike_dtypesc                 C   s   t g d}tg dg dd|d}|jddg }tg dg d	dt g d
d}tj||dd |jg d
 }tg dg ddt g dd}tj||dd tjtt	dd |jddg  W d    d S 1 spw   Y  d S )N)r%   rf   r%   r   r   r   r   r%   rf   r(   r,   r+   )r-   r   r)   r   Tr   r(   r,   r(   r,   r+   )r-   r   r-   r   r)   r%   r%   r%   r%   rf   r   r.   r   )
r   r   r2   r4   r5   r7   r8   r9   r   r   r;   r   r    r   rc   r   r   r   8test_loc_listlike_dtypes_duplicated_categories_and_codesZ  s    
"zMTestCategoricalIndex.test_loc_listlike_dtypes_duplicated_categories_and_codesc                 C   s  t g dtdd}tg dg dd|d}|jdd	g }tg d
g ddt g dtddd}tj||dd |jg d }tg dg ddt g dtddd}tj||dd tjtt	
dd |jddg  W d    d S 1 s|w   Y  d S )Nr%   rf   r%   re   abcderh   rL   r)   r   rr   rY   r   r   r%   rf   r   )r)   rr   r   r   Tr   r   )r)   rr   r)   rr   r   r   r   r.   r   )r   r   r   r2   r4   r5   r7   r8   r9   r   r   r   r   r   r   (test_loc_listlike_dtypes_unused_categoryq  s"   "z=TestCategoricalIndex.test_loc_listlike_dtypes_unused_categoryc                 C   s   t g dtdd}tg dg dd|d}tjtdd	 |jd  W d    n1 s.w   Y  tjttd
d	 |jddg  W d    d S 1 sPw   Y  d S )Nr   r   rh   rL   r   r   r   r   r.   r   r%   )	r   r   r   r7   r8   r9   r2   r   r   )r;   r   r    r   r   r   9test_loc_getitem_listlike_unused_category_raises_keyerror  s   "zNTestCategoricalIndex.test_loc_getitem_listlike_unused_category_raises_keyerrorc                 C   s\  t tjddtdtdd}| }t|j|_t|j|_t	|j
dd d f |jdd}t|j
dd d f | t	|j
d d df |jdd}t|j
d d df | ttdg d	d
}t |j
ddgd d f |j|d}t|j
ddgd d f | ttdg dd
}t |j
d d ddgf |j|d}t|j
d d ddgf | d S )Nr,   ABCXYZr   rx   r   rV   XABr   r   rB   rh   r   rx   r   XY)r   YZr   )r   r   randomrandnr   r6   r   r   rx   r   r2   r4   r`   r5   )r;   r    cdfexpectr   exp_columnsr   r   r   test_ix_categorical_index  s    """z.TestCategoricalIndex.test_ix_categorical_indexc                 C   sl  t tjddtdtdd}| }t|j|_t|j|_ttdddgd}t |j	dd d f |j|d	}t
|j	dd d f | ttd
ddgd}t |j	d d df |j|d}t
|j	d d df | t |j	ddgd d f |jttdd	}t
|j	ddgd d f | t |j	d d ddgf |jttdd}t
|j	d d ddgf | d S )Nr,   ABAXYXr   AAr   r   rh   r   XXr   r   AABXXY)r   r   r   r   r   r6   r   r   rx   r2   r4   r5   )r;   r    r   r   r   r   r   r   r   $test_ix_categorical_index_non_unique  s,    

"z9TestCategoricalIndex.test_ix_categorical_index_non_uniquec                 C   sl   d}t jt|d |jdd  W d    n1 sw   Y  |jdd }|jg d }t|| d S )NzRcannot do slice indexing on CategoricalIndex with these indexers \[1\] of type intr.   r(   r)   rf   re   )r+   r,   r-   )r7   r8   	TypeErrorr2   r_   r4   r5   )r;   r    msgr<   r>   r   r   r   test_loc_slice  s   z#TestCategoricalIndex.test_loc_slicec                 C   sz   t ddgddgddggtg dd}|d	 }|jd
 dks J |jd
 dks)J |jd dks2J |jd dks;J d S )Nr(   r+   r,   r-   r)   r   r   r   r   r   )r   r(   )r   r   r2   rz   )r;   r    sr   r   r   &test_loc_and_at_with_categorical_index  s   z;TestCategoricalIndex.test_loc_and_at_with_categorical_index
idx_valuesr   )rM   g      ?g      @      @)g      g      g      c                 c   "    | ]}t jg d |dV  qdS r   r   Nr   rZ   .0r   r   r   r   	<genexpr>       zTestCategoricalIndex.<genexpr>c                 c   r   )r   r   Nr   )r   dtypr   r   r   r     r   )r(   rf   r   r   r(   r-   r   rX   i  r+   r,   r0   rT   c                 c   r   r   )r]   rZ   r   r   r   r   r     r   )r(   r-   r   rX   z
2019-01-01)periods1d)startr   c                 C   s  t ||d}tdg di|d}t|d |d }|j|d  }tdgdg|d d}t|| |j|d d	  }tdd
g|d d	 dgd}t|| |j| }tdd
g|d d	 dgd}t|| | }d|j|d < tdg di|d}t|| | }ddg|j|d d	 df< tdg di|d}t|| | }ddg|j|df< tdg di|d}t|| d S )N)orderedr   )foobarbazr   r   r(   r   rV   r+   r   r   qux)r   r   r   qux2)r   r   r   )	r   r   r{   r2   r   r4   r`   r5   r6   )r;   r   r   cat_idxr    slr<   r>   r   r   r   +test_loc_getitem_with_non_string_categories  s0   
z@TestCategoricalIndex.test_loc_getitem_with_non_string_categoriesc                 C   s   t ddtjg}ttd|d}|tj dksJ |jtj dks#J t|}|jtjdf dks3J |jtj d dks?J d S )Nr   r   r,   r   r+   r   )r   r   rC   r   ranger2   r   )r;   ciserr    r   r   r   !test_getitem_categorical_with_nan!  s   z6TestCategoricalIndex.test_getitem_categorical_with_nanN)*__name__
__module____qualname__r@   rH   rK   rd   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r7   markparametrizer4   ALL_INT_NUMPY_DTYPESFLOAT_NUMPY_DTYPESr   rZ   r:   r   r
   r	   ALL_INT_EA_DTYPESr]   IntervalIndexfrom_breaks
date_rangetimedelta_ranger   r   r   r   r   r   r$   +   sd     y&		 
'r$   )r   numpyr   r7   pandas.core.dtypes.commonr   pandasr]   r   r   r   r   r   r   r	   r
   pandas._testing_testingr4   pandas.api.typesr   r   fixturer    r#   r$   r   r   r   r   <module>   s    (

	
	