
    o[we                        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dlmZ d Z ej        dd	g
          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/                  Z0 G d( d)ej1                  Z2 G d* d+ej3                  Z4 G d, d-ej5                  Z6 G d. d/ej7                  Z8 G d0 d1ej9                  Z:d2 Z;dS )3aj  
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is_string_dtype)ArrowStringArrayStringDtype)basec                 f    | j         j        dk    rt          j        d           d } ||           S )Npyarrowz-only applicable for pyarrow chunked array n/ac                     dd l }| j        }t          |          dz  }|                    g |d |         j        ||d          j                  }|j        dk    sJ  t          |           |          S )Nr      )r
   	_pa_arraylenchunked_arraychunks
num_chunkstype)arrpaarrow_arraysplits       Blib/python3.11/site-packages/pandas/tests/extension/test_string.py_split_arrayz!split_array.<locals>._split_array!   s    mK  A%&&Fk&5&!(F;uvv+>+EF
 
 %****tCyy%%%    )dtypestoragepytestskip)r   r   s     r   split_arrayr      sD    
yI%%CDDD	& 	& 	& <r   TF)paramsc                     | j         S N)param)requests    r   chunkedr$   /   s
    =r   c                 "    t          |           S )N)r   r   )string_storages    r   r   r   4   s    ~....r   c                    t           j                            d                              t	          t
          j                  d          }|d         |d         k    r]t           j                            d                              t	          t
          j                  d          }|d         |d         k    ]|                                                     |          }|rt          |          n|S )Nr   d   )sizer      )
nprandomdefault_rngchoiceliststringascii_lettersconstruct_array_type_from_sequencer   )r   r$   stringsr   s       r   datar5   9   s    i##A&&--d63G.H.Hs-SSG
!*

"
")''**11$v7K2L2LSV1WW !*

"
" 
$
$
&
&
5
5g
>
>C&/;sC/r   c                     |                                                      t          j        dg          }|rt	          |          n|S )zLength 2 array with [NA, Valid]Ar2   r3   pdNAr   r   r$   r   s      r   data_missingr<   C   sA     
$
$
&
&
5
5rucl
C
CC&/;sC/r   c                 z    |                                                      g d          }|rt          |          n|S )N)BCr7   )r2   r3   r   r;   s      r   data_for_sortingr@   J   s=    

$
$
&
&
5
5ooo
F
FC&/;sC/r   c                     |                                                      dt          j        dg          }|rt	          |          n|S )Nr>   r7   r8   r;   s      r   data_missing_for_sortingrB   P   sB    

$
$
&
&
5
5sBE36G
H
HC&/;sC/r   c           
          |                                                      ddt          j        t          j        ddddg          }|rt	          |          n|S )Nr>   r7   r?   r8   r;   s      r   data_for_groupingrD   V   sU    

$
$
&
&
5
5	c25"%c34 C  '/;sC/r   c                   $     e Zd Z fdZd Z xZS )	TestDtypec                 l    |d|j          dk    sJ t                                          |           d S )Nzstring[])r   supertest_eq_with_str)selfr   	__class__s     r   rJ   zTestDtype.test_eq_with_str_   s@    2%-2222222  '''''r   c                 (    t          |          sJ d S r!   r   )rK   r   s     r   test_is_not_string_typez!TestDtype.test_is_not_string_typec   s     u%%%%%%%r   )__name__
__module____qualname__rJ   rN   __classcell__rL   s   @r   rF   rF   ^   sG        ( ( ( ( (& & & & & & &r   rF   c                        e Zd Z fdZ xZS )TestInterfacec                     |j         j        |v rt          j        d           t	                                          |           d S Nz/2D support not implemented for ArrowStringArray)reason)r   r   r   r   rI   	test_viewrK   r5   r#   arrow_string_storagerL   s       r   rY   zTestInterface.test_viewj   sF    :!555KPQQQQ$r   )rO   rP   rQ   rY   rR   rS   s   @r   rU   rU   i   s8                         r   rU   c                       e Zd Zd ZdS )TestConstructorsc                     d S r!    )rK   r5   s     r   test_from_dtypez TestConstructors.test_from_dtypeq   s    r   N)rO   rP   rQ   r`   r_   r   r   r]   r]   p   s#            r   r]   c                        e Zd Z fdZ xZS )TestReshapingc                     |j         j        |v rt          j        d           t	                                          |           d S rW   )r   r   r   r   rI   test_transposerZ   s       r   rd   zTestReshaping.test_transposew   sF    :!555KPQQQQt$$$$$r   )rO   rP   rQ   rd   rR   rS   s   @r   rb   rb   v   s8        % % % % % % % % %r   rb   c                       e Zd ZdS )TestGetitemNrO   rP   rQ   r_   r   r   rf   rf   }           Dr   rf   c                        e Zd Z fdZ xZS )TestSetitemc                     |j         j        |v rt          j        d           t	                                          |           d S rW   )r   r   r   r   rI   test_setitem_preserves_viewsrZ   s       r   rl   z(TestSetitem.test_setitem_preserves_views   sF    :!555KPQQQQ,,T22222r   )rO   rP   rQ   rl   rR   rS   s   @r   rj   rj      s8        3 3 3 3 3 3 3 3 3r   rj   c                       e Zd ZdS )	TestIndexNrg   r_   r   r   rn   rn      rh   r   rn   c                       e Zd Zd Zd ZdS )TestMissingc                 j    |                                 }|dg         }t          j        ||           d S )Nr*   )dropnatmassert_extension_array_equal)rK   r<   resultexpecteds       r   test_dropna_arrayzTestMissing.test_dropna_array   s8    $$&&$
'99999r   c                    ||                                           }|d         }|                    |          }||usJ t          j        ||           |                    d          }||usJ t          j        ||           d S )Nr   backfill)method)isnafillnars   rt   )rK   r5   validru   s       r   test_fillna_no_op_returns_copyz*TestMissing.test_fillna_no_op_returns_copy   s    TYY[[L!QU##T!!!!
'555J//T!!!!
'55555r   N)rO   rP   rQ   rw   r~   r_   r   r   rp   rp      s2        : : :

6 
6 
6 
6 
6r   rp   c                   x    e Zd Zdej        dedefdZej	        
                    dddg          d             Zd	S )

TestReduceserop_namereturnc                 *    |j         j        dk    o|dv S )Npyarrow_numpy)anyall)r   r   )rK   r   r   s      r   _supports_reductionzTestReduce._supports_reduction   s!    I0 *>)	
r   skipnaTFc                     |}|dv rd S t          j        |          }t          j        t                    5   t          ||          |           d d d            d S # 1 swxY w Y   d S )N)minmax)r   )r9   Seriesr   raises	TypeErrorgetattr)rK   r5   all_numeric_reductionsr   r   r   s         r   test_reduce_series_numericz%TestReduce.test_reduce_series_numeric   s    (n$$4ioo]9%% 	1 	1!GC!!0000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1s   AA"%A"N)rO   rP   rQ   r9   r   strboolr   r   markparametrizer   r_   r   r   r   r      sq        
ry 
3 
4 
 
 
 
 [Xe}551 1 651 1 1r   r   c                       e Zd ZdS )TestMethodsNrg   r_   r   r   r   r      rh   r   r   c                       e Zd ZdS )TestCastingNrg   r_   r   r   r   r      rh   r   r   c                        e Zd ZdefdZd ZdS )TestComparisonOpsr   c                     t          j        |          }|j        dk    rd}n|j        dk    rt          j        }nd}|                    |          S )Nr
   zboolean[pyarrow]r   boolean)rs   	get_dtyper   r+   bool_astype)rK   r   objotherpointwise_resultr   cast_tos          r   _cast_pointwise_resultz(TestComparisonOps._cast_pointwise_result   sV    S!! =I%%(GG]o--hGGG&&w///r   c                 ^    t          j        |          }|                     |||d           d S )Nabc)r9   r   _compare_other)rK   r5   comparison_opr   s       r   test_compare_scalarz%TestComparisonOps.test_compare_scalar   s/    iooC}e<<<<<r   N)rO   rP   rQ   r   r   r   r_   r   r   r   r      s>        
0c 
0 
0 
0 
0= = = = =r   r   c                       e Zd ZdS )TestParsingNrg   r_   r   r   r   r      rh   r   r   c                       e Zd ZdS )TestPrintingNrg   r_   r   r   r   r      rh   r   r   c                   ^     e Zd Zej                            d           fd            Z xZS )TestGroupByz4ignore:Falling back:pandas.errors.PerformanceWarningc                 L    t                                          ||           d S r!   )rI   test_groupby_extension_apply)rK   rD   groupby_apply_oprL   s      r   r   z(TestGroupBy.test_groupby_extension_apply   s%    ,,->@PQQQQQr   )rO   rP   rQ   r   r   filterwarningsr   rR   rS   s   @r   r   r      s^        [ VWWR R R R XWR R R R Rr   r   c                   B    e Zd Z ej        d          d             ZdS )Test2DCompatT)autousec                 ^    t          |t                    rt          j        d           d S d S rW   )
isinstancer   r   r   )rK   r5   r#   s      r   arrow_not_supportedz Test2DCompat.arrow_not_supported   s<    d,-- 	RKPQQQQQQ	R 	Rr   N)rO   rP   rQ   r   fixturer   r_   r   r   r   r      sB        V^D!!!R R "!R R Rr   r   c                     | \  }}}|                      g d          }t          j        |d<   |rt          j        |          }d}t	          j        t          |          5  |                    |           d d d            d S # 1 swxY w Y   d S )N)r   r   r*   zOsearchsorted requires array to be sorted, which is impossible with NAs present.)match)taker9   r:   r   r   r   
ValueErrorsearchsorted)r@   	as_seriesbcar   msgs          r    test_searchsorted_with_na_raisesr      s    GAq!


			
*
*CeCG inn	0  
z	-	-	-                   s    BB
B)<__doc__r0   numpyr+   r   pandasr9   pandas._testing_testingrs   pandas.api.typesr   pandas.core.arraysr   pandas.core.arrays.string_r   pandas.tests.extensionr   r   r   r$   r   r5   r<   r@   rB   rD   BaseDtypeTestsrF   BaseInterfaceTestsrU   BaseConstructorsTestsr]   BaseReshapingTestsrb   BaseGetitemTestsrf   BaseSetitemTestsrj   BaseIndexTestsrn   BaseMissingTestsrp   BaseReduceTestsr   BaseMethodsTestsr   BaseCastingTestsr   BaseComparisonOpsTestsr   BaseParsingTestsr   BasePrintingTestsr   BaseGroupbyTestsr   Dim2CompatTestsr   r   r_   r   r   <module>r      sz                    , , , , , , / / / / / / 2 2 2 2 2 2 ' ' ' ' ' '  $ e}%%%  &% / / / 0 0 0 0 0 0 0 0 0
 0 0 0
 0 0 0& & & & &# & & &         D+          t1   % % % % %D+ % % %	 	 	 	 	$' 	 	 	3 3 3 3 3$' 3 3 3	 	 	 	 	# 	 	 	6 6 6 6 6$' 6 6 6&1 1 1 1 1% 1 1 1&	 	 	 	 	$' 	 	 		 	 	 	 	$' 	 	 	= = = = =3 = = =$	 	 	 	 	$' 	 	 		 	 	 	 	4) 	 	 	R R R R R$' R R RR R R R R4' R R R    r   