
    Owg                        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j2                        Z G d dej6                        Zy)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                      	 t         j                  j                  d      j                  t	        t
        j                        d      } | d   | d   k7  r	 | S V)N   d   )sizer      )nprandomdefault_rngchoiceliststringascii_letters)valuess    ^/var/www/horilla/myenv/lib/python3.12/site-packages/pandas/tests/extension/test_categorical.py	make_datar      sT    
&&q)00f6J6J1KRU0V !9q	!M     c                      t               S Nr    r   r   dtyper   )   s    r   c                  (    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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Mr   c                      t        g d      S )N)ar-   NNbr.   r-   cr   r   r   r   data_for_groupingr0   H   s    ABBr   c                       e Zd Zej                  j                  d       fd       Zd Zd Zej                  j                  d       fd       Z
ej                  j                  d       fd	       Zd
 Zej                  j                  dddg      d        Z fdZ fdZdej$                  f fdZej                  j                  d      ej                  j                  dddg       fd              Zej                  j                  d      ej                  j                  dddg       fd              Z xZS )TestCategoricalzMemory usage doesn't matchreasonc                 $    t         |   |       y r   )supertest_memory_usageselfr   	__class__s     r   r7   z!TestCategorical.test_memory_usageN   s     	!$'r   c                     |j                   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               r||v rJ  y )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### OO 	4Lx't+++-/#|333	4r   c                     |j                         }|j                  d|      }t        ||      sJ |j                  t	        g       k(  sJ y )N)   )r   )construct_array_type_empty
isinstancer   r   )r9   r   clsresults       r   
test_emptyzTestCategorical.test_emptym   sL    ((*D.&#&&& ||/3333r   zBackwards compatibilityc                 $    t         |   |       y r   )r6   test_getitem_scalarr8   s     r   rK   z#TestCategorical.test_getitem_scalarv   s    
 	#D)r   zUnobserved categories includedc                 $    t         |   ||      S r   )r6   test_value_counts)r9   all_datadropnar:   s      r   rM   z!TestCategorical.test_value_counts}   s    w(6::r   c                 2    |d      \  }}t        j                  |      }t        j                  |      }|j                  |d       }t        j                  t        t	        |      t	        |            D cg c]
  \  }}||z    c}}      }	t        j                  ||	       |j                  d   }
|j                  |
d       }t        j                  t	        |      D cg c]  }||
z   	 c}      }	t        j                  ||	       y c c}}w c c}w )Nr
   c                     | |z   S r   r   x1x2s     r   <lambda>z2TestCategorical.test_combine_add.<locals>.<lambda>   s
    rBw r   r   c                     | |z   S r   r   rR   s     r   rU   z2TestCategorical.test_combine_add.<locals>.<lambda>   s
    R r   )pdSeriescombinezipr   r>   assert_series_equaliloc)r9   data_repeated
orig_data1
orig_data2s1s2rH   r-   r.   expectedvals              r   test_combine_addz TestCategorical.test_combine_add   s     "/q!1
JYYz"YYz"B 6799!$T*%5tJ7G!HIv1QUI
 	vx0ggajC!7899tJ/?@!a#g@A
vx0 J As   9D
$D	na_actionNignorec                 X    |j                  d |      }t        j                  ||       y )Nc                     | S r   r   )xs    r   rU   z*TestCategorical.test_map.<locals>.<lambda>   s    A r   )re   )mapr>   assert_extension_array_equal)r9   r   re   rH   s       r   test_mapzTestCategorical.test_map   s$    +;
''5r   c                     |}|dk(  r/|j                  t        j                  j                  d             t        |   ||       y 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   rt   z,TestCategorical.test_arith_frame_with_scalar   sI    *j !!L " 
 	,T7;r   c                     |}|dk(  r/|j                  t        j                  j                  d             t        |   ||       y rn   )rp   rq   rr   rs   r6   test_arith_series_with_scalarru   s        r   rz   z-TestCategorical.test_arith_series_with_scalar   sI    *j !!L " 
 	-dG<r   serc                     d|j                    d}|dvr0d}t        j                  t        |      5   |||       d d d        y t        |   ||||      S # 1 sw Y   y xY w)N__)__eq____ne__z7Unordered Categoricals can only compare equality or not)match)__name__rq   raises	TypeErrorr6   _compare_other)r9   r{   r   opotherrx   msgr:   s          r   r   zTestCategorical._compare_other   sl    r{{m2&..KCy4  4    7)#tR??   s   
AA!zCategorical overrides __repr__r   bigsmallc                 &    t         |   ||       y r   )r6   test_array_repr)r9   r   r   r:   s      r   r   zTestCategorical.test_array_repr   s     	d+r   TBDas_indexTFc                 &    t         |   ||       y r   )r6   test_groupby_extension_agg)r9   r   r0   r:   s      r   r   z*TestCategorical.test_groupby_extension_agg   s     	*85FGr   )r   
__module____qualname__rq   rr   rs   r7   rA   rI   skiprK   rM   rd   parametrizerl   rt   rz   rW   rX   r   r   r   __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                       e Zd Zd Zy)Test2DCompatc                     t        |j                  dd            }|j                  d      dk(  sJ t        |j                  dd            }|j                  d      dk(  sJ y )Nr   z
Categories)reprreshapecount)r9   r   ress      r   test_repr_2dzTest2DCompat.test_repr_2d   s\     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   rq   pandas._configr   pandasrW   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   