
    bMh?$                       d Z ddlmZ ddlZddlmZ ddlZddlZddl	m
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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&d 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/`.

    )annotationsN)cast)HAS_PYARROW)StorageExtensionDtypeis_string_dtype)ArrowStringArrayStringDtype)basec                8   |s| S | j         j        dk    r| S t          j        d          }| j        }t          |          dz  }|                    g |d |         j        ||d          j                  }|j        dk    sJ  t          |           |          S )Npyarrow   )
dtypestoragepytestimportorskip	_pa_arraylenchunked_arraychunks
num_chunkstype)arrchunkedpaarrow_arraysplits        b/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pandas/tests/extension/test_string.pymaybe_split_arrayr    $   s     
		i	'	'
		Y	'	'B-K!E""B+fuf

$B{566':'AB K !Q&&&&499[!!!    TF)paramsc                    | j         S N)param)requests    r   r   r   5   s
    =r!   c                .    | \  }}t          ||          S )N)r   na_valuer
   )string_dtype_argumentsr   r(   s      r   r   r   :   s    .GXw::::r!   c                   t           j                            d                              t	          t
          j                  d          }|d         |d         k    r]t           j                            d                              t	          t
          j                  d          }|d         |d         k    ]|                                                     ||           }t          ||          S )Nr   d   )sizer      r   )
nprandomdefault_rngchoiceliststringascii_lettersconstruct_array_type_from_sequencer    )r   r   stringsr   s       r   datar9   @   s    i##A&&--d63G.H.Hs-SSG
!*

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

"
" 
$
$
&
&
5
5gU
5
K
KCS'***r!   c                    |                                                      t          j        dg|           }t	          ||          S )zLength 2 array with [NA, Valid]Ar.   r6   r7   pdNAr    r   r   r   s      r   data_missingr@   J   s>     
$
$
&
&
5
5rucl%
5
P
PCS'***r!   c                x    |                                                      g d|           }t          ||          S )N)BCr;   r.   )r6   r7   r    r?   s      r   data_for_sortingrD   Q   s:    

$
$
&
&
5
5oooU
5
S
SCS'***r!   c                    |                                                      dt          j        dg|           }t	          ||          S )NrB   r;   r.   r<   r?   s      r   data_missing_for_sortingrF   W   s?    

$
$
&
&
5
5sBE36Gu
5
U
UCS'***r!   c           
         |                                                      ddt          j        t          j        ddddg|           }t	          ||          S )NrB   r;   rC   r.   r<   r?   s      r   data_for_groupingrH   ]   sT    

$
$
&
&
5
5	c25"%c34E 6  C S'***r!   c                       e Zd Z fdZd Z fdZ fdZ fdZd Z fdZ	 fdZ
d	 Zd
 ZddZddZddZddZd Z fdZ fdZ xZS )TestStringArrayc                &   t                                          |           |j        t          j        u r|d|j         dk    sJ d S |j        dk    r=t          j        t                    5  |dk    sJ 	 d d d            d S # 1 swxY w Y   d S d S )Nzstring[]r   zstring[pyarrow_numpy])	supertest_eq_with_strr(   r=   r>   r   tmassert_produces_warningFutureWarning)selfr   	__class__s     r   rN   z TestStringArray.test_eq_with_strf   s      '''>RU""6em666666666]i''+M:: 8 8 7777778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 ('s   -	BBBc                (    t          |          sJ d S r$   r   )rR   r   s     r   test_is_not_string_typez'TestStringArray.test_is_not_string_typep   s     u%%%%%%%r!   c                    |j         t          j        u r1|s/t          |                              |j                  }|du sJ d S t                                          |           d S )NF)r(   r/   nanr   is_dtypenamerM   test_is_dtype_from_name)rR   r   using_infer_stringresultrS   s       r   rZ   z'TestStringArray.test_is_dtype_from_nameu   sb    >RV##,>#%[[))%*55FU??????GG++E22222r!   c                   |j         t          j        u rR|sPt          j        t
          d          5  |                    |j                   d d d            d S # 1 swxY w Y   d S t                      	                    |           d S )Nz Cannot construct a 'StringDtype'match)
r(   r/   rW   r   raises	TypeErrorconstruct_from_stringrY   rM   #test_construct_from_string_own_name)rR   r   r[   rS   s      r   rc   z3TestStringArray.test_construct_from_string_own_name|   s    >RV##,>#y0RSSS 8 8++EJ7778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 GG77>>>>>s   AA!Ac                    |j         j        dk    rt          j        d           t	                                          |           d S Nr   /2D support not implemented for ArrowStringArrayreason)r   r   r   skiprM   	test_viewrR   r9   rS   s     r   rj   zTestStringArray.test_view   sE    :**KPQQQQ$r!   c                    d S r$    rR   r9   s     r   test_from_dtypezTestStringArray.test_from_dtype   s    r!   c                    |j         j        dk    rt          j        d           t	                                          |           d S re   )r   r   r   ri   rM   test_transposerk   s     r   rq   zTestStringArray.test_transpose   sE    :**KPQQQQt$$$$$r!   c                    |j         j        dk    rt          j        d           t	                                          |           d S re   )r   r   r   ri   rM   test_setitem_preserves_viewsrk   s     r   rs   z,TestStringArray.test_setitem_preserves_views   sE    :**KPQQQQ,,T22222r!   c                j    |                                 }|dg         }t          j        ||           d S )Nr-   )dropnarO   assert_extension_array_equal)rR   r@   r\   expecteds       r   test_dropna_arrayz!TestStringArray.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fillnarO   rv   )rR   r9   validr\   s       r   test_fillna_no_op_returns_copyz.TestStringArray.test_fillna_no_op_returns_copy   s    TYY[[L!QU##T!!!!
'555J//T!!!!
'55555r!   op_namestrreturn4type[Exception] | tuple[type[Exception], ...] | Nonec                H    |dv rt           S |dv rt           S |dv rt           S d S )N)__mod____rmod__
__divmod____rdivmod____pow____rpow__)__mul____rmul__)__truediv____rtruediv____floordiv____rfloordiv____sub____rsub__)ra   )rR   r   objothers       r   _get_expected_exceptionz'TestStringArray._get_expected_exception   sO      
 
 
 /// 
 
 
 tr!   ser	pd.Seriesboolc                B    |dv p|j         j        t          j        u o|dv S )N)minmaxsum)anyall)r   r(   r/   rW   rR   r   r   s      r   _supports_reductionz#TestStringArray._supports_reduction   s1    ,, *y!RV+ *>)	
r!   c                B    t          |j        t                    sJ |dv S )N)cummincummaxcumsum)
isinstancer   r   r   s      r   _supports_accumulationz&TestStringArray._supports_accumulation   s'    #)%:;;;;;888r!   c                    t          t          t          j        |                    }|dv r|}n0|j        t
          j        u rt
          j        }n|j        dk    rd}nd}|	                    |          S )N)__add____radd__r   zboolean[pyarrow]boolean)
r   r   rO   	get_dtyper(   r/   rW   bool_r   astype)rR   r   r   r   pointwise_resultr   cast_tos          r   _cast_pointwise_resultz&TestStringArray._cast_pointwise_result   ss    [",s"3"344---GG^rv%%hGG]i''(GGG&&w///r!   c                ^    t          j        |          }|                     |||d           d S )Nabc)r=   Series_compare_other)rR   r9   comparison_opr   s       r   test_compare_scalarz#TestStringArray.test_compare_scalar   s/    iooC}e<<<<<r!   c                .   t           |d                    j        }|rS|j        t          j        u r@|j        dk    r5t          j                            d          }|	                    |           t                                          |           d S )Nr-   pythonmThe pointwise operation result will be inferred to string[nan, pyarrow], which does not match the input dtyperg   )nextr   r(   r=   r>   r   r   markxfailapplymarkerrM   test_combine_add)rR   data_repeatedr[   r&   r   r   rS   s         r   r   z TestStringArray.test_combine_add   s    ]]1%%&&, 	&^ru$$%-8*C*C;$$M %  D %%%  /////r!   c                   |j         }|r`|dk    rZ|j        t          j        u s|j        dk    r<t
          r5t          j                            d          }|	                    |           t                                          ||           d S )Nr   r   r   rg   )r   r(   r=   r>   r   r   r   r   r   r   rM   test_arith_series_with_array)rR   r9   all_arithmetic_operatorsr[   r&   r   r   rS   s          r   r   z,TestStringArray.test_arith_series_with_array   s     
	&(J6625((emx.G.GK.G ;$$M %  D %%%,,T3KLLLLLr!   )r   r   r   r   )r   r   r   r   r   r   )r   r   )__name__
__module____qualname__rN   rU   rZ   rc   rj   ro   rq   rs   rx   r   r   r   r   r   r   r   r   __classcell__)rS   s   @r   rJ   rJ   e   s       8 8 8 8 8& & &
3 3 3 3 3? ? ? ? ?         
  % % % % %
3 3 3 3 3
: : :

6 
6 
6   6
 
 
 
9 9 9 9
0 
0 
0 
0= = =
0 
0 
0 
0 
0M M M M M M M M Mr!   rJ   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 )Nrf   rg   )r   r	   r   ri   rn   s     r   arrow_not_supportedz Test2DCompat.arrow_not_supported   s<    d,-- 	RKPQQQQQQ	R 	Rr!   N)r   r   r   r   fixturer   rm   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.r^   )taker=   r>   r   r   r`   
ValueErrorsearchsorted)rD   	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__
__future__r   r4   typingr   numpyr/   r   pandas.compatr   pandas.core.dtypes.baser   pandasr=   pandas._testing_testingrO   pandas.api.typesr   pandas.core.arraysr	   pandas.core.arrays.string_r   pandas.tests.extensionr   r    r   r   r   r9   r@   rD   rF   rH   ExtensionTestsrJ   Dim2CompatTestsr   r   rm   r!   r   <module>r      sU    # " " " " "             % % % % % % 9 9 9 9 9 9           , , , , , , / / / / / / 2 2 2 2 2 2 ' ' ' ' ' '" " "" e}%%%  &% ; ; ;
 + + + + + + + + +
 + + +
 + + +TM TM TM TM TMd) TM TM TMnR R R R R4' R R R    r!   