a
    é´«j[F  ã                   @   s^  d 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d„ Zejd	d
„ ƒZejdejgd�dd„ ƒZejdd„ ƒZejdejgd�dd„ ƒZejdejgd�dd„ ƒZejdejgd�dd„ ƒZejdejgd�dd„ ƒZejdd„ ƒZejdejgd�dd„ ƒZejdejgd�dd„ ƒZG dd„ dejƒZd 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/`.

é    N)ÚPerformanceWarning©ÚSparseDtype)ÚSparseArray)Úbasec                 C   sh   t j d¡}t  | ¡r$|jdd�}n2|jdddtd�}|d |d krV|d  d7  < | |dd d…< |S )Né   éd   )Úsizeé   )r	   Údtyper   é   )ÚnpÚrandomZdefault_rngÚisnanÚuniformZintegersÚint)Ú
fill_valueÚrngÚdata© r   úa/var/www/html/laksyashrimp/venv/lib/python3.9/site-packages/pandas/tests/extension/test_sparse.pyÚ	make_data   s    
r   c                   C   s   t ƒ S ©Nr   r   r   r   r   r   *   s    r   )Úparamsc                 C   s   t t| jƒ| jd�}|S )z*Length-100 PeriodArray for semantics test.©r   )r   r   Úparam)ÚrequestÚresr   r   r   r   /   s    r   c                   C   s   t t d¡d ƒS )Nr   r   )r   r   Zonesr   r   r   r   Údata_for_twos6   s    r   c                 C   s   t tjdg| jd�S )zLength 2 array with [NA, Valid]r
   r   ©r   r   Únanr   ©r   r   r   r   Údata_missing;   s    r"   c                 #   s   ‡ fdd„}|V  dS )z1Return different versions of data for count timesc                 3   s(   t | ƒD ]}ttˆ jƒˆ jd�V  qd S )Nr   )Úranger   r   r   )ÚcountÚ_r!   r   r   ÚgenE   s    zdata_repeated.<locals>.genNr   )r   r&   r   r!   r   Údata_repeatedA   s    r'   c                 C   s   t g d¢| jd�S )N)r   r   r
   r   )r   r   r!   r   r   r   Údata_for_sortingL   s    r(   c                 C   s   t dtjdg| jd�S )Nr   r
   r   r   r!   r   r   r   Údata_missing_for_sortingQ   s    r)   c                   C   s   dd„ S )Nc                 S   s   t  | ¡ot  |¡S r   )ÚpdÚisna)ÚleftÚrightr   r   r   Ú<lambda>X   ó    zna_cmp.<locals>.<lambda>r   r   r   r   r   Úna_cmpV   s    r0   c              	   C   s"   t ddtjtjddddg| jd�S )Nr
   r   r   r   r   r!   r   r   r   Údata_for_grouping[   s    r1   c                 C   s$   t ddtjdddddddg
| jd�S )Nr   éþÿÿÿéÿÿÿÿé   r   r   r   r   r!   r   r   r   Údata_for_compare`   s    r5   c                       sd  e Zd Zeedœdd„Zej dddg¡‡ fdd„ƒZ	ej dddg¡‡ fd	d
„ƒZ
dd„ Zdd„ Zej d¡ej dddgejjddgddgd�g¡ej dddg¡‡ fdd„ƒƒƒZ‡ fdd„Z‡ fdd„Z‡ fdd „Z‡ fd!d"„Z‡ fd#d$„Z‡ fd%d&„Zd'd(„ Z‡ fd)d*„Zd+d,„ Z‡ fd-d.„Z‡ fd/d0„Zejjd1d2�‡ fd3d4„ƒZd5d6„ Zd7Z d8d9„ Z!d:d;„ Z"ejjd<d2�‡ fd=d>„ƒZ#d?d@„ Z$‡ fdAdB„Z%dCdD„ Z&ej dEdFdGg¡‡ fdHdI„ƒZ'ejj(ej dJej)ej*ej+g¡‡ fdKdL„ƒƒZ,ejj(‡ fdMdN„ƒZ-ej dOdPdQ„ dRe.dSe/j0gƒfdTdQ„ dUe.dSe/j0gƒfedRe.dVdWgdWdX�fedUe.dVe/j0gƒfg¡dYdZ„ ƒZ1ej d[dRdUg¡d\d]„ ƒZ2ejje3d^d_�‡ fd`da„ƒZ4dRZ5dRZ6dRZ7dRZ8dbdc„ Z9‡ fddde„Z:‡ fdfdg„Z;‡ fdhdi„Z<ej*e.djœdkdl„Z=e.dmœdndo„Z>e.dmœdpdq„Z?e.dmœdrds„Z@ejjdtd2�‡ fdudv„ƒZAejjdwd2�ej dxddg¡‡ fdydz„ƒƒZB‡  ZCS ){ÚTestSparseArray)Úop_nameÚreturnc                 C   s   dS )NTr   )ÚselfÚobjr7   r   r   r   Ú_supports_reductionf   s    z#TestSparseArray._supports_reductionÚskipnaTFc                    sj   |dv r$t jjdd�}|j |¡ n2|dv rV|jjdkrV|sVt jjdd�}|j |¡ tƒ  |||¡ d S )N©ÚprodZmedianÚvarZstdZsemZskewZkurtú,This should be viable but is not implemented©Úreason©ÚsumÚmaxÚminÚmeanÚfzgetting a non-nan float)	ÚpytestÚmarkÚxfailÚnodeÚ
add_markerr   ÚkindÚsuperÚtest_reduce_series_numeric©r9   r   Zall_numeric_reductionsr<   r   rJ   ©Ú	__class__r   r   rP   i   s    	ÿÿ
þýz*TestSparseArray.test_reduce_series_numericc                    sj   |dv r$t jjdd�}|j |¡ n2|dv rV|jjdkrV|sVt jjdd�}|j |¡ tƒ  |||¡ d S )Nr=   r@   rA   rC   rH   z$ExtensionArray NA mask are different)	rI   rJ   rK   rL   rM   r   rN   rO   Útest_reduce_framerQ   rR   r   r   rT   ‚   s    	ÿÿ
þýz!TestSparseArray.test_reduce_framec                 C   s   |j ttdƒkrt d¡ d S )Nr   zCan't store nan in int array.)r   r   r   rI   Úskip©r9   r   r   r   r   Ú_check_unsupported›   s    z"TestSparseArray._check_unsupportedc                 C   sx   t  d|d d… i¡}t  dg d¢i¡}t  dg d¢i¡ d¡}|||g}t  |¡}t  dd„ |D ƒ¡}t ||¡ d S )NÚAr   )r
   r   r   )ÚaÚbÚcÚcategoryc                 S   s   g | ]}|  d d„ ¡‘qS )c                 S   s   t  | ¡ t¡S r   )r   ÚasarrayÚastypeÚobject)Úsr   r   r   r.   ª   r/   zETestSparseArray.test_concat_mixed_dtypes.<locals>.<listcomp>.<lambda>)Úapply)Ú.0Úxr   r   r   Ú
<listcomp>ª   r/   z<TestSparseArray.test_concat_mixed_dtypes.<locals>.<listcomp>)r*   Ú	DataFramer^   ÚconcatÚtmÚassert_frame_equal)r9   r   Zdf1Zdf2Zdf3ÚdfsÚresultÚexpectedr   r   r   Útest_concat_mixed_dtypesŸ   s    

ÿz(TestSparseArray.test_concat_mixed_dtypesz9ignore:The previous implementation of stack is deprecatedÚcolumnsrX   ÚB)rX   rY   )rX   rZ   ÚouterÚinner)ÚnamesÚfuture_stackc                    s   t ƒ  |||¡ d S r   )rO   Ú
test_stack)r9   r   rm   rr   rR   r   r   rs   ®   s    zTestSparseArray.test_stackc                    s   |   |¡ tƒ  ||¡ d S r   )rW   rO   Útest_concat_columns©r9   r   Úna_valuerR   r   r   rt   ¾   s    
z#TestSparseArray.test_concat_columnsc                    s   |   |¡ tƒ  ||¡ d S r   )rW   rO   Ú'test_concat_extension_arrays_copy_falseru   rR   r   r   rw   Â   s    
z7TestSparseArray.test_concat_extension_arrays_copy_falsec                    s   |   |¡ tƒ  ||¡ d S r   )rW   rO   Ú
test_alignru   rR   r   r   rx   Æ   s    
zTestSparseArray.test_alignc                    s   |   |¡ tƒ  ||¡ d S r   )rW   rO   Útest_align_frameru   rR   r   r   ry   Ê   s    
z TestSparseArray.test_align_framec                    s   |   |¡ tƒ  ||¡ d S r   )rW   rO   Útest_align_series_frameru   rR   r   r   rz   Î   s    
z'TestSparseArray.test_align_series_framec                    s   |   |¡ tƒ  ||¡ d S r   )rW   rO   Ú
test_mergeru   rR   r   r   r{   Ò   s    
zTestSparseArray.test_mergec                 C   sˆ   t j|dd„ tt|ƒƒD ƒd�}t |jj¡rTt | d¡¡rNt |j	d ¡slJ ‚n| d¡|j	d kslJ ‚| d¡|j	d ks„J ‚d S )Nc                 S   s   g | ]}d | ‘qS )r   r   )rb   Úir   r   r   rd   ×   r/   z,TestSparseArray.test_get.<locals>.<listcomp>)Úindexr4   r   r
   )
r*   ÚSeriesr#   Úlenr   r   Úvaluesr   ÚgetÚiloc)r9   r   Úserr   r   r   Útest_getÖ   s
     &zTestSparseArray.test_getc                    s   |   |¡ tƒ  ||¡ d S r   )rW   rO   Útest_reindexru   rR   r   r   r…   Þ   s    
zTestSparseArray.test_reindexc                 C   s„   t |ƒ}ttt |jj¡ƒ}t ddg|d�}| ¡ }t ||¡ | 	d¡}ttt |jj¡ƒ}t ddgd|d�}t 
| ¡ |¡ d S )NTF©r   r   ©r   r   )r   r   Úboolr*   r+   r   r   rg   Zassert_sp_array_equalÚfillnaÚassert_equal)r9   r"   ZsarrZexpected_dtyperk   rj   r   r   r   Ú	test_isnaâ   s    
zTestSparseArray.test_isnac                    sF   t tf}tj|dd�� tƒ  |¡ W d   ƒ n1 s80    Y  d S ©NF)Zcheck_stacklevel)r   ÚFutureWarningrg   Úassert_produces_warningrO   Útest_fillna_limit_backfill)r9   r"   ZwarnsrR   r   r   r�   ï   s    z*TestSparseArray.test_fillna_limit_backfillc                    s0   t  |j¡r | tjjdd�¡ tƒ  |¡ d S )Nz'returns array with different fill valuerA   )	r   r   r   ÚapplymarkerrI   rJ   rK   rO   Útest_fillna_no_op_returns_copy)r9   r   r   rR   r   r   r‘   ô   s
    ÿz.TestSparseArray.test_fillna_no_op_returns_copyZUnsupportedrA   c                    s   t ƒ  ¡  d S r   )rO   Útest_fillna_series©r9   r"   rR   r   r   r’   û   s    z"TestSparseArray.test_fillna_seriesc                 C   st   |d }t  |ddgdœ¡ |¡}t  |j¡r<t|j|ƒ}n|j}t  |j||g|d�ddgdœ¡}t 	||¡ d S )Nr
   r   )rX   rn   r†   )
r*   re   r‰   r+   r   r   r   Ú_from_sequencerg   rh   )r9   r"   r   rj   r   rk   r   r   r   Útest_fillna_frame  s    þÿz!TestSparseArray.test_fillna_framezSparse[bool]c                 C   sŠ   |  ddg¡}tjd|idd�}|jd }| |¡}t|jdƒrn|rZ|jj|jju snJ ‚n|jj|jjusnJ ‚|j	j
 ¡ | ¡ u s†J ‚d S )Nr
   rX   F©Úcopy)r   r   Úblocks)Útaker*   re   r‚   r‰   ÚhasattrZ_mgrr€   r   rX   Ú_valuesÚto_dense)r9   r"   Úusing_copy_on_writeÚarrZdfÚ
filled_valrj   r   r   r   Útest_fillna_copy_frame  s    

z&TestSparseArray.test_fillna_copy_framec                 C   sn   |  ddg¡}tj|dd�}|d }| |¡}|rD|j|ju sTJ ‚n|j|jusTJ ‚|j ¡ | ¡ u sjJ ‚d S )Nr
   Fr–   r   )r™   r*   r~   r‰   r›   rœ   )r9   r"   r�   rž   rƒ   rŸ   rj   r   r   r   Útest_fillna_copy_series&  s    
z'TestSparseArray.test_fillna_copy_serieszNot Applicablec                    s   t ƒ  |¡ d S r   )rO   Útest_fillna_length_mismatchr“   rR   r   r   r¢   4  s    z+TestSparseArray.test_fillna_length_mismatchc                 C   sô   |d |d ksJ ‚t |ƒ}|d d… \}}t |j||||g|jd�¡}t g d¢¡}| |¡}tddƒ}	t |j||||g|	d�¡}
t	 
||
¡ |j||||g|jd�}t g d¢¡}| ||¡}t |j||||g|jd�¡}
t	 
||
¡ d S )	Nr   r
   r   r†   )TTFFÚfloatg        )TFTT)Útyper*   r~   r”   r   r   ÚarrayÚwherer   rg   Zassert_series_equal)r9   r   rv   ÚclsrY   rZ   rƒ   Zcondrj   Z	new_dtyperk   Úotherr   r   r   Útest_where_series8  s     

ÿz!TestSparseArray.test_where_seriesc                    s@   t jtdd�� tƒ  ||¡ W d   ƒ n1 s20    Y  d S rŒ   )rg   rŽ   r   rO   Útest_searchsorted)r9   r(   Ú	as_seriesrR   r   r   rª   N  s    z!TestSparseArray.test_searchsortedc                 C   s6   |  d¡}|jd |jd< |jd |jd ks2J ‚d S )Nr   r
   )ÚshiftZ_sparse_values)r9   r   rj   r   r   r   Útest_shift_0_periodsR  s    
z$TestSparseArray.test_shift_0_periodsÚmethodZargmaxZargminc                    s   |   |¡ tƒ  |||¡ d S r   )rW   rO   Útest_argmin_argmax_all_na)r9   r®   r   rv   rR   r   r   r¯   Y  s    
z)TestSparseArray.test_argmin_argmax_all_naÚboxc                    s    |   |¡ tƒ  ||||¡ d S r   )rW   rO   Útest_equals)r9   r   rv   r«   r°   rR   r   r   r±   _  s    
zTestSparseArray.test_equalsc                    s   t ƒ  |¡ d S r   )rO   Ú&test_equals_same_data_different_objectrV   rR   r   r   r²   e  s    z6TestSparseArray.test_equals_same_data_different_objectzfunc, na_action, expectedc                 C   s   | S r   r   ©rc   r   r   r   r.   l  r/   zTestSparseArray.<lambda>Ng      ð?c                 C   s   | S r   r   r³   r   r   r   r.   m  r/   Úignorez1.0r    r   c                 C   s,   t dtjgƒ}|j||d�}t ||¡ d S )Nr
   ©Ú	na_action)r   r   r    Úmaprg   Zassert_extension_array_equal)r9   Úfuncr¶   rk   r   rj   r   r   r   Útest_mapi  s    zTestSparseArray.test_mapr¶   c                 C   sH   d}t jt|d��" |jdd„ |d� W d   ƒ n1 s:0    Y  d S )Nz-fill value in the sparse values not supported)Úmatchc                 S   s   t jS r   )r   r    r³   r   r   r   r.   }  r/   z1TestSparseArray.test_map_raises.<locals>.<lambda>rµ   )rI   ÚraisesÚ
ValueErrorr·   )r9   r   r¶   Úmsgr   r   r   Útest_map_raisesx  s    zTestSparseArray.test_map_raiseszno sparse StringDtype)r»   rB   c                    s   t ƒ  |¡ d S r   )rO   Útest_astype_string)r9   r   Znullable_string_dtyperR   r   r   r¿     s    z"TestSparseArray.test_astype_stringc                 C   s   |j dkrt d¡ d S )Nr   z=Incorrected expected from Series.combine and tested elsewhere)r   rI   rU   rV   r   r   r   Ú_skip_if_different_combineŠ  s    
z*TestSparseArray._skip_if_different_combinec                    s   |   |¡ tƒ  ||¡ d S r   )rÀ   rO   Útest_arith_series_with_scalar©r9   r   Úall_arithmetic_operatorsrR   r   r   rÁ   ‘  s    
z-TestSparseArray.test_arith_series_with_scalarc                    s   |   |¡ tƒ  ||¡ d S r   )rÀ   rO   Útest_arith_series_with_arrayrÂ   rR   r   r   rÄ   •  s    
z,TestSparseArray.test_arith_series_with_arrayc                    sF   |j jdkrn&| d¡dvr4tjjdd�}| |¡ tƒ  ||¡ d S )Nr   r%   )ÚmulZrmulÚfloordivZ	rfloordivÚpowÚmodZrmodz result dtype.fill_value mismatchrA   )	r   r   ÚstriprI   rJ   rK   r�   rO   Útest_arith_frame_with_scalar)r9   r   rÃ   r   rJ   rR   r   r   rÊ   ™  s    	
z,TestSparseArray.test_arith_frame_with_scalar)rƒ   r5   c           	      C   sþ   |}|||ƒ}t |tjƒr<t |tjƒs*J ‚t |jtƒsJJ ‚nt |tƒsJJ ‚|jjtjks\J ‚t |tjƒrš||j	|j
j	ƒ}t|| ¡ t |¡ƒ|tjd�}n>t |t |j	¡t |¡ƒ¡}t|| ¡ t |¡ƒ|tjd�}t |tjƒrît |¡}t ||¡ d S )Nr‡   )Ú
isinstancer*   r~   r   r   r   Úsubtyper   Zbool_r   r›   rœ   r]   Úallrg   rŠ   )	r9   rƒ   r5   Úcomparison_opr¨   Úoprj   r   rk   r   r   r   Ú_compare_other©  s2    
ýÿý
zTestSparseArray._compare_other)r5   c                 C   sP   t  |¡}|  |||d¡ |  |||d¡ |  |||d¡ |  |||tj¡ d S )Nr   r
   r3   )r*   r~   rÐ   r   r    )r9   r5   rÎ   rƒ   r   r   r   Útest_scalarÍ  s
    
zTestSparseArray.test_scalarc                 C   sZ   |j jdkr.|jdv r.tjjdd�}| |¡ t ddd¡}t	 
|¡}|  ||||¡ d S )Nr   )ÚeqÚgeÚleúWrong fill_valuerA   éüÿÿÿé   é
   )r   r   Ú__name__rI   rJ   rK   r�   r   Zlinspacer*   r~   rÐ   )r9   r5   rÎ   r   rJ   rž   rƒ   r   r   r   Ú
test_arrayÔ  s    

zTestSparseArray.test_arrayc                 C   sl   |j jdkr.|jdkr.tjjdd�}| |¡ t |¡}|d }|  	||||¡ |d }|  	||||¡ d S )Nr   ÚgtrÕ   rA   r
   r   )
r   r   rÙ   rI   rJ   rK   r�   r*   r~   rÐ   )r9   r5   rÎ   r   rJ   rƒ   rž   r   r   r   Útest_sparse_arrayá  s    

z!TestSparseArray.test_sparse_arrayzDifferent reprc                    s   t ƒ  ||¡ d S r   )rO   Útest_array_repr)r9   r   r	   rR   r   r   rÝ   ì  s    zTestSparseArray.test_array_reprzresult does not match expectedÚas_indexc                    s   t ƒ  ||¡ d S r   )rO   Útest_groupby_extension_agg)r9   rÞ   r1   rR   r   r   rß   ð  s    z*TestSparseArray.test_groupby_extension_agg)DrÙ   Ú
__module__Ú__qualname__Ústrrˆ   r;   rI   rJ   ZparametrizerP   rT   rW   rl   Úfilterwarningsr*   Z
MultiIndexÚfrom_tuplesrs   rt   rw   rx   ry   rz   r{   r„   r…   r‹   r�   r‘   rK   r’   r•   Z_combine_le_expected_dtyper    r¡   r¢   r©   rª   r­   r¯   Zfails_arm_wheelsr¥   r~   re   r±   r²   r   r   r    r¹   r¾   Ú	TypeErrorr¿   Zseries_scalar_excZframe_scalar_excZ
divmod_excZseries_array_excrÀ   rÁ   rÄ   rÊ   rÐ   rÑ   rÚ   rÜ   rÝ   rß   Ú__classcell__r   r   rR   r   r6   e   s    ÿÿþþ	üþ	

ÿ$r6   c                 C   s   |   ¡ tu sJ ‚d S r   )Zconstruct_array_typer   r†   r   r   r   Útest_array_type_with_argö  s    rç   ) Ú__doc__Únumpyr   rI   Zpandas.errorsr   Zpandasr*   r   Zpandas._testingZ_testingrg   Zpandas.arraysr   Zpandas.tests.extensionr   r   Zfixturer   r    r   r   r"   r'   r(   r)   r0   r1   r5   ZExtensionTestsr6   rç   r   r   r   r   Ú<module>   sD   










   