
    d%                        d Z ddlZddlZddlZddlZddlmZmZ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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j0                  Z1 G d& d'ej2                  Z3 G d( d)ej4                  Z5 G d* d+ej6                  Z7 G d, d-ej8                  Z9d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CategoricalIndex	TimestampCategoricalDtype)basec                      	 t           j                            t          t          j                  d          } | d         | d         k    rnL| S )NTd   )sizer      )nprandomchoiceliststringascii_letters)valuess    c/var/www/html/t/fyr/venv311/lib/python3.11/site-packages/pandas/tests/extension/test_categorical.py	make_datar       sP    !!$v';"<"<3!GG !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   0   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    :   s     }%%%r   c                  .    t          g dg dd          S )N)r   BC)r#   r   r"   T
categoriesorderedr   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*   E   s"    '''S#JMMMMr   c                      t           j        S r   )r   r   r   r   r   na_valuer,   J   s	    6Mr   c                  $    t          g d          S )N)ar.   NNbr/   r.   cr'   r   r   r   data_for_groupingr1   O   s    AAABBBr   c                       e Zd ZdS )	TestDtypeN__name__
__module____qualname__r   r   r   r3   r3   T           Dr   r3   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_usageY   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   r,   isnatmNULL_OBJECTS)rA   r   r    r,   na_value_objs        r   test_containszTestInterface.test_contains^   s    
 :&TYY[[L! Aw$A,.... <''''t#### O 	0 	0Lx''t++++</////		0 	0r   )	r5   r6   r7   pytestmarkxfailr?   rH   __classcell__rB   s   @r   r:   r:   X   sf        [:;;( ( ( ( <;(0 0 0 0 0 0 0r   r:   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   )rA   r   clsresults       r   
test_emptyzTestConstructors.test_emptyx   sb    ((**D..&#&&&&& |/33333333r   N)r5   r6   r7   rX   r   r   r   rO   rO   w   s#        4 4 4 4 4r   rO   c                       e Zd ZdS )TestReshapingNr4   r   r   r   rZ   rZ      r8   r   rZ   c                   `     e Zd Zej                            d           fd            Z xZS )TestGetitemzBackwards compatibilityr;   c                 J    t                                          |           d S r   )r>   test_getitem_scalarr@   s     r   r^   zTestGetitem.test_getitem_scalar   s#    
 	##D)))))r   )r5   r6   r7   rI   rJ   skipr^   rL   rM   s   @r   r\   r\      sW        [677* * * * 87* * * * *r   r\   c                       e Zd ZdS )TestSetitemNr4   r   r   r   ra   ra      r8   r   ra   c                       e Zd ZdS )	TestIndexNr4   r   r   r   rc   rc      r8   r   rc   c                       e Zd ZdS )TestMissingNr4   r   r   r   re   re      r8   r   re   c                       e Zd ZdS )
TestReduceNr4   r   r   r   rg   rg      r8   r   rg   c                   Z    e Zd Zej                            dddg          d             ZdS )TestAccumulateskipnaTFc                     d S r   r   )rA   r   all_numeric_accumulationsrj   s       r   test_accumulate_seriesz%TestAccumulate.test_accumulate_series   s    r   N)r5   r6   r7   rI   rJ   parametrizerm   r   r   r   ri   ri      sD        [Xe}55  65  r   ri   c                   f     e Zd Zej                            d           fd            Zd Z xZS )TestMethodszUnobserved categories includedr;   c                 H    t                                          ||          S r   )r>   test_value_counts)rA   all_datadropnarB   s      r   rr   zTestMethods.test_value_counts   s    ww((6:::r   c           	      (    |d          \  }}t          j        |          }t          j        |          }|                    |d           }t          j        d t          t	          |          t	          |                    D                       }|                     ||           |j        d         |                    d           }t          j        fdt	          |          D                       }|                     ||           d S )N   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   rx   s     r   r{   z.TestMethods.test_combine_add.<locals>.<lambda>   s
    R r   c                     g | ]}|z   S r   r   )r}   r.   vals     r   r~   z0TestMethods.test_combine_add.<locals>.<listcomp>   s    @@@!a#g@@@r   )pdSeriescombinezipr   assert_series_equaliloc)	rA   data_repeated
orig_data1
orig_data2s1s2rW   expectedr   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
 
 	  222gajC!7!7889@@@@tJ/?/?@@@AA  22222r   )	r5   r6   r7   rI   rJ   rK   rr   r   rL   rM   s   @r   rp   rp      sg        [>??; ; ; ; @?;3 3 3 3 3 3 3r   rp   c                      e Zd Zej                            deeg          ej                            ddej	        g e
d          ej        gg          d                         Zej                            d ej        ddgd	
           ej        ddgd
           ej         ej        d           ej        d          gd
           ej         ej        dd           ej        dd          gd
           ej        dej	        gd
          g          d             Zej                            dd ej        dgd
          fd ej         e
dd          g          j        fg          d             ZdS )TestCastingrV   r   r   2000c                      ||          }d}t          j        t          t          f|          5  |                    t
                     d d d            d S # 1 swxY w Y   d S )NzCannot (cast|convert)match)rI   raises
ValueError	TypeErrorastypeint)rA   rV   r   smsgs        r   test_cast_nan_to_intz TestCasting.test_cast_nan_to_int   s     CKK%]J	2#>>> 	 	HHSMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAr   20192020zdatetime64[ns, UTC]rR   r   ztimedelta64[ns]zperiod[A-DEC]rv   intervalInt64c                     |                     d                               |j                  }t          j        ||           d S )Ncategory)r   r   rE   r   )rA   r   rW   s      r   %test_cast_category_to_extension_dtypez1TestCasting.test_cast_category_to_extension_dtype   s>     ,,33HNCC
vx00000r   zdtype, expectedzdatetime64[ns]z2015-01-01T00:00:00.000000000zdatetime64[ns, MET]z2015-01-01 00:00:00+0100MET)tzc                 \    t          dg                              |          }||k    sJ d S )Nz
2015-01-01)r   r   )rA   r   r   rW   s       r   test_consistent_castingz#TestCasting.test_consistent_casting   s8    " l^,,33E::!!!!!!r   N)r5   r6   r7   rI   rJ   rn   r   r   r   r   r   r   NaTr   r   PeriodIntervalr   arrayDatetimeIndexr   r   r   r   r   r      s       [U[2B$CDD[XBFii6G6G5P'QRR  SR ED [BIvv&.CDDDBIq!f$5666BIyry(()")F*;*;<OTTTBI{r{1a((+"+a*;*;<JOOOBIq"&k111	
	 	1 1	 	1 [ !9:BRSSS
 &  Y9eDDDE 		
 " " " " "r   r   c                   B     e Zd Z fdZ fdZd Zd Zef 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 argumentr;   )node
add_markerrI   rJ   rK   r>   test_arith_frame_with_scalarrA   r   all_arithmetic_operatorsrequestop_namerB   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   rI   rJ   rK   r>   test_arith_series_with_scalarr   s        r   r   z/TestArithmeticOps.test_arith_series_with_scalar   sl    *j  L##!!L "    
 	--dG<<<<<r   c                     t          j        |          }t          j        t          d          5  ||z    d d d            d S # 1 swxY w Y   d S )Nz"cannot perform|unsupported operandr   )r   r   rI   r   r   )rA   r   sers      r   $test_add_series_with_extension_arrayz6TestArithmeticOps.test_add_series_with_extension_array  s    ioo]9,PQQQ 	 	$JJ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AA
Ac                     d S r   r   )rA   s    r   test_divmod_series_arrayz*TestArithmeticOps.test_divmod_series_array  s	     	r   c                 X    t                                          |||t                    S )N)exc)r>   _check_divmod_opr   )rA   r   opotherr   rB   s        r   r   z"TestArithmeticOps._check_divmod_op  s$    ww''2u)'DDDr   )
r5   r6   r7   r   r   r   r   NotImplementedErrorr   rL   rM   s   @r   r   r      s        	< 	< 	< 	< 	<= = = = =  
  
 2E E E E E E E E E E Er   r   c            	           e Zd Zd Zej                            dddgddg ed           ed          gg          d	             Zd
S )TestComparisonOpsc                    d|j          d}|dk    r? |||          }|                    |d           }||k                                    sJ d S |dk    r? |||          }|                    |d           }||k                                    sJ d S d}t          j        t
          |          5   |||           d d d            d S # 1 swxY w Y   d S )N____eq__c                     | |k    S r   r   xys     r   r{   z2TestComparisonOps._compare_other.<locals>.<lambda>  
    Q!V r   __ne__c                     | |k    S r   r   r   s     r   r{   z2TestComparisonOps._compare_other.<locals>.<lambda>  r   r   z7Unordered Categoricals can only compare equality or notr   )r5   r   allrI   r   r   )	rA   r   r   r   r   r   rW   r   r   s	            r   _compare_otherz TestComparisonOps._compare_other  sL   &r{&&&hR5\\Fyy(;(;<<Hh&++-------  R5\\Fyy(;(;<<Hh&++------- LCy444    4                                   s   3CCCr%   r.   r/   r   r   r   r   c                     t          j        ddg|          }t          j        ddg|          }||k    }|                                sJ d S )Nr   )r%   r   )r   
from_codesr   )rA   r%   c1c2rW   s        r   test_not_equal_with_naz(TestComparisonOps.test_not_equal_with_na"  sY     #RG
CCC#QFzBBBrzz||r   N)	r5   r6   r7   r   rI   rJ   rn   r   r   r   r   r   r   r     s             " [
saVii//61B1BCD  	   r   r   c                       e Zd ZdS )TestParsingNr4   r   r   r   r   r   0  r8   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   r   z
Categories)reprreshapecount)rA   r   ress      r   test_repr_2dzTest2DCompat.test_repr_2d5  sz     4<<2&&''yy((A----4<<A&&''yy((A------r   N)r5   r6   r7   r   r   r   r   r   r   4  s#        . . . . .r   r   ):__doc__r   numpyr   rI   pandasr   r   r   r   pandas._testing_testingrE   pandas.api.typesr   pandas.tests.extensionr   r   fixturer   r   r    r(   r*   r,   r1   BaseDtypeTestsr3   BaseInterfaceTestsr:   BaseConstructorsTestsrO   BaseReshapingTestsrZ   BaseGetitemTestsr\   BaseSetitemTestsra   BaseIndexTestsrc   BaseMissingTestsre   BaseNoReduceTestsrg   BaseAccumulateTestsri   BaseMethodsTestsrp   BaseCastingTestsr   BaseArithmeticOpsTestsr   BaseComparisonOpsTestsr   BaseParsingTestsr   NDArrayBacked2DTestsr   r   r   r   <module>r      sm                      
       - - - - - - ' ' ' ' ' '      $ $ $ & & &
 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-   3 3 3 3 3$' 3 3 3.-" -" -" -" -"$' -" -" -"`!E !E !E !E !E3 !E !E !EH    3   @	 	 	 	 	$' 	 	 	. . . . .4, . . . . .r   