
    PiBM                         d dl Z d dlZd dlZd dlmZ d dlmZmZm	Z	m
Z
mZmZ d dlmZ d dlmZ  G d d          Z G d d          Z G d	 d
          ZdS )    N)Pandas4Warning)CategoricalCategoricalIndex	DataFrameIndexSeriesStringDtype)recode_for_categoriesc                      e Zd Zd Zd Zd Zej                            dg dddgg          d             Z	d	 Z
d
 Zd Zej                            ddgg dg dg          d             Zd Zd Zd Zd Zej                            dg dddgddgfg dddgddgfg dddgddgfg dddgddgfg dddgddgfg dddgddgfg dddgddgfg dddgddgfg dddgdgfg dddgdgfg dddgdgfg dddgdgfg dddgddgfg          d             Zd Zd Zd Zej                            d d!gd!ej        gd!d!d!gg          d"             Zd# Zd$S )%TestCategoricalAPIc                    t          t          d          d          }t          j        |j        t          g d                     |j        rJ t          t          d          t          d          d          }t          j        |j        t          g d                     |j        rJ t          t          d          d          }t          j        |j        t          g d                     |j        sJ t          t          d          t          d          d          }t          j        |j        t          g d                     |j        sJ d S )	NacbForderedabcbca
categoriesr   )r   r   r   T)r   listtmassert_index_equalr   r   r   )selfcat1cat2cat3cat4s        |/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/pandas/tests/arrays/categorical/test_api.pytest_ordered_apiz#TestCategoricalAPI.test_ordered_api   s2   4;;666
dou___/E/EFFF<4;;4;;NNN
dou___/E/EFFF<4;;555
dou___/E/EFFF||4;;4;;MMM
dou___/E/EFFF||    c                    t          g dd          }|                                }|j        rJ |                                }|j        sJ |                    d          j        sJ |                    d          j        rJ d}t          j        t          |          5  d|_        d d d            n# 1 swxY w Y   t          j        t          |          5  d|_        d d d            d S # 1 swxY w Y   d S )Nr   r   r   r   Tr   Fz8property 'ordered' of 'Categorical' object has no settermatch)r   as_unorderedr   
as_orderedset_orderedpytestraisesAttributeError)r   catr   msgs       r    test_set_orderedz#TestCategoricalAPI.test_set_ordered'   s   ...===!!<~~||%%----##E**2222 I]>555 	 	CK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]>555 	  	 CK	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s$   #B77B;>B;C22C69C6c                    t          g d          }|                    g d          }t          j        |                                t          j        g dt
          j                             t          j        |j	        t          g d                     t          j        g dt
          j                  }t          j        |                                |           t          g d          }t          j        |j	        |           |                    d           }t          g d          }t          j        ||           d S )Nr$            )r2   r3   r4   r2   dtyper   c                 *    |                                  S )N)upper)xs    r    <lambda>z;TestCategoricalAPI.test_rename_categories.<locals>.<lambda>I   s     r"   )ABCr;   )r   rename_categoriesr   assert_numpy_array_equal	__array__nparrayint64r   r   r   object_assert_categorical_equal)r   r-   resexp_catresultexpecteds         r    test_rename_categoriesz)TestCategoricalAPI.test_rename_categories8   s-   ...// ##III..
#MMOORXlll"(CCC	
 	
 	
 	cneIII.>.>???(///rzBBB
#CMMOOW===((
cng666 &&':':;;33344
#FH55555r"   new_categoriesr2   r3   r4      r2   r3   c                     t          g d          }d}t          j        t          |          5  |                    |           d d d            d S # 1 swxY w Y   d S )Nr$   zKnew categories need to have the same number of items as the old categories!r%   )r   r*   r+   
ValueErrorr>   r   rK   r-   r.   s       r    *test_rename_categories_wrong_length_raisesz=TestCategoricalAPI.test_rename_categories_wrong_length_raisesM   s    ...// 	 ]:S111 	2 	2!!.111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s   AAAc                     t          ddg          }|                    t          ddgddg                    }t          ddg          }t          j        ||           d S )Nr   r   r   r2   index)r   r>   r   r   rE   )r   r   rH   rI   s       r    test_rename_categories_seriesz0TestCategoricalAPI.test_rename_categories_seriesW   se    c
##$$VQF3*%E%E%EFF1v&&
#FH55555r"   c           	         t          g d          }|                    ddddd          }t          g d          }t          j        |j        |           t          g d          }|                    ddd          }t          g d          }t          j        |j        |           t          g d          }|                    ddddd	d
d          }t          g d          }t          j        |j        |           t          g d          }|                    ddd          }t          g d          }t          j        |j        |           d S )Nr   r   r   drM   r4   r3   r2   rM   r4   r3   r2   )r   r   )r2   r   r4   rX         )r   r   r   rX   efrL   )r]   g)r   r>   r   r   r   r   )r   r-   rF   rI   s       r    test_rename_categories_dictz.TestCategoricalAPI.test_rename_categories_dict^   su   ...//##!!!!$D$DEE&&
cnh777 ...//##!!$4$455)))**
cnh777 ...//##!!!!!RS$T$TUU&&
cnh777 ...//##!!$4$455---..
cnh77777r"   c                    t          g dd          }|                                }t          g dg dd          }|                    g d          }t          j        ||           t          j        ||           d S )Nr$   Tr   r   r   r   r   )r   copyreorder_categoriesr   rE   r   r-   oldnewrF   s        r    test_reorder_categoriesz*TestCategoricalAPI.test_reorder_categoriesy   s    ...===hhjj   ___d
 
 
 $$___55
#C---
#C-----r"   r   r   r   rX   rW   c                     t          g dd          }d}t          j        t          |          5  |                    |           d d d            d S # 1 swxY w Y   d S )Nr$   Tr   z=items in new_categories are not the same as in old categoriesr%   )r   r*   r+   rO   rc   rP   s       r    test_reorder_categories_raisesz1TestCategoricalAPI.test_reorder_categories_raises   s     ...===M]:S111 	3 	3"">222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3s   AAAc                    t          g dd          }|                                }t          g dg dd          }|                    d          }t          j        ||           t          j        ||           |                    dg          }t          j        ||           t          j        ||           t          t          d          d          }t          t          d          t          d          d          }|                    t          dd	g                    }t          j        ||           |                    t          j        dd	g                    }t          j        ||           |                    t          dd	g                    }t          j        ||           |                    dd	g          }t          j        ||           d S )
Nr$   Tr   rW   r   rX   abcabcder\   )
r   rb   add_categoriesr   rE   r   r   rA   rB   r   )r   r-   re   rf   rF   rI   s         r    test_add_categoriesz&TestCategoricalAPI.test_add_categories   s   ...===hhjj   -A-A-A4
 
 
   %%
#C---
#C---  #''
#C---
#C--- $u++t444tE{{tG}}dSSS  c
!3!344
#C222  3*!5!566
#C222  Sz!2!233
#C222  #s,,
#C22222r"   c                     t          g dd          }t          j        d          }t          j        t
          |          5  |                    dg           d d d            d S # 1 swxY w Y   d S )NrW   Tr   z5new categories must not include old categories: {'d'}r%   rX   )r   reescaper*   r+   rO   rn   )r   r-   r.   s      r    #test_add_categories_existing_raisesz6TestCategoricalAPI.test_add_categories_existing_raises   s    ...===iOPP]:S111 	& 	&u%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s   A''A+.A+c                    t          t          ddgd                    }t          dgd          }|                    |          }t          t          ddgd          t          g dd                    }t          j        ||           t          t          g dt                                          }t          d	gt                                }|                    |          }t          t          g dt                                t          g d
t                                          }t          j        ||           d S )Nr2   r3   Int64r5   rM   )r2   r3   rM   r   r   r   r   rX   rh   )r   r   rn   r   rE   r	   )r   r-   serrH   rI   s        r    ,test_add_categories_losing_dtype_informationz?TestCategoricalAPI.test_add_categories_losing_dtype_information   sC   &!Qw77788aS(((##C((Aq6)))fYYYg6V6V6V
 
 
 	#FH555&FFFGGcU+--000##C((???+--888ooo[]]CCC
 
 
 	#FH55555r"   c                 R	   t          g dd          }t          g d          }t          j        g dt          j                  }|                    g d          }|                    g d          }t          j        |j        |           t          j	        |
                                |           t          g d          }t          j        |j        |           t          j	        |
                                |           t          g dd          }|                    dg          }t          j	        |j        t          j        g dt          j                             |                    g d	          }t          j	        |j        t          j        g d
t          j                             t          j        |j        t          g d	                     |                    g d          }t          g d          }t          j        |j        |           t          g dg dd          }t          j	        |j        t          j        g dt          j                             t          j        |j        t          g d                     t          j        g dt          j                  }t          j	        t          j        |          |           |                    g d          }t          j	        |j        t          j        g dt          j                             t          j        |j        t          g d                     t          j        g dt          j                  }t          j	        t          j        |          |           |                                dk    sJ |                                dk    sJ |                    g dd          }|j        rJ t          j	        t          j        |          t          j        |                     |                    d                              g d          }|j        rJ t          j	        t          j        |          t          j        |                     d S )Nr$   Tr   ra   r5   r   r   )r   r{   r   rh   )r   r2   r{   r   rW   )r2   r3   r4   rM   r2   rL   r   )r   r2   r3   r4   r   rY   )r4   r3   r2   r   r4   rM   r2   F)r   r   rA   rB   rD   set_categoriesr   r   r   r?   r@   codesint8_codesrC   asarrayminmaxr   r)   )	r   r-   exp_categories
exp_valuesrF   exp_categories_backr   expc2s	            r    test_set_categoriesz&TestCategoricalAPI.test_set_categories   s   ...===//X222"*EEE
  11  11
cnn===
#CMMOOZ@@@#OOO44
cn.ABBB
#CMMOOZ@@@ ...===  #''
#CIrxbg/V/V/VWWW   11
#CIrxRW/U/U/UVVV
cneOOO.D.DEEE   !5!5!56633344
cnn=== LLL$OOO
#AHbhbg.V.V.VWWW
alE,,,,?,?@@@hbh777
#BJqMM3777 \\\** 	#AHbhbg.V.V.VWWW 	alE,,,,?,?@@@ hbh777
#BJqMM3777uuww!||||uuww!|||| lllE:::~
#BJqMM2:b>>BBB ]]5!!00>>:~
#BJqMM2:b>>BBBBBr"   z"values, categories, new_categoriesrw   r   )r   r   r   r   )r   r   r   rX   r\   c                    d}t          |                              |          rt          nd }t          j        ||          5  t          ||          }d d d            n# 1 swxY w Y   t          |                              |          rt          nd }t          j        ||          5  t          |||          }	d d d            n# 1 swxY w Y   |                    ||          }
t          j        |
|	           d S )Nz=Constructing a Categorical with a dtype and values containingr%   r   )set
differencer   r   assert_produces_warningr   r|   rE   )r   valuesr   rK   r   r.   warn1r   warn2rI   rH   s              r    test_set_categories_manyz+TestCategoricalAPI.test_set_categories_many  s   4 N"%f++"8"8"D"DN$'S999 	0 	0FJ//A	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 #&f++"8"8"H"HRd'S999 	D 	D"6>7CCH	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D !!.'!BB
#FH55555s$   A!!A%(A%-CCCc                     t          ddg          }|                    dgd          }t          dt          j        g          }t	          j        ||           d S )Nr;   r<   T)rename)r   r|   rA   nanr   rE   )r   r-   rH   rI   s       r    test_set_categories_rename_lessz2TestCategoricalAPI.test_set_categories_rename_less3  sY    3*%%##SE$#77RV}--
#FH55555r"   c                    t          g dg d          }|                    g d           t          g dt          d                    }t          j        ||           t          g dg d          }|                    g dd           t          g dt          d                    }t          j        ||           d S )	Nr   rW   rv   )r   r   rX   r\   )r   r   rX   acdeT)fastpath)r   _set_categoriesr   r   rE   )r   r-   rI   s      r    test_set_categories_privatez.TestCategoricalAPI.test_set_categories_private:  s    ///6J6J6JKKK0001114<<HHH
#C222 ///6J6J6JKKK0004@@@4<<HHH
#C22222r"   c                    t          g dd          }|                                }t          ddt          j        dgddgd          }|                    d          }t          j        ||           t          j        ||           |                    dg          }t          j        ||           t          j        ||           d S )Nr$   Tr   r   r   r   r   )r   rb   rA   r   remove_categoriesr   rE   rd   s        r    test_remove_categoriesz)TestCategoricalAPI.test_remove_categoriesF  s    ...===hhjj3RVS1sCjRVWWW##C((
#C---
#C---##SE**
#C---
#C-----r"   removalsr   c                     t          g d          }t          j        d          }t          j        t
          |          5  |                    |           d d d            d S # 1 swxY w Y   d S )Nrw   z-removals must all be in old categories: {'c'}r%   )r   rq   rr   r*   r+   rO   r   )r   r   r-   messages       r    test_remove_categories_raisesz0TestCategoricalAPI.test_remove_categories_raisesS  s    ///**)KLL]:W555 	, 	,!!(+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s   A$$A(+A(c           	      X   t          g dg d          }t          g d          }t          g d          }t          j        |j        |           |                                }t          j        |j        |           t          j        |j        |           t          dddt          j        gg d          }|                                }t          j        |j        t          t          j        g d                               t          j        g d	t          j	        
          }t          j
        |j        |           t          j        |j        |           dt          j        ddddt          j        g}t          |t          d                    }|                                }t          j        |j        t          g d                     t          j        g dt          j	        
          }t          j
        |j        |           |                                |k    sJ t          d          }	t          j                            d                              |	d d d         d                              d          }t          j        |t          j                            d                              t%          |          d          <   t          ||	          }|                                }|                                |                                k    sJ d S )N)r   r   r   rX   r   )r   r   r   rX   r\   rv   rW   r   r   r   r   )r   r2   r3   r{   r5   FDr<   ABCDEFG)r   r   )r<   r   r   )r3   r{   r2   r   r2   r3   r{   abcdefghijklmnopqrstuvwxyzr3   i'  objectd   )r   r   r   r   r   remove_unused_categoriesrA   r   rB   r~   r?   r}   r   tolistrandomdefault_rngchoiceastypelen)
r   r   exp_categories_allexp_categories_droppedrF   	exp_codesvalr-   outalphas
             r    test_remove_unused_categoriesz0TestCategoricalAPI.test_remove_unused_categories[  s   111>W>W>WXXX"#<#<#<==!&';';';!<!<
al,>???((**
cn.DEEE
al,>??? c3/<U<U<UVVV((**
cneBH___4M4M.N.NOOOH]]]"':::	
#CIy999
al,>???BFCc37iAAA**,,
cneOOO.D.DEEEH444BGDDD	
#CIy999zz||s""""122i##A&&--eCCaCj%@@GGQQ>@fBI!!!$$++CHHc::;777**,,zz||szz||++++++r"   N)__name__
__module____qualname__r!   r/   rJ   r*   markparametrizerQ   rU   r_   rg   rj   ro   rs   ry   r   r   r   r   r   rA   r   r   r    r"   r    r   r      s         $     "6 6 6* [-q!f/EFF2 2 GF26 6 68 8 86. . . [EOO   	
 3 3 33 3 38& & &6 6 6&@C @C @CD [, __sCj3*5__sCj3*5__sCj3*5__sCj3*5__sCj3*5__sCj3*5__sCj3*5__sCj3*5__sCj3%0__sCj3%0__sCj3%0__sCj3%0__sCj3*5)	
 26 63 266 6 6
3 
3 
3. . . [Z3%#rvc3Z)PQQ, , RQ,!, !, !, !, !,r"   r   c                       e Zd Zd ZdS )TestCategoricalAPIWithFactorc                    t          g dd          }|                                }|j        sJ t          g dd|j                  }t	          g dg dd	|
          }t          j        ||           |                                }|                    g d          }|                                }t          t          d          |j        d          }t	          g dg dd	|
          }t          j        ||           t          g d          }|                                }t          g d|j        d          }t	          g dg dd	|
          }t          j        ||           t          t          j        dddg          }|                                }t	          g dg dd	t          ddt          j        gddgd          
          }t          j        ||           d S )N)r   r   r   r   r   r   r   r   Tr   r   r   )namer   )r4   r3   r4   )      ?      ?r   )countsfreqsrS   rW   abcd)r   r   )r4   r3   r4   r   )r   r   r   r   )r2   r3   r4   r2   r3   r4   r4   r3   r2   r2   r2   r1   )rZ   r4   r4   )g]tE?tE]t?r   r2   r3   )r2   r3   r2   )r   g      ?r   )r   r   )r   describer   r   r   r   assert_frame_equalrb   r|   r   rA   r   )r   factordesc	exp_indexrI   r-   s         r    test_describez*TestCategoricalAPIWithFactor.test_describe  sH   EEEtTTT  ~~$OO,
 
 
	  yy+F+F+FGGy
 
 
 	dH--- kkmm  !5!5!566||~~$LL&.|
 
 
	 #||.L.L.LMM
 
 
 	dH--- ;;;<<||~~$YYY,WWW	 yy+I+I+IJJ
 
 
 	dH--- 261a+,,||~~ yy+F+F+FGG"ArvAq6  
 
 
 	dH-----r"   N)r   r   r   r   r   r"   r    r   r     s#        /. /. /. /. /.r"   r   c                      e Zd Zd Zej                            dddgddgddgddgfddgddgddgddgfddgddgddgddgfddgddgddgddgfg dddgg dg dfg d	g dddgg d
fg dg dg dg dfg dg ddgg dfg dg ddgg dfg dg dg g dfddgg ddgddgfddgddgddgddgfg          d             Zd ZdS )TestPrivateCategoricalAPIc                    t          ddddt          j        g          }t          j        g dd          }t	          j        |j        |           d}t          j        t          |          5  t          j        g d	d          |_        d d d            n# 1 swxY w Y   |j        }t          j        t          d
          5  d|d<   d d d            n# 1 swxY w Y   d|d<   t          j        g dd          }t	          j        |j        |           d|j        d<   t          j        g dd          }t	          j        |j        |           d S )Nr   r   r   )r   r2   r3   r   r{   r~   r5   z6property 'codes' of 'Categorical' object has no setterr%   )r   r2   r3   r   r2   z#assignment destination is read-onlyr2   rM   )r   r2   r3   r   r   r3   )r   r2   r3   r   r3   )r   rA   r   rB   r   r?   r}   r*   r+   r,   rO   r   )r   r   r   r.   r}   s        r    test_codes_immutablez.TestPrivateCategoricalAPI.test_codes_immutable  s   c3RV455h'''v666
#AGS111 G]>555 	> 	>hf===AG	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> ]:-RSSS 	 	E!H	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 !hf555
#AGS111hf555
#AGS11111s$   .BBBCCCzcodes, old, new, expectedr   r2   r   r   )r   r2   r   r2   r   )r   r2   r3   r3   )r   r2   r{   r{   )r   r2   r{   )r{   r   r{   rX   )r{   r{   r{   r{   c                    t          j        |t           j                  }t          j        |t           j                  }t          |          }t          |          }t	          |||d          }t          j        ||           d S )Nr5   Trb   )rA   
asanyarrayr~   r   r
   r   r?   )r   r}   re   rf   rI   rH   s         r    test_recode_to_categoriesz3TestPrivateCategoricalAPI.test_recode_to_categories  su    $ e27333=999CjjCjj&uc3TBBB
#FH55555r"   c                    d}t          j        |          }t          |          }t          j        |dz
  ddt           j                  }t          |          }t	          |||d          }t          j        ||           d S )Ni  r2   r{   r5   Tr   )rA   aranger   int16r
   r   r?   )r   Nr}   re   rI   rf   rH   s          r    test_recode_to_categories_largez9TestPrivateCategoricalAPI.test_recode_to_categories_large  sw    	!Ell9QUB"(;;;Hoo&uc3TBBB
#FH55555r"   N)	r   r   r   r   r*   r   r   r   r   r   r"   r    r   r     s       2 2 24 [#Vc3Z#saV4Vc3Z#saV4Vc3Z#saV4Vc3Z#saV4\\C:E\\???S#JGZZ///:::FZZ3%=ZZ3%>ZZ"lll;"XrC:Bx0Vc3Z#saV4	
 "6 6# "66 6 6 6 6r"   r   )rq   numpyrA   r*   pandas.errorsr   pandasr   r   r   r   r   r	   pandas._testing_testingr   pandas.core.arrays.categoricalr
   r   r   r   r   r"   r    <module>r      s7   				      ( ( ( ( ( (                      @ @ @ @ @ @h, h, h, h, h, h, h, h,V0. 0. 0. 0. 0. 0. 0. 0.f;6 ;6 ;6 ;6 ;6 ;6 ;6 ;6 ;6 ;6r"   