o
    Û­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�}n|jdddtd�}|d |d kr+|d  d7  < | |dd d…< |S )Né   éd   )Úsizeé   )r	   Údtyper   é   )ÚnpÚrandomÚdefault_rngÚisnanÚuniformÚintegersÚint)Ú
fill_valueÚrngÚdata© r   ú_/var/www/html/CropPilot/venv/lib/python3.10/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   Úonesr   r   r   r   Údata_for_twos6   ó   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   r"   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   r4   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   "r5   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   $r9   c                       sh  e Zd Zdedef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d0d1„Zejjd2d3�‡ fd4d5„ƒZd6d7„ Zd8Z d9d:„ Z!d;d<„ Z"ejjd=d3�‡ fd>d?„ƒZ#d@dA„ Z$‡ fdBdC„Z%dDdE„ Z&ej dFdGdHg¡‡ fdIdJ„ƒZ'ejj(ej dKej)ej*ej+g¡‡ fdLdM„ƒƒZ,ejj(‡ fdNdO„ƒZ-ej dPdQdR„ dSe.dTe/j0gƒfdUdR„ dVe.dTe/j0gƒfedSe.dWdXgdXdY�fedVe.dWe/j0gƒfg¡dZd[„ ƒZ1ej d\dSdVg¡d]d^„ ƒZ2ejje3d_d`�‡ fdadb„ƒZ4dSZ5dSZ6dSZ7dSZ8dcdd„ Z9‡ fdedf„Z:‡ fdgdh„Z;‡ fdidj„Z<dkej*dle.fdmdn„Z=dle.fdodp„Z>dle.fdqdr„Z?dle.fdsdt„Z@ejjdud3�‡ fdvdw„ƒZAejjdxd3�ej dyddg¡‡ fdzd{„ƒƒZB‡  ZCS )|ÚTestSparseArrayÚop_nameÚreturnc                 C   s   dS )NTr   )ÚselfÚobjr;   r   r   r   Ú_supports_reductionf   s   z#TestSparseArray._supports_reductionÚskipnaTFc                    ój   |dv rt jjdd�}|j |¡ n|dv r+|jjdkr+|s+t jjdd�}|j |¡ tƒ  |||¡ d S )N©ÚprodÚmedianÚvarÚstdÚsemÚskewÚ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©r=   r   Úall_numeric_reductionsr@   r   rT   ©Ú	__class__r   r   rZ   i   ó   	ÿÿz*TestSparseArray.test_reduce_series_numericc                    rA   )NrB   rJ   rK   rM   rR   z$ExtensionArray NA mask are different)	rS   rT   rU   rV   rW   r   rX   rY   Útest_reduce_framer[   r]   r   r   r`   ‚   r_   z!TestSparseArray.test_reduce_framec                 C   s"   |j ttdƒkrt d¡ d S d S )Nr   zCan't store nan in int array.)r   r   r   rS   Úskip©r=   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   r2   ª   s    zETestSparseArray.test_concat_mixed_dtypes.<locals>.<listcomp>.<lambda>)Úapply)Ú.0Úxr   r   r   Ú
<listcomp>ª   s    z<TestSparseArray.test_concat_mixed_dtypes.<locals>.<listcomp>)r.   Ú	DataFramerj   ÚconcatÚtmÚassert_frame_equal)r=   r   Údf1Údf2Údf3ÚdfsÚresultÚexpectedr   r   r   Útest_concat_mixed_dtypesŸ   s   

ÿz(TestSparseArray.test_concat_mixed_dtypesz9ignore:The previous implementation of stack is deprecatedÚcolumnsrd   ÚB)rd   re   )rd   rf   ÚouterÚinner)ÚnamesÚfuture_stackc                    s   t ƒ  |||¡ d S r   )rY   Ú
test_stack)r=   r   r|   r�   r]   r   r   r‚   ®   s   zTestSparseArray.test_stackc                    ó   |   |¡ tƒ  ||¡ d S r   )rc   rY   Útest_concat_columns©r=   r   Úna_valuer]   r   r   r„   ¾   ó   
z#TestSparseArray.test_concat_columnsc                    rƒ   r   )rc   rY   Ú'test_concat_extension_arrays_copy_falser…   r]   r   r   rˆ   Â   r‡   z7TestSparseArray.test_concat_extension_arrays_copy_falsec                    rƒ   r   )rc   rY   Ú
test_alignr…   r]   r   r   r‰   Æ   r‡   zTestSparseArray.test_alignc                    rƒ   r   )rc   rY   Útest_align_framer…   r]   r   r   rŠ   Ê   r‡   z TestSparseArray.test_align_framec                    rƒ   r   )rc   rY   Útest_align_series_framer…   r]   r   r   r‹   Î   r‡   z'TestSparseArray.test_align_series_framec                    rƒ   r   )rc   rY   Ú
test_merger…   r]   r   r   rŒ   Ò   r‡   zTestSparseArray.test_mergec                 C   sˆ   t j|dd„ tt|ƒƒD ƒd�}t |jj¡r*t | d¡¡r't |j	d ¡s)J ‚n| d¡|j	d ks6J ‚| d¡|j	d ksBJ ‚d S )Nc                 S   s   g | ]}d | ‘qS )r   r   )rn   Úir   r   r   rp   ×   r3   z,TestSparseArray.test_get.<locals>.<listcomp>)Úindexr8   r   r
   )
r.   ÚSeriesr'   Úlenr   r   Úvaluesr   ÚgetÚiloc)r=   r   Úserr   r   r   Útest_getÖ   s
    &zTestSparseArray.test_getc                    rƒ   r   )rc   rY   Útest_reindexr…   r]   r   r   r–   Þ   r‡   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   rs   Úassert_sp_array_equalÚfillnaÚassert_equal)r=   r&   ÚsarrÚexpected_dtyperz   ry   r   r   r   Ú	test_isnaâ   s   
zTestSparseArray.test_isnac                    sH   t tf}tj|dd�� tƒ  |¡ W d   ƒ d S 1 sw   Y  d S ©NF)Úcheck_stacklevel)r   ÚFutureWarningrs   Úassert_produces_warningrY   Útest_fillna_limit_backfill)r=   r&   Úwarnsr]   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 valuerK   )	r   r   r   ÚapplymarkerrS   rT   rU   rY   Útest_fillna_no_op_returns_copy)r=   r   r   r]   r   r   r§   ô   s
   ÿz.TestSparseArray.test_fillna_no_op_returns_copyÚUnsupportedrK   c                    s   t ƒ  ¡  d S r   )rY   Útest_fillna_series©r=   r&   r]   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   )rd   r}   r—   )
r.   rq   r›   r/   r   r   r   Ú_from_sequencers   rt   )r=   r&   r   ry   r   rz   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ƒr7|r-|jj|jju s,J ‚n
|jj|jjus7J ‚|j	j
 ¡ | ¡ u sCJ ‚d S )Nr
   rd   F©Úcopy)r   r   Úblocks)Útaker.   rq   r“   r›   ÚhasattrÚ_mgrr‘   r   rd   Ú_valuesÚto_dense)r=   r&   Úusing_copy_on_writeÚarrÚdfÚ
filled_valry   r   r   r   Útest_fillna_copy_frame  s   

z&TestSparseArray.test_fillna_copy_framec                 C   sn   |  ddg¡}tj|dd�}|d }| |¡}|r"|j|ju s!J ‚n|j|jus*J ‚|j ¡ | ¡ u s5J ‚d S )Nr
   Fr­   r   )r°   r.   r�   r›   r³   r´   )r=   r&   rµ   r¶   r”   r¸   ry   r   r   r   Útest_fillna_copy_series&  s   
z'TestSparseArray.test_fillna_copy_serieszNot Applicablec                    ó   t ƒ  |¡ d S r   )rY   Útest_fillna_length_mismatchrª   r]   r   r   r¼   4  ó   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   rs   Úassert_series_equal)r=   r   r†   Úclsre   rf   r”   Úcondry   Ú	new_dtyperz   Úotherr   r   r   Útest_where_series8  s    

ÿz!TestSparseArray.test_where_seriesc                    sB   t jtdd�� tƒ  ||¡ W d   ƒ d S 1 sw   Y  d S r    )rs   r£   r   rY   Útest_searchsorted)r=   r,   Ú	as_seriesr]   r   r   rÈ   N  s   "ÿz!TestSparseArray.test_searchsortedc                 C   s6   |  d¡}|jd |jd< |jd |jd ksJ ‚d S )Nr   r
   )ÚshiftÚ_sparse_values)r=   r   ry   r   r   r   Útest_shift_0_periodsR  s   
z$TestSparseArray.test_shift_0_periodsÚmethodÚargmaxÚargminc                    s   |   |¡ tƒ  |||¡ d S r   )rc   rY   Útest_argmin_argmax_all_na)r=   rÍ   r   r†   r]   r   r   rÐ   Y  s   
z)TestSparseArray.test_argmin_argmax_all_naÚboxc                    s    |   |¡ tƒ  ||||¡ d S r   )rc   rY   Útest_equals)r=   r   r†   rÉ   rÑ   r]   r   r   rÒ   _  s   
zTestSparseArray.test_equalsc                    r»   r   )rY   Ú&test_equals_same_data_different_objectrb   r]   r   r   rÓ   e  r½   z6TestSparseArray.test_equals_same_data_different_objectzfunc, na_action, expectedc                 C   ó   | S r   r   ©ro   r   r   r   r2   l  ó    zTestSparseArray.<lambda>Ng      ð?c                 C   rÔ   r   r   rÕ   r   r   r   r2   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$   Úmaprs   Úassert_extension_array_equal)r=   ÚfuncrÙ   rz   r   ry   r   r   r   Útest_mapi  s   zTestSparseArray.test_maprÙ   c                 C   sJ   d}t jt|d�� |jdd„ |d� W d   ƒ d S 1 sw   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   r2   }  s    z1TestSparseArray.test_map_raises.<locals>.<lambda>rØ   )rS   ÚraisesÚ
ValueErrorrÚ   )r=   r   rÙ   Úmsgr   r   r   Útest_map_raisesx  s   "ÿzTestSparseArray.test_map_raiseszno sparse StringDtype)rß   rL   c                    r»   r   )rY   Útest_astype_string)r=   r   Únullable_string_dtyper]   r   r   rã     s   z"TestSparseArray.test_astype_stringc                 C   s   |j dkrt d¡ d S d S )Nr   z=Incorrected expected from Series.combine and tested elsewhere)r   rS   ra   rb   r   r   r   Ú_skip_if_different_combineŠ  s   
üz*TestSparseArray._skip_if_different_combinec                    rƒ   r   )rå   rY   Útest_arith_series_with_scalar©r=   r   Úall_arithmetic_operatorsr]   r   r   ræ   ‘  r‡   z-TestSparseArray.test_arith_series_with_scalarc                    rƒ   r   )rå   rY   Útest_arith_series_with_arrayrç   r]   r   r   ré   •  r‡   z,TestSparseArray.test_arith_series_with_arrayc                    sF   |j jdkrn| d¡dvrtjjdd�}| |¡ tƒ  ||¡ d S )Nr   r)   )ÚmulÚrmulÚfloordivÚ	rfloordivÚpowÚmodÚrmodz result dtype.fill_value mismatchrK   )	r   r   ÚstriprS   rT   rU   r¦   rY   Útest_arith_frame_with_scalar)r=   r   rè   r   rT   r]   r   r   rò   ™  s   	
z,TestSparseArray.test_arith_frame_with_scalarr”   r9   c           	      C   sþ   |}|||ƒ}t |tjƒrt |tjƒsJ ‚t |jtƒsJ ‚nt |tƒs%J ‚|jjtjks.J ‚t |tjƒrM||j	|j
j	ƒ}t|| ¡ t |¡ƒ|tjd�}nt |t |j	¡t |¡ƒ¡}t|| ¡ t |¡ƒ|tjd�}t |tjƒrwt |¡}t ||¡ d S )Nr˜   )Ú
isinstancer.   r�   r   r   r   Úsubtyper   Úbool_r   r³   r´   ri   Úallrs   rœ   )	r=   r”   r9   Úcomparison_oprÆ   Úopry   r   rz   r   r   r   Ú_compare_other©  s2   
ýÿý
zTestSparseArray._compare_otherc                 C   sP   t  |¡}|  |||d¡ |  |||d¡ |  |||d¡ |  |||tj¡ d S )Nr   r
   r7   )r.   r�   rù   r   r$   )r=   r9   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_valuerK   éüÿÿÿé   é
   )r   r   Ú__name__rS   rT   rU   r¦   r   Úlinspacer.   r�   rù   )r=   r9   r÷   r   rT   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þ   rK   r
   r   )
r   r   r  rS   rT   rU   r¦   r.   r�   rù   )r=   r9   r÷   r   rT   r”   r¶   r   r   r   Útest_sparse_arrayá  s   

z!TestSparseArray.test_sparse_arrayzDifferent reprc                    ó   t ƒ  ||¡ d S r   )rY   Útest_array_repr)r=   r   r	   r]   r   r   r  ì  r"   zTestSparseArray.test_array_reprzresult does not match expectedÚas_indexc                    r  r   )rY   Útest_groupby_extension_agg)r=   r	  r5   r]   r   r   r
  ð  s   z*TestSparseArray.test_groupby_extension_agg)Dr  Ú
__module__Ú__qualname__Ústrr™   r?   rS   rT   ÚparametrizerZ   r`   rc   r{   Úfilterwarningsr.   Ú
MultiIndexÚfrom_tuplesr‚   r„   rˆ   r‰   rŠ   r‹   rŒ   r•   r–   rŸ   r¤   r§   rU   r©   r¬   Ú_combine_le_expected_dtyper¹   rº   r¼   rÇ   rÈ   rÌ   rÐ   Úfails_arm_wheelsrÀ   r�   rq   rÒ   rÓ   r   r   r$   rÝ   râ   Ú	TypeErrorrã   Úseries_scalar_excÚframe_scalar_excÚ
divmod_excÚseries_array_excrå   ræ   ré   rò   rù   rú   r  r  r  r
  Ú__classcell__r   r   r]   r   r:   e   s¨    ÿÿþþ	üþ
	
ÿ
ÿ$r:   c                 C   s   |   ¡ tu sJ ‚d S r   )Úconstruct_array_typer   r—   r   r   r   Útest_array_type_with_argö  s   r  ) Ú__doc__Únumpyr   rS   Úpandas.errorsr   Úpandasr.   r   Úpandas._testingÚ_testingrs   Úpandas.arraysr   Úpandas.tests.extensionr   r   Úfixturer   r$   r   r!   r&   r+   r,   r-   r4   r5   r9   ÚExtensionTestsr:   r  r   r   r   r   Ú<module>   sF    






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