
    o[weG                        d Z ddlZddlZddl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 G d dej                  Z G d dej                  Z G d dej                  Z  G d dej!                  Z" G d dej#                  Z$ G d dej%                  Z& G d dej'                  Z( G d d ej)                  Z* G d! d"ej+                  Z, G d# d$ej-                  Z. G d% d&ej/                  Z0 G d' d(ej1                  Z2 G d) d*ej3                  Z4 G d+ d,ej5                  Z6d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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    Glib/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!   6   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*   A   s"    '''S#JMMMMr   c                  $    t          g d          S )N)ar,   NNbr-   r,   cr   r   r   r   data_for_groupingr/   F   s    AAABBBr   c                       e Zd ZdS )	TestDtypeN__name__
__module____qualname__r   r   r   r1   r1   K           Dr   r1   c                   f     e Zd Zej                            d           fd            Zd Z xZS )TestInterfacezMemory usage doesn't matchreasonc                 J    t                                          |           d S r   )supertest_memory_usageselfr   	__class__s     r   r=   zTestInterface.test_memory_usageP   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 ||v sJ d S )Nr   )r   na_valueisnatmNULL_OBJECTS)r?   r   r!   rB   na_value_objs        r   test_containszTestInterface.test_containsU   s    
 :&TYY[[L! Aw$A,.... <''''t#### O 	0 	0Lx''t++++</////		0 	0r   )	r3   r4   r5   pytestmarkxfailr=   rG   __classcell__r@   s   @r   r8   r8   O   sf        [:;;( ( ( ( <;(0 0 0 0 0 0 0r   r8   c                       e Zd Zd ZdS )TestConstructorsc                     |                                 }|                    d|          }t          ||          sJ |j        t	          g           k    sJ d S )N)   )r   )construct_array_type_empty
isinstancer   r   )r?   r   clsresults       r   
test_emptyzTestConstructors.test_emptyo   sb    ((**D..&#&&&&& |/33333333r   N)r3   r4   r5   rV   r   r   r   rN   rN   n   s#        4 4 4 4 4r   rN   c                       e Zd ZdS )TestReshapingNr2   r   r   r   rX   rX   y   r6   r   rX   c                   `     e Zd Zej                            d           fd            Z xZS )TestGetitemzBackwards compatibilityr9   c                 J    t                                          |           d S r   )r<   test_getitem_scalarr>   s     r   r\   zTestGetitem.test_getitem_scalar~   s#    
 	##D)))))r   )r3   r4   r5   rH   rI   skipr\   rK   rL   s   @r   rZ   rZ   }   sW        [677* * * * 87* * * * *r   rZ   c                       e Zd ZdS )TestSetitemNr2   r   r   r   r_   r_      r6   r   r_   c                       e Zd ZdS )	TestIndexNr2   r   r   r   ra   ra      r6   r   ra   c                       e Zd ZdS )TestMissingNr2   r   r   r   rc   rc      r6   r   rc   c                       e Zd ZdS )
TestReduceNr2   r   r   r   re   re      r6   r   re   c                       e Zd ZdS )TestAccumulateNr2   r   r   r   rg   rg      r6   r   rg   c                        e Zd Zej                            d           fd            Zd Zej                            dddg          d             Z	 xZ
S )	TestMethodszUnobserved categories includedr9   c                 H    t                                          ||          S r   )r<   test_value_counts)r?   all_datadropnar@   s      r   rk   zTestMethods.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>z.TestMethods.test_combine_add.<locals>.<lambda>   s
    rBw r   c                     g | ]
\  }}||z   S r   r   ).0r,   r-   s      r   
<listcomp>z0TestMethods.test_combine_add.<locals>.<listcomp>   s     IIIv1QUIIIr   r   c                     | |z   S r   r   rp   s     r   rs   z.TestMethods.test_combine_add.<locals>.<lambda>   s
    R r   c                     g | ]}|z   S r   r   )ru   r,   vals     r   rv   z0TestMethods.test_combine_add.<locals>.<listcomp>   s    @@@!a#g@@@r   )pdSeriescombinezipr   rD   assert_series_equaliloc)	r?   data_repeated
orig_data1
orig_data2s1s2rU   expectedry   s	           @r   test_combine_addzTestMethods.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   rs   z&TestMethods.test_map.<locals>.<lambda>   s    A r   )r   )maprD   assert_extension_array_equal)r?   r   r   rU   s       r   test_mapzTestMethods.test_map   s2    ++;;
'55555r   )r3   r4   r5   rH   rI   rJ   rk   r   parametrizer   rK   rL   s   @r   ri   ri      s        [>??; ; ; ; @?;1 1 1" [[4*:;;6 6 <;6 6 6 6 6r   ri   c                       e Zd ZdS )TestCastingNr2   r   r   r   r   r      r6   r   r   c                   (     e Zd Z fdZ fdZ xZS )TestArithmeticOpsc                     |}|dk    r8|j                             t          j                            d                     t                                          ||           d S N__rmod__z/rmod never called when string is first argumentr9   )node
add_markerrH   rI   rJ   r<   test_arith_frame_with_scalarr?   r   all_arithmetic_operatorsrequestop_namer@   s        r   r   z.TestArithmeticOps.test_arith_frame_with_scalar   sl    *j  L##!!L "    
 	,,T7;;;;;r   c                     |}|dk    r8|j                             t          j                            d                     t                                          ||           d S r   )r   r   rH   rI   rJ   r<   test_arith_series_with_scalarr   s        r   r   z/TestArithmeticOps.test_arith_series_with_scalar   sl    *j  L##!!L "    
 	--dG<<<<<r   )r3   r4   r5   r   r   rK   rL   s   @r   r   r      sQ        	< 	< 	< 	< 	<= = = = = = = = =r   r   c                        e Zd Z fdZ xZS )TestComparisonOpsc                     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)r3   rH   raises	TypeErrorr<   _compare_other)r?   sr   opotherr   msgr@   s          r   r   z TestComparisonOps._compare_other   s    &r{&&&...KCy444    4                                    77))!T2u===s   AAA)r3   r4   r5   r   rK   rL   s   @r   r   r      s8        > > > > > > > > >r   r   c                       e Zd ZdS )TestParsingNr2   r   r   r   r   r      r6   r   r   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)r?   r   ress      r   test_repr_2dzTest2DCompat.test_repr_2d   sz     4<<2&&''yy((A----4<<A&&''yy((A------r   N)r3   r4   r5   r   r   r   r   r   r      s#        . . . . .r   r   )7__doc__r   numpyr   rH   pandasrz   r   pandas._testing_testingrD   pandas.api.typesr   pandas.tests.extensionr   r   fixturer   r   r!   r(   r*   r/   BaseDtypeTestsr1   BaseInterfaceTestsr8   BaseConstructorsTestsrN   BaseReshapingTestsrX   BaseGetitemTestsrZ   BaseSetitemTestsr_   BaseIndexTestsra   BaseMissingTestsrc   BaseReduceTestsre   BaseAccumulateTestsrg   BaseMethodsTestsri   BaseCastingTestsr   BaseArithmeticOpsTestsr   BaseComparisonOpsTestsr   BaseParsingTestsr   NDArrayBacked2DTestsr   r   r   r   <module>r      s#                          - - - - - - ' ' ' ' ' '      $ $ $ & & &
 R R R N N N C C C	 	 	 	 	# 	 	 	0 0 0 0 0D+ 0 0 0>4 4 4 4 4t1 4 4 4	 	 	 	 	D+ 	 	 	* * * * *$' * * *	 	 	 	 	$' 	 	 		 	 	 	 	# 	 	 		 	 	 	 	$' 	 	 		 	 	 	 	% 	 	 		 	 	 	 	T- 	 	 	6 6 6 6 6$' 6 6 68	 	 	 	 	$' 	 	 	= = = = =3 = = =.> > > > >3 > > >	 	 	 	 	$' 	 	 	. . . . .4, . . . . .r   