
    Mh                        S r SSKrSSKrSSKrSSKJr  SSKrSSKJ	r	  SSK
Jr  SSKJr  SSKJr  S r\R$                  S 5       r\R$                  S	 5       r\R$                  S
 5       r\R$                  S 5       r\R$                  S 5       r\R$                  S 5       r " S S\R2                  5      r " S S\R6                  5      rg)aj  
This file contains a minimal set of tests for compliance with the extension
array interface test suite, and should contain no other tests.
The test suite for the full functionality of the array is located in
`pandas/tests/arrays/`.

The tests in this file are inherited from the BaseExtensionTests, and only
minimal tweaks should be applied to get the tests passing (by overwriting a
parent method).

Additional tests should either be added to one of the BaseExtensionTests
classes (if they are relevant for the extension interface for all dtypes), or
be added to the array-specific tests in `pandas/tests/arrays/`.

    N)using_pyarrow_string_dtypeCategoricalCategoricalDtype)basec                       [         R                  R                  S5      R                  [	        [
        R                  5      SS9n U S   U S   :w  a   U $ MU  )N   d   )sizer      )nprandomdefault_rngchoiceliststringascii_letters)valuess    Y/var/www/html/env/lib/python3.13/site-packages/pandas/tests/extension/test_categorical.py	make_datar      sT    
&&q)00f6J6J1KRU0V !9q	!M     c                      [        5       $ Nr    r   r   dtyper   )   s    r   c                  (    [        [        5       5      $ )z|Length-100 array for this type.

* data[0] and data[1] should both be non missing
* data[0] and data[1] should not be equal
)r   r   r   r   r   datar   .   s     y{##r   c                  8    [        [        R                  S/5      $ )zLength 2 array with [NA, Valid]A)r   r   nanr   r   r   data_missingr"   8   s     }%%r   c                       [        / SQ/ SQSS9$ )N)r    BC)r%   r    r$   T
categoriesorderedr   r   r   r   data_for_sortingr)   >   s    ?DQQr   c                       [        / SQSS/SS9$ )N)r    Nr$   r$   r    Tr&   r   r   r   r   data_missing_for_sortingr+   C   s    'S#JMMr   c                      [        / SQ5      $ )N)ar-   NNbr.   r-   cr   r   r   r   data_for_groupingr0   H   s    ABBr   c                     ^  \ rS rSr\R
                  R                  SS9U 4S j5       rS rS r	\R
                  R                  SS9U 4S j5       r\R
                  R                  S	S9U 4S
 j5       rS r\R
                  R                  SSS/5      S 5       rU 4S jrU 4S jrS\R&                  4U 4S jjr\R
                  R                  SS9\R
                  R                  SSS/5      U 4S j5       5       r\R
                  R                  SS9\R
                  R                  SSS/5      U 4S j5       5       rSrU =r$ )TestCategoricalM   zMemory usage doesn't matchreasonc                 $   > [         TU ]  U5        g r   )supertest_memory_usageselfr   	__class__s     r   r8   !TestCategorical.test_memory_usageN   s     	!$'r   c                    UR                   R                  nXR                  5       )    nUS   U;   d   eUS   U;   d   eX2;   d   eX1;  d   e[        R                   H(  nXCL a  M	  XA;  d   e[        5       (       a  M!  XB;   a  M(   e   g )Nr   )r   na_valueisnatmNULL_OBJECTSr   )r:   r   r"   r>   na_value_objs        r   test_containsTestCategorical.test_containsS   s    
 ::&&YY[L! Aw$A,... '''### OOL'+++-//#333 ,r   c                     UR                  5       nUR                  SUS9n[        X25      (       d   eUR                  [	        / 5      :X  d   eg )N)   )r   )construct_array_type_empty
isinstancer   r   )r:   r   clsresults       r   
test_emptyTestCategorical.test_emptym   sM    ((*D.&&&&& ||/3333r   zBackwards compatibilityc                 $   > [         TU ]  U5        g r   )r7   test_getitem_scalarr9   s     r   rO   #TestCategorical.test_getitem_scalarv   s    
 	#D)r   zUnobserved categories includedc                 "   > [         TU ]  X5      $ r   )r7   test_value_counts)r:   all_datadropnar;   s      r   rR   !TestCategorical.test_value_counts}   s    w(::r   c                 >   U" S5      u  p#[         R                  " U5      n[         R                  " U5      nUR                  US 5      n[         R                  " [        [	        U5      [	        U5      5       VVs/ s H	  u  pxXx-   PM     snn5      n	[
        R                  " Xi5        UR                  S   n
UR                  U
S 5      n[         R                  " [	        U5       Vs/ s H  owU
-   PM	     sn5      n	[
        R                  " Xi5        g s  snnf s  snf )Nr
   c                 
    X-   $ r   r   x1x2s     r   <lambda>2TestCategorical.test_combine_add.<locals>.<lambda>   s    rwr   r   c                 
    X-   $ r   r   rX   s     r   r[   r\      s    r   )pdSeriescombinezipr   r@   assert_series_equaliloc)r:   data_repeated
orig_data1
orig_data2s1s2rK   r-   r.   expectedvals              r   test_combine_add TestCategorical.test_combine_add   s     "/q!1
YYz"YYz"B 6799!$T*%5tJ7G!HI!HvQU!HI
 	v0ggajC!7899tJ/?@/?!#g/?@A
v0 J As   ;D
(D	na_actionNignorec                 R    UR                  S US9n[        R                  " X15        g )Nc                     U $ r   r   )xs    r   r[   *TestCategorical.test_map.<locals>.<lambda>   s    Ar   )rm   )mapr@   assert_extension_array_equal)r:   r   rm   rK   s       r   test_mapTestCategorical.test_map   s"    +;
''5r   c                    > UnUS:X  a,  UR                  [        R                  R                  SS95        [        TU ]  X5        g N__rmod__z/rmod never called when string is first argumentr4   )applymarkerpytestmarkxfailr7   test_arith_frame_with_scalarr:   r   all_arithmetic_operatorsrequestop_namer;   s        r   r~   ,TestCategorical.test_arith_frame_with_scalar   sG    *j !!L " 
 	,T;r   c                    > UnUS:X  a,  UR                  [        R                  R                  SS95        [        TU ]  X5        g rx   )rz   r{   r|   r}   r7   test_arith_series_with_scalarr   s        r   r   -TestCategorical.test_arith_series_with_scalar   sG    *j !!L " 
 	-d<r   serc                    > SUR                    S3nUS;  a-  Sn[        R                  " [        US9   U" X$5        S S S 5        g [        TU ]  XX45      $ ! , (       d  f       g = f)N__)__eq____ne__z7Unordered Categoricals can only compare equality or not)match)__name__r{   raises	TypeErrorr7   _compare_other)r:   r   r   opotherr   msgr;   s          r   r   TestCategorical._compare_other   s]    r{{m2&..KCy44 54 7)#R?? 54s   	A
A#zCategorical overrides __repr__r   bigsmallc                 $   > [         TU ]  X5        g r   )r7   test_array_repr)r:   r   r   r;   s      r   r   TestCategorical.test_array_repr   s     	+r   TBDas_indexTFc                 $   > [         TU ]  X5        g r   )r7   test_groupby_extension_agg)r:   r   r0   r;   s      r   r   *TestCategorical.test_groupby_extension_agg   s     	*8Gr   r   )r   
__module____qualname____firstlineno__r{   r|   r}   r8   rC   rL   skiprO   rR   rk   parametrizeru   r~   r   r^   r_   r   r   r   __static_attributes____classcell__)r;   s   @r   r2   r2   M   sW   [[:;( <(444 [[67* 8* [[>?; @;1" [[[4*:;6 <6	<=@")) @ [[>?[[VeW%56, 7 @, [[e$[[Z$7H 8 %Hr   r2   c                       \ rS rSrS rSrg)Test2DCompat   c                     [        UR                  SS5      5      nUR                  S5      S:X  d   e[        UR                  SS5      5      nUR                  S5      S:X  d   eg )Nr   z
Categories)reprreshapecount)r:   r   ress      r   test_repr_2dTest2DCompat.test_repr_2d   s\     4<<2&'yy(A---4<<A&'yy(A---r   r   N)r   r   r   r   r   r   r   r   r   r   r      s    .r   r   )__doc__r   numpyr   r{   pandas._configr   pandasr^   r   pandas._testing_testingr@   pandas.api.typesr   pandas.tests.extensionr   r   fixturer   r   r"   r)   r+   r0   ExtensionTestsr2   NDArrayBacked2DTestsr   r   r   r   <module>r      s       5    - '   $ $ & &
 R R N N C CpHd)) pHf.4,, .r   