
    PiQ                     ~   d Z ddlZddlZddlZddlmZ ddlZddlm	Z	 ddl
mZ ddlmZ ddlmZ defdZej        d	             Zej        d
             Zej        d             Zej        d             Zej        d             Zej        d             Z G d dej                  Z G d dej                  ZdS )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_string_dtypeCategoricalCategoricalDtype)basenc                     	 t           j                            d                              t	          t
          j                  |           }|d         |d         k    rn_|S )NT   )sizer      )nprandomdefault_rngchoiceliststringascii_letters)r	   valuess     {/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/pandas/tests/extension/test_categorical.py	make_datar      s_    &&q))00f6J1K1KRS0TT !9q	!! M    c                      t                      S Nr    r   r   dtyper   *   s    r   c                  :    t          t          d                    S )zLength-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    t          t          j        dg          S )zLength 2 array with [NA, Valid]A)r   r   nanr   r   r   data_missingr#   9   s     }%%%r   c                  .    t          g dg dd          S )N)r!   BC)r&   r!   r%   T
categoriesorderedr   r   r   r   data_for_sortingr*   ?   s    ???DQQQQr   c                  .    t          g dddgd          S )N)r!   Nr%   r%   r!   Tr'   r   r   r   r   data_missing_for_sortingr,   D   s"    '''S#JMMMMr   c                  $    t          g d          S )N)ar.   NNbr/   r.   cr   r   r   r   data_for_groupingr1   I   s    AAABBBr   c                       e Zd Zd Zd Zej                            d           fd            Zd Z	ej        
                    ddd	g          d
             Z fdZ fdZdej        f fdZej                            d          ej        
                    dddg           fd                        Zej                            d          ej        
                    dddg           fd                        Z xZS )TestCategoricalc                     |j         j        }||                                          }|d         |v sJ |d         |v sJ ||v sJ ||vsJ t          j        D ]!}||u r||vsJ t                      s||v sJ "d S )Nr   )r   na_valueisnatmNULL_OBJECTSr   )selfr   r#   r5   na_value_objs        r   test_containszTestCategorical.test_containsO   s    
 :&TYY[[L! Aw$A,.... <''''t#### O 	4 	4Lx''t++++%'' 4#|3333	4 	4r   c                     |                                 }|                    d|          }t          ||          sJ |j        t	          g           k    sJ d S )N)   )r   )construct_array_type_empty
isinstancer   r   )r9   r   clsresults       r   
test_emptyzTestCategorical.test_emptyi   sb    ((**D..&#&&&&& |/33333333r   zBackwards compatibilityreasonc                 J    t                                          |           d S r   )supertest_getitem_scalar)r9   r   	__class__s     r   rH   z#TestCategorical.test_getitem_scalarr   s#    
 	##D)))))r   c           	      (    |d          \  }}t          j        |          }t          j        |          }|                    |d           }t          j        d t          t	          |          t	          |          d          D                       }t          j        ||           |j        d         |                    d           }t          j        fdt	          |          D                       }t          j        ||           d S )	Nr   c                     | |z   S r   r   x1x2s     r   <lambda>z2TestCategorical.test_combine_add.<locals>.<lambda>   s
    rBw r   c                     g | ]
\  }}||z   S r   r   ).0r.   r/   s      r   
<listcomp>z4TestCategorical.test_combine_add.<locals>.<listcomp>   s     VVVv1QUVVVr   T)strictr   c                     | |z   S r   r   rL   s     r   rO   z2TestCategorical.test_combine_add.<locals>.<lambda>   s
    R r   c                     g | ]}|z   S r   r   )rQ   r.   vals     r   rR   z4TestCategorical.test_combine_add.<locals>.<listcomp>   s    @@@!a#g@@@r   )pdSeriescombinezipr   r7   assert_series_equaliloc)	r9   data_repeated
orig_data1
orig_data2s1s2rB   expectedrV   s	           @r   test_combine_addz TestCategorical.test_combine_addy   s    "/q!1!1
JYz""Yz""B 6 6779VVT*%5%5tJ7G7GPT!U!U!UVVV
 
 	vx000gajC!7!7889@@@@tJ/?/?@@@AA
vx00000r   	na_actionNignorec                 `    |                     d |          }t          j        ||           d S )Nc                     | S r   r   )xs    r   rO   z*TestCategorical.test_map.<locals>.<lambda>   s    A r   )rd   )mapr7   assert_extension_array_equal)r9   r   rd   rB   s       r   test_mapzTestCategorical.test_map   s2    ++;;
'55555r   c                     |}|dk    r3|                     t          j                            d                     t	                                          ||           d S N__rmod__z/rmod never called when string is first argumentrD   )applymarkerpytestmarkxfailrG   test_arith_frame_with_scalarr9   r   all_arithmetic_operatorsrequestop_namerI   s        r   rs   z,TestCategorical.test_arith_frame_with_scalar   sj    *j  !!L "    
 	,,T7;;;;;r   c                     |}|dk    r3|                     t          j                            d                     t	                                          ||           d S rm   )ro   rp   rq   rr   rG   test_arith_series_with_scalarrt   s        r   ry   z-TestCategorical.test_arith_series_with_scalar   sj    *j  !!L "    
 	--dG<<<<<r   serc                     d|j          d}|dvrDd}t          j        t          |          5   |||           d d d            d S # 1 swxY w Y   d S t	                                          ||||          S )N__)__eq____ne__z7Unordered Categoricals can only compare equality or not)match)__name__rp   raises	TypeErrorrG   _compare_other)r9   rz   r   opotherrw   msgrI   s          r   r   zTestCategorical._compare_other   s    &r{&&&...KCy444    4                                    77))#tR???s   AAAzCategorical overrides __repr__r   bigsmallc                 L    t                                          ||           d S r   )rG   test_array_repr)r9   r   r   rI   s      r   r   zTestCategorical.test_array_repr   s%     	d+++++r   TBDas_indexTFc                 L    t                                          ||           d S r   )rG   test_groupby_extension_agg)r9   r   r1   rI   s      r   r   z*TestCategorical.test_groupby_extension_agg   s&     	**85FGGGGGr   )r   
__module____qualname__r;   rC   rp   rq   skiprH   rc   parametrizerk   rs   ry   rW   rX   r   rr   r   r   __classcell__)rI   s   @r   r3   r3   N   s       4 4 444 4 4 [677* * * * 87*1 1 1" [[4*:;;6 6 <;6	< 	< 	< 	< 	<= = = = =@") @ @ @ @ @ @ [>??[VeW%566, , , , 76 @?, [e$$[Z$77H H H H 87 %$H H H H Hr   r3   c                       e Zd Zd ZdS )Test2DCompatc                     t          |                    dd                    }|                    d          dk    sJ t          |                    dd                    }|                    d          dk    sJ d S )Nr   z
Categories)reprreshapecount)r9   r   ress      r   test_repr_2dzTest2DCompat.test_repr_2d   sz     4<<2&&''yy((A----4<<A&&''yy((A------r   N)r   r   r   r   r   r   r   r   r      s#        . . . . .r   r   )__doc__r   numpyr   rp   pandas._configr   pandasrW   r   pandas._testing_testingr7   pandas.api.typesr   pandas.tests.extensionr   intr   fixturer   r   r#   r*   r,   r1   ExtensionTestsr3   NDArrayBacked2DTestsr   r   r   r   <module>r      s           - - - - - -                 - - - - - - ' ' ' ' ' '        & & & & & &
 R R R N N N C C CgH gH gH gH gHd) gH gH gHT. . . . .4, . . . . .r   