
    MhM                         S SK r S SKrS SKrS SKJr  S SKJrJrJ	r	J
r
JrJr  S SKJr  S SKJr   " S S5      r " S S5      r " S	 S
5      rg)    N)PY311)CategoricalCategoricalIndex	DataFrameIndexSeriesStringDtype)recode_for_categoriesc                      \ rS rSrS rS rS rS r\R                  R                  S/ SQSS	//5      S
 5       rS rS rS r\R                  R                  SS// SQ/ SQ/5      S 5       rS rS rS rS r\R                  R                  S/ SQSS/SS/4/ SQSS/SS/4/ SQSS/SS/4/ SQSS/SS/4/ SQSS/SS/4/ SQSS/SS/4/ SQSS/SS/4/ SQSS/SS/4/ SQSS/S/4/ SQSS/S/4/ SQSS/S/4/ SQSS/S/4/ SQSS/SS/4/5      \R                  R                  SSS /5      S! 5       5       rS" rS# rS$ r\R                  R                  S%S&/S&\R2                  /S&S&S&//5      S' 5       rS( rS)rg*)+TestCategoricalAPI   c                     [        [        S5      SS9nSn[        R                  " [        US9   UR                  5         S S S 5        g ! , (       d  f       g = f)NacbForderedz5Categorical.to_list is deprecated and will be removedmatch)r   listtmassert_produces_warningFutureWarningto_list)selfcat1msgs      Z/var/www/html/env/lib/python3.13/site-packages/pandas/tests/arrays/categorical/test_api.pytest_to_list_deprecated*TestCategoricalAPI.test_to_list_deprecated   s=    4;6E''SALLN BAAs   A		
Ac                    [        [        S5      SS9n[        R                  " UR                  [        / SQ5      5        UR                  (       a   e[        [        S5      [        S5      SS9n[        R                  " UR                  [        / SQ5      5        UR                  (       a   e[        [        S5      SS9n[        R                  " UR                  [        / SQ5      5        UR                  (       d   e[        [        S5      [        S5      SS9n[        R                  " UR                  [        / SQ5      5        UR                  (       d   eg )	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_api#TestCategoricalAPI.test_ordered_api   s    4;6
doou_/EF<<4;4;N
doou_/EF<<4;5
doou_/EF|||4;4;M
doou_/EF|||    c                 6   [        / SQSS9nUR                  5       nUR                  (       a   eUR                  5       nUR                  (       d   eUR	                  S5      R                  (       d   eUR	                  S5      R                  (       a   e[
        (       a  SOSn[        R                  " [        US9   SUl        S S S 5        [        R                  " [        US9   SUl        S S S 5        g ! , (       d  f       N8= f! , (       d  f       g = f)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_ordered#TestCategoricalAPI.test_set_ordered.   s    .=!<<~~|||%----##E*2222
 u G& 	
 ]]>5CK 6]]>5CK 65 6555s   ?C9(D
9
D

Dc                    [        / SQ5      nUR                  / SQ5      n[        R                  " UR	                  5       [
        R                  " / SQ[
        R                  S95        [        R                  " UR                  [        / SQ5      5        [
        R                  " / SQ[
        R                  S9n[        R                  " UR	                  5       U5        [        / SQ5      n[        R                  " UR                  U5        UR                  S 5      n[        / SQ5      n[        R                  " XE5        g )Nr/            )r<   r=   r>   r<   dtyper    c                 "    U R                  5       $ )N)upper)xs    r   <lambda>;TestCategoricalAPI.test_rename_categories.<locals>.<lambda>T   s
    r-   )ABCrF   )r   rename_categoriesr   assert_numpy_array_equal	__array__nparrayint64r'   r&   r   object_assert_categorical_equal)r   r7   resexp_catresultexpecteds         r   test_rename_categories)TestCategoricalAPI.test_rename_categoriesC   s    ./ ##I.
##MMORXXl"((C	
 	cnneI.>?((/rzzB
##CMMOW=(
cnng6 &&':;34
##F5r-   new_categoriesr<   r=   r>      r<   r=   c                     [        / SQ5      nSn[        R                  " [        US9   UR	                  U5        S S S 5        g ! , (       d  f       g = f)Nr/   zKnew categories need to have the same number of items as the old categories!r   )r   r4   r5   
ValueErrorrI   r   rW   r7   r   s       r   *test_rename_categories_wrong_length_raises=TestCategoricalAPI.test_rename_categories_wrong_length_raisesX   sA    ./ 	 ]]:S1!!.1 211s   A
Ac                     [        SS/5      nUR                  [        SS/SS/S95      n[        SS/5      n[        R                  " X#5        g )Nr!   r"   r   r<   index)r   rI   r   r   rP   )r   r#   rS   rT   s       r   test_rename_categories_series0TestCategoricalAPI.test_rename_categories_seriesb   sK    c
#$$VQF3*%EF1v&
##F5r-   c           	         [        / SQ5      nUR                  SSSSS.5      n[        / SQ5      n[        R                  " UR
                  U5        [        / SQ5      nUR                  SSS.5      n[        / SQ5      n[        R                  " UR
                  U5        [        / SQ5      nUR                  SSSSS	S
S.5      n[        / SQ5      n[        R                  " UR
                  U5        [        / SQ5      nUR                  SSS.5      n[        / SQ5      n[        R                  " UR
                  U5        g )Nr!   r"   r#   drY   r>   r=   r<   rY   r>   r=   r<   )r!   r#   )r<   r"   r>   rf         )r!   r"   r#   rf   efrX   )rk   g)r   rI   r   r   r'   r&   )r   r7   rQ   rT   s       r   test_rename_categories_dict.TestCategoricalAPI.test_rename_categories_dicti   s   ./##!!!!$DE&
cnnh7 ./##!!$45)*
cnnh7 ./##!!!!!RS$TU&
cnnh7 ./##!!$45-.
cnnh7r-   c                     [        / SQSS9nUR                  5       n[        / SQ/ SQSS9nUR                  / SQ5      n[        R                  " X5        [        R                  " XC5        g )Nr/   Tr   r#   r"   r!   r%   )r   copyreorder_categoriesr   rP   r   r7   oldnewrQ   s        r   test_reorder_categories*TestCategoricalAPI.test_reorder_categories   sY    .=hhj _d
 $$_5
##C-
##C-r-   r!   r!   r"   rf   re   c                     [        / SQSS9nSn[        R                  " [        US9   UR	                  U5        S S S 5        g ! , (       d  f       g = f)Nr/   Tr   z=items in new_categories are not the same as in old categoriesr   )r   r4   r5   r[   rr   r\   s       r   test_reorder_categories_raises1TestCategoricalAPI.test_reorder_categories_raises   s>     .=M]]:S1"">2 211s   A
Ac                 D   [        / SQSS9nUR                  5       n[        / SQ/ SQSS9nUR                  S5      n[        R                  " X5        [        R                  " XC5        UR                  S/5      n[        R                  " X5        [        R                  " XC5        [        [        S5      SS9n[        [        S5      [        S5      SS9nUR                  [        SS	/5      5      n[        R                  " XE5        UR                  [        R                  " SS	/5      5      n[        R                  " XE5        UR                  [        SS	/5      5      n[        R                  " XE5        UR                  SS	/5      n[        R                  " XE5        g )
Nr/   Tr   re   r%   rf   abcabcderj   )
r   rq   add_categoriesr   rP   r   r   rL   rM   r   )r   r7   rt   ru   rQ   rT   s         r   test_add_categories&TestCategoricalAPI.test_add_categories   sK   .=hhj -A4
   %
##C-
##C-  #'
##C-
##C- $u+t4tE{tG}dS  c
!34
##C2  3*!56
##C2  Sz!23
##C2  #s,
##C2r-   c                     [        / SQSS9n[        R                  " S5      n[        R                  " [
        US9   UR                  S/5        S S S 5        g ! , (       d  f       g = f)Nre   Tr   z5new categories must not include old categories: {'d'}r   rf   )r   reescaper4   r5   r[   r   )r   r7   r   s      r   #test_add_categories_existing_raises6TestCategoricalAPI.test_add_categories_existing_raises   sH    .=iiOP]]:S1u% 211s   A
A&c                    [        [        SS/SS95      n[        S/SS9nUR                  U5      n[        [        SS/SS9[        / SQSS9S9n[        R                  " X45        [        [        / SQ[        5       S95      n[        S	/[        5       S9nUR                  U5      n[        [        / SQ[        5       S9[        / S
Q[        5       S9S9n[        R                  " X45        g )Nr<   r=   Int64r?   rY   )r<   r=   rY   r&   r!   r"   r!   rf   rx   )r   r   r   r   rP   r	   )r   r7   serrS   rT   s        r   ,test_add_categories_losing_dtype_information?TestCategoricalAPI.test_add_categories_losing_dtype_information   s    &!Qw78aS(##C(Aq6)fYg6V
 	##F5&FGcU+-0##C(?+-8o[]C
 	##F5r-   c                 	   [        / SQSS9n[        / SQ5      n[        R                  " / SQ[        R                  S9nUR                  / SQ5      nUR                  / SQ5      n[        R                  " UR                  U5        [        R                  " UR                  5       U5        [        / SQ5      n[        R                  " UR                  U5        [        R                  " UR                  5       U5        [        / SQSS9nUR                  S/5      n[        R                  " UR                  [        R                  " / SQ[        R                  S95        UR                  / S	Q5      n[        R                  " UR                  [        R                  " / S
Q[        R                  S95        [        R                  " UR                  [        / S	Q5      5        UR                  / SQ5      n[        / SQ5      n[        R                  " UR                  U5        [        / SQ/ SQSS9n[        R                  " UR                  [        R                  " / SQ[        R                  S95        [        R                  " UR                  [        / SQ5      5        [        R                  " / SQ[        R                  S9n[        R                  " [        R                  " U5      U5        UR                  / SQ5      n[        R                  " UR                  [        R                  " / SQ[        R                  S95        [        R                  " UR                  [        / SQ5      5        [        R                  " / SQ[        R                  S9n[        R                  " [        R                  " U5      U5        UR!                  5       S:X  d   eUR#                  5       S:X  d   eUR                  / SQSS9nUR$                  (       a   e[        R                  " [        R                  " U5      [        R                  " U5      5        UR'                  S5      R                  / SQ5      nUR$                  (       a   e[        R                  " [        R                  " U5      [        R                  " U5      5        g )Nr/   Tr   rp   r?   r    r!   )r   r   r   rx   )r   r<   r   r   re   )r<   r=   r>   rY   r<   rX   r%   )r   r<   r=   r>   r   rg   )r>   r=   r<   r   r>   rY   r<   F)r   r   rL   rM   rO   set_categoriesr   r'   r&   rJ   rK   codesint8_codesrN   asarrayminmaxr   r3   )	r   r7   exp_categories
exp_valuesrQ   exp_categories_backr#   expc2s	            r   test_set_categories&TestCategoricalAPI.test_set_categories   s   .=/XX2"**E
  1  1
cnnn=
##CMMOZ@#O4
cnn.AB
##CMMOZ@ .=  #'
##CIIrxxbgg/VW   1
##CIIrxxRWW/UV
cnneO.DE   !5634
cnnn= L$O
##AHHbhhbgg.VW
allE,,?@hhbhh7
##BJJqM37 \* 	##AHHbhhbgg.VW 	allE,,?@ hhbhh7
##BJJqM37uuw!||uuw!|| lE:::~
##BJJqM2::b>B ]]5!00>::~
##BJJqM2::b>Br-   z"values, categories, new_categoriesr   r"   )r"   r!   r!   r    )r"   r!   r#   rf   rj   r   TFc                 |    [        X5      n[        XU5      nUR                  X4S9n[        R                  " Xv5        g )Nr   )r   r   r   rP   )r   valuesr&   rW   r   r#   rT   rS   s           r   test_set_categories_many+TestCategoricalAPI.test_set_categories_many  s;    6 +vw?!!.!B
##F5r-   c                     [        SS/5      nUR                  S/SS9n[        S[        R                  /5      n[        R
                  " X#5        g )NrF   rG   T)rename)r   r   rL   nanr   rP   )r   r7   rS   rT   s       r   test_set_categories_rename_less2TestCategoricalAPI.test_set_categories_rename_less7  sG    3*%##SE$#7RVV}-
##F5r-   c                 2   [        / SQ/ SQS9nUR                  / SQ5        [        / SQ[        S5      S9n[        R                  " X5        [        / SQ/ SQS9nUR                  / SQSS9  [        / SQ[        S5      S9n[        R                  " X5        g )	Nr    re   r   )r!   r#   rf   rj   )r!   r#   rf   acdeT)fastpath)r   _set_categoriesr   r   rP   )r   r7   rT   s      r   test_set_categories_private.TestCategoricalAPI.test_set_categories_private>  s}    /6JK014<H
##C2 /6JK04@4<H
##C2r-   c                 p   [        / SQSS9nUR                  5       n[        SS[        R                  S/SS/SS9nUR	                  S5      n[
        R                  " X5        [
        R                  " XC5        UR	                  S/5      n[
        R                  " X5        [
        R                  " XC5        g )Nr/   Tr   r!   r"   r%   r#   )r   rq   rL   r   remove_categoriesr   rP   rs   s        r   test_remove_categories)TestCategoricalAPI.test_remove_categoriesJ  s    .=hhj3RVVS1sCjRVW##C(
##C-
##C-##SE*
##C-
##C-r-   removalsr#   c                     [        / SQ5      n[        R                  " S5      n[        R                  " [
        US9   UR                  U5        S S S 5        g ! , (       d  f       g = f)Nr   z-removals must all be in old categories: {'c'}r   )r   r   r   r4   r5   r[   r   )r   r   r7   messages       r   test_remove_categories_raises0TestCategoricalAPI.test_remove_categories_raisesW  sC    /*))KL]]:W5!!(+ 655s   A
A&c           	      .   [        / SQ/ SQS9n[        / SQ5      n[        / SQ5      n[        R                  " UR                  U5        UR                  5       n[        R                  " UR                  U5        [        R                  " UR                  U5        [        SSS[        R                  // SQS9nUR                  5       n[        R                  " UR                  [        [        R                  " / SQ5      5      5        [        R                  " / S	Q[        R                  S
9n[        R                  " UR                  U5        [        R                  " UR                  U5        S[        R                  SSSS[        R                  /n[        U[        S5      S9nUR                  5       n[        R                  " UR                  [        / SQ5      5        [        R                  " / SQ[        R                  S
9n[        R                  " UR                  U5        UR                  5       U:X  d   e[        S5      n	[        R                  R                  S5      R!                  U	S S S2   S5      R#                  S5      n[        R                  U[        R                  R                  S5      R!                  [%        U5      S5      '   [        XiS9nUR                  5       nUR                  5       UR                  5       :X  d   eg )N)r!   r"   r#   rf   r!   )r!   r"   r#   rf   rj   r   re   r!   r"   r#   r    )r   r<   r=   r   r?   FDrG   ABCDEFG)r   r&   )rG   r   r   )r=   r   r<   r   r<   r=   r   abcdefghijklmnopqrstuvwxyzr=   i'  objectd   )r   r   r   r'   r&   remove_unused_categoriesrL   r   rM   r   rJ   r   r   tolistrandomdefault_rngchoiceastypelen)
r   r#   exp_categories_allexp_categories_droppedrQ   	exp_codesvalr7   outalphas
             r   test_remove_unused_categories0TestCategoricalAPI.test_remove_unused_categories_  s-   1>WX"#<=!&';!<
all,>?((*
cnn.DE
all,>? c3/<UV((*
cnneBHH_4M.NOHH]"'':	
##CIIy9
all,>?BFFCc37iA**,
cnneO.DEHH4BGGD	
##CIIy9zz|s"""12ii##A&--eCaCj%@GGQ>@ffBII!!!$++CHc:;7**,zz|szz|+++r-    N)__name__
__module____qualname____firstlineno__r   r+   r8   rU   r4   markparametrizer]   rb   rm   rv   rz   r   r   r   r   r   r   r   r   rL   r   r   r   __static_attributes__r   r-   r   r   r      s!   $ *6* [[-q!f/EF2 G2686. [[E 	
3338&6&@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 73466
3. [[Z3%#rvvc3Z)PQ, R,!,r-   r   c                       \ rS rSrS rSrg)TestCategoricalAPIWithFactori  c           	      d   [        / SQSS9nUR                  5       nUR                  (       d   e[        / SQSUR                  S9n[	        / SQ/ SQS	.US
9n[
        R                  " X$5        UR                  5       nUR                  / SQ5      nUR                  5       n[        [        S5      UR                  SS9n[	        / SQ/ SQS	.US
9n[
        R                  " X$5        [        / SQ5      nUR                  5       n[        / SQUR                  SS9n[	        / SQ/ SQS	.US
9n[
        R                  " X$5        [        [        R                  SSS/5      nUR                  5       n[	        / SQ/ SQS	.[        SS[        R                  /SS/SS9S
9n[
        R                  " X$5        g )N)r!   r"   r"   r!   r!   r#   r#   r#   Tr   r    r&   )namer   )r>   r=   r>   )      ?      ?r   )countsfreqsr`   re   abcd)r   r   )r>   r=   r>   r   )r   r   r   r   )r<   r=   r>   r<   r=   r>   r>   r=   r<   r<   r<   r;   )rh   r>   r>   )g]tE?tE]t?r   r<   r=   )r<   r=   r<   )r   g      ?r   )r&   r   )r   describer   r   r   r   assert_frame_equalrq   r   r   rL   r   )r   factordesc	exp_indexrT   r7   s         r   test_describe*TestCategoricalAPIWithFactor.test_describe  s   EtT ~~~$,
	  +FGy
 	d- kkm  !56||~$L&..|
	 #.LM
 	d- ;<||~$Y,W	 +IJ
 	d- 2661a+,||~ +FG"ArvvAq6
 	d-r-   r   N)r   r   r   r   r   r   r   r-   r   r   r     s    /.r-   r   c                      \ rS rSrS r\R                  R                  SSS/SS/SS/SS/4SS/SS/SS/SS/4SS/SS/SS/SS/4SS/SS/SS/SS/4/ SQSS// S	Q/ SQ4/ S
Q/ S	QSS// SQ4/ SQ/ S	Q/ S	Q/ SQ4/ SQ/ S	QS// SQ4/ SQ/ S	QS// SQ4/ SQ/ S	Q/ / SQ4SS// SS/SS/4SS/SS/SS/SS/4/5      S 5       rS r	Sr
g)TestPrivateCategoricalAPIi  c                    [        SSSS[        R                  /5      n[        R                  " / SQSS9n[        R
                  " UR                  U5        [        (       a  SOSn[        R                  " [        US	9   [        R                  " / S
QSS9Ul        S S S 5        UR                  n[        R                  " [        SS	9   SUS'   S S S 5        SUS'   [        R                  " / SQSS9n[        R
                  " UR                  U5        SUR                  S'   [        R                  " / SQSS9n[        R
                  " UR                  U5        g ! , (       d  f       N= f! , (       d  f       N= f)Nr!   r"   r#   )r   r<   r=   r   r   r   r?   z6property 'codes' of 'Categorical' object has no setterr0   r   )r   r<   r=   r   r<   z#assignment destination is read-onlyr<   rY   )r   r<   r=   r   r   r=   )r   r<   r=   r   r=   )r   rL   r   rM   r   rJ   r   r   r4   r5   r6   r[   r   )r   r#   r   r   r   s        r   test_codes_immutable.TestPrivateCategoricalAPI.test_codes_immutable  s   c3RVV45hh'v6
##AGGS1
 u E& 	
 ]]>5hhf=AG 6 ]]:-RSE!H T
 !hhf5
##AGGS1hhf5
##AGGS1! 65 TSs   ?E	E-
E*-
E;zcodes, old, new, expectedr   r<   r!   r"   )r   r<   r   r<   r    )r   r<   r=   r=   )r   r<   r   r   )r   r<   r   )r   r   r   rf   )r   r   r   r   c                     [         R                  " U[         R                  S9n[         R                  " U[         R                  S9n[        U5      n[        U5      n[	        XU5      n[
        R                  " XT5        g )Nr?   )rL   
asanyarrayr   r   r
   r   rJ   )r   r   rt   ru   rT   rS   s         r   test_recode_to_categories3TestPrivateCategoricalAPI.test_recode_to_categories  sX    $ e2773==9CjCj&u37
##F5r-   c                     Sn[         R                  " U5      n[        U5      n[         R                  " US-
  SS[         R                  S9n[        U5      n[	        X#U5      n[
        R                  " Xd5        g )Ni  r<   r   r?   )rL   aranger   int16r
   r   rJ   )r   Nr   rt   rT   ru   rS   s          r   test_recode_to_categories_large9TestPrivateCategoricalAPI.test_recode_to_categories_large  s\    		!El99QUB"((;Ho&u37
##F5r-   r   N)r   r   r   r   r   r4   r   r   r   r   r   r   r-   r   r   r     s/   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/:F3%=3%>"l;"XrC:Bx0Vc3Z#saV4	
"6#"66r-   r   )r   numpyrL   r4   pandas.compatr   pandasr   r   r   r   r   r	   pandas._testing_testingr   pandas.core.arrays.categoricalr
   r   r   r   r   r-   r   <module>r      sE    	      @l, l,^0. 0.f?6 ?6r-   