
    bMh                     x   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 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)basec                      	 t           j                            d                              t	          t
          j                  d          } | d         | d         k    rn_| S )NT   d   )sizer      )nprandomdefault_rngchoiceliststringascii_letters)valuess    g/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pandas/tests/extension/test_categorical.py	make_datar      s_    &&q))00f6J1K1KRU0VV !9q	!! M    c                      t                      S Nr    r   r   dtyper   )   s    r   c                  8    t          t                                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"   8   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+   C   s"    '''S#JMMMMr   c                  $    t          g d          S )N)ar-   NNbr.   r-   cr   r   r   r   data_for_groupingr0   H   s    AAABBBr   c                       e Zd Zej                            d           fd            Zd Zd Zej        	                    d           f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 )TestCategoricalzMemory usage doesn't matchreasonc                 J    t                                          |           d S r   )supertest_memory_usageselfr   	__class__s     r   r7   z!TestCategorical.test_memory_usageN   s#     	!!$'''''r   c                     |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   )r9   r   r"   r<   na_value_objs        r   test_containszTestCategorical.test_containsS   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_emptym   sb    ((**D..&#&&&&& |/33333333r   zBackwards compatibilityc                 J    t                                          |           d S r   )r6   test_getitem_scalarr8   s     r   rK   z#TestCategorical.test_getitem_scalarv   s#    
 	##D)))))r   zUnobserved categories includedc                 H    t                                          ||          S r   )r6   test_value_counts)r9   all_datadropnar:   s      r   rM   z!TestCategorical.test_value_counts}   s    ww((6:::r   c           	      $    |d          \  }}t          j        |          }t          j        |          }|                    |d           }t          j        d t          t	          |          t	          |                    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     IIIv1QUIIIr   r   c                     | |z   S r   r   rR   s     r   rU   z2TestCategorical.test_combine_add.<locals>.<lambda>   s
    R r   c                     g | ]}|z   S r   r   )rW   r-   vals     r   rX   z4TestCategorical.test_combine_add.<locals>.<listcomp>   s    @@@!a#g@@@r   )pdSeriescombinezipr   r>   assert_series_equaliloc)	r9   data_repeated
orig_data1
orig_data2s1s2rH   expectedr[   s	           @r   test_combine_addz TestCategorical.test_combine_add   s    "/q!1!1
JYz""Yz""B 6 6779IIT*%5%5tJ7G7G!H!HIII
 
 	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   rU   z*TestCategorical.test_map.<locals>.<lambda>   s    A r   )ri   )mapr>   assert_extension_array_equal)r9   r   ri   rH   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 argumentr3   )applymarkerpytestmarkxfailr6   test_arith_frame_with_scalarr9   r   all_arithmetic_operatorsrequestop_namer:   s        r   rx   z,TestCategorical.test_arith_frame_with_scalar   sj    *j  !!L "    
 	,,T7;;;;;r   c                     |}|dk    r3|                     t          j                            d                     t	                                          ||           d S rr   )rt   ru   rv   rw   r6   test_arith_series_with_scalarry   s        r   r~   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__ru   raises	TypeErrorr6   _compare_other)r9   r   r   opotherr|   msgr:   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   )r6   test_array_repr)r9   r   r   r:   s      r   r   zTestCategorical.test_array_repr   s%     	d+++++r   TBDas_indexTFc                 L    t                                          ||           d S r   )r6   test_groupby_extension_agg)r9   r   r0   r:   s      r   r   z*TestCategorical.test_groupby_extension_agg   s&     	**85FGGGGGr   )r   
__module____qualname__ru   rv   rw   r7   rA   rI   skiprK   rM   rh   parametrizerp   rx   r~   r\   r]   r   r   r   __classcell__)r:   s   @r   r2   r2   M   sL       [:;;( ( ( ( <;(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   r2   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   ru   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          - - - - - -                 - - - - - - ' ' ' ' ' '      $ $ $ & & &
 R R R N N N C C CpH pH pH pH pHd) pH pH pHf. . . . .4, . . . . .r   