
    I jBM                         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)Pandas4Warning)CategoricalCategoricalIndex	DataFrameIndexSeriesStringDtype)recode_for_categoriesc                      \ 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      S 5       rS rS rS  r\R                  R                  S!S"/S"\R0                  /S"S"S"//5      S# 5       rS$ rS%rg&)'TestCategoricalAPI   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 )	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        y/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/pandas/tests/arrays/categorical/test_api.py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                    [        / 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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match)r   as_unorderedr   
as_orderedset_orderedpytestraisesAttributeError)r   catr   msgs       r!   test_set_ordered#TestCategoricalAPI.test_set_ordered'   s    .=!<<~~|||%----##E*2222 I]]>5CK 6]]>5CK 65 6555s   2C,C=,
C:=
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&            )r5   r6   r7   r5   dtyper   c                 "    U R                  5       $ )N)upper)xs    r!   <lambda>;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_categories)TestCategoricalAPI.test_rename_categories8   s    ./ ##I.
##MMORXXl"((C	
 	cnneI.>?((/rzzB
##CMMOW=(
cnng6 &&':;34
##F5r$   new_categoriesr5   r6   r7      r5   r6   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   r,   r-   
ValueErrorrB   r   rP   r/   r0   s       r!   *test_rename_categories_wrong_length_raises=TestCategoricalAPI.test_rename_categories_wrong_length_raisesM   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   r5   index)r   rB   r   r   rI   )r   r   rL   rM   s       r!   test_rename_categories_series0TestCategoricalAPI.test_rename_categories_seriesW   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   drR   r7   r6   r5   rR   r7   r6   r5   )r   r   )r5   r   r7   r_         )r   r   r   r_   efrQ   )rd   g)r   rB   r   r   r   r   )r   r/   rJ   rM   s       r!   test_rename_categories_dict.TestCategoricalAPI.test_rename_categories_dict^   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   rI   r   r/   oldnewrJ   s        r!   test_reorder_categories*TestCategoricalAPI.test_reorder_categoriesy   sY    .=hhj _d
 $$_5
##C-
##C-r$   r   r   r   r_   r^   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   r,   r-   rT   rk   rU   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   r^   r   r_   abcabcderc   )
r   rj   add_categoriesr   rI   r   r   rE   rF   r   )r   r/   rm   rn   rJ   rM   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)Nr^   Tr   z5new categories must not include old categories: {'d'}r'   r_   )r   reescaper,   r-   rT   rx   )r   r/   r0   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 )Nr5   r6   Int64r8   rR   )r5   r6   rR   r   r   r   r   r_   rq   )r   r   rx   r   rI   r	   )r   r/   serrL   rM   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   ri   r8   r   r   )r   r   r   rq   )r   r5   r   r   r^   )r5   r6   r7   rR   r5   rQ   r   )r   r5   r6   r7   r   r`   )r7   r6   r5   r   r7   rR   r5   F)r   r   rE   rF   rH   set_categoriesr   r   r   rC   rD   codesint8_codesrG   asarrayminmaxr   r+   )	r   r/   exp_categories
exp_valuesrJ   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   r_   rc   c                    Sn[        U5      R                  U5      (       a  [        OS n[        R                  " XeS9   [        X5      nS S S 5        [        U5      R                  U5      (       a  [        OS n[        R                  " XS9   [        XU5      n	S S S 5        WR                  X4S9n
[        R                  " U
W	5        g ! , (       d  f       N= f! , (       d  f       NF= f)Nz=Constructing a Categorical with a dtype and values containingr'   r   )set
differencer   r   assert_produces_warningr   r   rI   )r   valuesr   rP   r   r0   warn1r   warn2rM   rL   s              r!   test_set_categories_many+TestCategoricalAPI.test_set_categories_many  s    4 N"%f+"8"8"D"D$''9F/A : #&f+"8"8"H"Hd''9"67CH : !!.!B
##FH5 :9 :9s   C	C	
C
C(c                     [        SS/5      nUR                  S/SS9n[        S[        R                  /5      n[        R
                  " X#5        g )Nr?   r@   T)rename)r   r   rE   nanr   rI   )r   r/   rL   rM   s       r!   test_set_categories_rename_less2TestCategoricalAPI.test_set_categories_rename_less3  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   r^   r   )r   r   r_   rc   )r   r   r_   acdeT)fastpath)r   _set_categoriesr   r   rI   )r   r/   rM   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   rj   rE   r   remove_categoriesr   rI   rl   s        r!   test_remove_categories)TestCategoricalAPI.test_remove_categoriesF  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}   r,   r-   rT   r   )r   r   r/   messages       r!   test_remove_categories_raises0TestCategoricalAPI.test_remove_categories_raisesS  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   r_   r   )r   r   r   r_   rc   r   r^   r   r   r   r   )r   r5   r6   r   r8   FDr@   ABCDEFG)r   r   )r@   r   r   )r6   r   r5   r   r5   r6   r   abcdefghijklmnopqrstuvwxyzr6   i'  objectd   )r   r   r   r   r   remove_unused_categoriesrE   r   rF   r   rC   r   r   tolistrandomdefault_rngchoiceastypelen)
r   r   exp_categories_allexp_categories_droppedrJ   	exp_codesvalr/   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"   r1   rN   r,   markparametrizerV   r[   rf   ro   rs   ry   r~   r   r   r   r   r   r   rE   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632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   )r7   r6   r7   )      ?      ?r   )countsfreqsrY   r^   abcd)r   r   )r7   r6   r7   r   )r   r   r   r   )r5   r6   r7   r5   r6   r7   r7   r6   r5   r5   r5   r4   )ra   r7   r7   )g]tE?tE]t?r   r5   r6   )r5   r6   r5   )r   g      ?r   )r   r   )r   describer   r   r   r   assert_frame_equalrj   r   r   rE   r   )r   factordesc	exp_indexrM   r/   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        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   r5   r6   r   r   r   r8   z6property 'codes' of 'Categorical' object has no setterr'   )r   r5   r6   r   r5   z#assignment destination is read-onlyr5   rR   )r   r5   r6   r   r   r6   )r   r5   r6   r   r6   )r   rE   r   rF   r   rC   r   r,   r-   r.   rT   r   )r   r   r   r0   r   s        r!   test_codes_immutable.TestPrivateCategoricalAPI.test_codes_immutable  s	   c3RVV45hh'v6
##AGGS1 G]]>5hhf=AG 6 ]]:-RSE!H T
 !hhf5
##AGGS1hhf5
##AGGS1! 65 TSs   2E<E 
E 
E.zcodes, old, new, expectedr   r5   r   r   )r   r5   r   r5   r   )r   r5   r6   r6   )r   r5   r   r   )r   r5   r   )r   r   r   r_   )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SS9n[
        R                  " XT5        g )Nr8   Trj   )rE   
asanyarrayr   r   r
   r   rC   )r   r   rm   rn   rM   rL   s         r!   test_recode_to_categories3TestPrivateCategoricalAPI.test_recode_to_categories  sZ    $ e2773==9CjCj&u3TB
##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SS9n[
        R                  " Xd5        g )Ni  r5   r   r8   Tr   )rE   aranger   int16r
   r   rC   )r   Nr   rm   rM   rn   rL   s          r!   test_recode_to_categories_large9TestPrivateCategoricalAPI.test_recode_to_categories_large  s^    		!El99QUB"((;Ho&u3TB
##F5r$   r   N)r   r   r   r   r   r,   r   r   r   r   r   r   r$   r!   r   r     s/   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/:F3%=3%>"l;"XrC:Bx0Vc3Z#saV4	
"6#"66r$   r   )r|   numpyrE   r,   pandas.errorsr   pandasr   r   r   r   r   r	   pandas._testing_testingr   pandas.core.arrays.categoricalr
   r   r   r   r   r$   r!   <module>r      sE    	   (   @h, h,V0. 0.f;6 ;6r$   