
    EgM                         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)PY311)CategoricalCategoricalIndex	DataFrameIndexSeriesStringDtype)recode_for_categoriesc                      e Zd 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          ej        	                    ddd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          }d}t          j        t          |          5  |                                 d d d            d S # 1 swxY w Y   d S )NacbForderedz5Categorical.to_list is deprecated and will be removedmatch)r   listtmassert_produces_warningFutureWarningto_list)selfcat1msgs      ]/var/www/sysmax/venv/lib/python3.11/site-packages/pandas/tests/arrays/categorical/test_api.pytest_to_list_deprecatedz*TestCategoricalAPI.test_to_list_deprecated   s    4;;666E'SAAA 	 	LLNNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AA"%A"c                    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 )	Nr   Fr   abcbca
categoriesr   )r    r!   r   T)r   r   r   assert_index_equalr$   r   r   )r   r   cat2cat3cat4s        r   test_ordered_apiz#TestCategoricalAPI.test_ordered_api   s4   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 t
          rdn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can't set attributer   )	r   as_unorderedr   
as_orderedset_orderedr   pytestraisesAttributeError)r   catr&   r   s       r   test_set_orderedz#TestCategoricalAPI.test_set_ordered.   s   ...===!!<~~|%%----##E**2222
 'FF& 	
 ]>555 	 	CK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]>555 	  	 CK	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s$   ,C  CC&C;;C?C?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,            )r8   r9   r:   r8   dtyper   c                 *    |                                  S )N)upper)xs    r   <lambda>z;TestCategoricalAPI.test_rename_categories.<locals>.<lambda>T   s     r*   )ABCrA   )r   rename_categoriesr   assert_numpy_array_equal	__array__nparrayint64r%   r$   r   object_assert_categorical_equal)r   r4   resexp_catresultexpecteds         r   test_rename_categoriesz)TestCategoricalAPI.test_rename_categoriesC   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r8   r9   r:      r8   r9   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   r1   r2   
ValueErrorrD   r   rQ   r4   r   s       r   *test_rename_categories_wrong_length_raisesz=TestCategoricalAPI.test_rename_categories_wrong_length_raisesX   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   r8   index)r   rD   r   r   rK   )r   r!   rN   rO   s       r   test_rename_categories_seriesz0TestCategoricalAPI.test_rename_categories_seriesb   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!   drS   r:   r9   r8   rS   r:   r9   r8   )r   r!   )r8   r    r:   r^         )r   r    r!   r^   efrR   )rc   g)r   rD   r   r   r%   r$   )r   r4   rL   rO   s       r   test_rename_categories_dictz.TestCategoricalAPI.test_rename_categories_dicti   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   rK   r   r4   oldnewrL   s        r   test_reorder_categoriesz*TestCategoricalAPI.test_reorder_categories   s    ...===hhjj   ___d
 
 
 $$___55
#C---
#C-----r*   r   r   r    r^   r]   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   r1   r2   rU   ri   rV   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   r]   r#   r^   abcabcderb   )
r   rh   add_categoriesr   rK   r   r   rG   rH   r   )r   r4   rk   rl   rL   rO   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 )Nr]   Tr   z5new categories must not include old categories: {'d'}r   r^   )r   reescaper1   r2   rU   rt   )r   r4   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 )Nr8   r9   Int64r;   rS   )r8   r9   rS   r$   r   r    r   r^   rn   )r   r   rt   r   rK   r	   )r   r4   serrN   rO   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   rg   r;   r   r   )r   r   r   rn   )r   r8   r   r   r]   )r8   r9   r:   rS   r8   rR   r#   )r   r8   r9   r:   r   r_   )r:   r9   r8   r   r:   rS   r8   F)r   r   rG   rH   rJ   set_categoriesr   r%   r$   rE   rF   codesint8_codesrI   asarrayminmaxr   r0   )	r   r4   exp_categories
exp_valuesrL   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_categoriesr}   r    )r    r   r   r   )r    r   r!   r^   rb   r   TFc                     t          ||          }t          |||          }|                    ||          }t          j        ||           d S )Nr   )r   r   r   rK   )r   valuesr$   rQ   r   r!   rO   rN   s           r   test_set_categories_manyz+TestCategoricalAPI.test_set_categories_many  sU    6 
++v~w??!!.'!BB
#FH55555r*   c                     t          ddg          }|                    dgd          }t          dt          j        g          }t	          j        ||           d S )NrA   rB   T)rename)r   r   rG   nanr   rK   )r   r4   rN   rO   s       r   test_set_categories_rename_lessz2TestCategoricalAPI.test_set_categories_rename_less7  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   r]   r|   )r   r!   r^   rb   )r   r!   r^   acdeT)fastpath)r   _set_categoriesr   r   rK   )r   r4   rO   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   rh   rG   r   remove_categoriesr   rK   rj   s        r   test_remove_categoriesz)TestCategoricalAPI.test_remove_categoriesJ  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 )Nr}   z-removals must all be in old categories: {'c'}r   )r   rw   rx   r1   r2   rU   r   )r   r   r4   messages       r   test_remove_categories_raisesz0TestCategoricalAPI.test_remove_categories_raisesW  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!   r^   r   )r   r    r!   r^   rb   r|   r]   r   r    r!   r   )r   r8   r9   r   r;   FDrB   ABCDEFG)r   r$   )rB   r   r   )r9   r   r8   r   r8   r9   r   abcdefghijklmnopqrstuvwxyzr9   i'  objectd   )r   r   r   r%   r$   remove_unused_categoriesrG   r   rH   r   rE   r   r   tolistrandomdefault_rngchoiceastypelen)
r   r!   exp_categories_allexp_categories_droppedrL   	exp_codesvalr4   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)   r5   rP   r1   markparametrizerW   r[   re   rm   rp   ru   ry   r   r   r   r   r   r   rG   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 [Yu666 6 763 4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   )r:   r9   r:   )      ?      ?r   )countsfreqsrY   r]   abcd)r   r   )r:   r9   r:   r   )r   r   r   r   )r8   r9   r:   r8   r9   r:   r:   r9   r8   r8   r8   r7   )r`   r:   r:   )g]tE?tE]t?r   r8   r9   )r8   r9   r8   )r   g      ?r   )r$   r   )r   describer   r   r   r   assert_frame_equalrh   r   r   rG   r   )r   factordesc	exp_indexrO   r4   s         r   test_describez*TestCategoricalAPIWithFactor.test_describe  sI   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        |           t          rdn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   r8   r9   r   r   r   r;   z6property 'codes' of 'Categorical' object has no setterr-   r   )r   r8   r9   r   r8   z#assignment destination is read-onlyr8   rS   )r   r8   r9   r   r   r9   )r   r8   r9   r   r9   )r   rG   r   rH   r   rE   r   r   r1   r2   r3   rU   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
 'DD& 	
 ]>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$   7B!!B%(B%C  C$'C$zcodes, old, new, expectedr   r8   r   r    )r   r8   r   r8   r   )r   r8   r9   r9   )r   r8   r   r   )r   r8   r   )r   r   r   r^   )r   r   r   r   c                    t          j        |t           j                  }t          j        |t           j                  }t          |          }t          |          }t	          |||          }t          j        ||           d S )Nr;   )rG   
asanyarrayr   r   r
   r   rE   )r   r   rk   rl   rO   rN   s         r   test_recode_to_categoriesz3TestPrivateCategoricalAPI.test_recode_to_categories  sp    $ e27333=999CjjCjj&uc377
#FH55555r*   c                    d}t          j        |          }t          |          }t          j        |dz
  ddt           j                  }t          |          }t	          |||          }t          j        ||           d S )Ni  r8   r   r;   )rG   aranger   int16r
   r   rE   )r   Nr   rk   rO   rl   rN   s          r   test_recode_to_categories_largez9TestPrivateCategoricalAPI.test_recode_to_categories_large  sr    	!Ell9QUB"(;;;Hoo&uc377
#FH55555r*   N)	r   r   r   r   r1   r   r   r   r   r   r*   r   r   r     s       2 2 2< [#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   )rw   numpyrG   r1   pandas.compatr   pandasr   r   r   r   r   r	   pandas._testing_testingr   pandas.core.arrays.categoricalr
   r   r   r   r   r*   r   <module>r      s7   				                                 @ @ @ @ @ @l, l, l, l, l, l, l, l,^0. 0. 0. 0. 0. 0. 0. 0.f?6 ?6 ?6 ?6 ?6 ?6 ?6 ?6 ?6 ?6r*   