o
    Û­jœ  ã                   @   sä   d Z ddl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d„ ƒZejdd„ ƒZejdd„ ƒZejdd„ ƒZejdd„ ƒZG dd„ dejƒZG dd„ dejƒ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)Úusing_string_dtype©ÚCategorical©ÚCategoricalDtype)Úbasec                  C   s6   	 t j d¡jttjƒdd�} | d | d kr	 | S q)NTé   éd   )Úsizer   é   )ÚnpÚrandomÚdefault_rngÚchoiceÚlistÚstringÚascii_letters)Úvalues© r   úd/var/www/html/CropPilot/venv/lib/python3.10/site-packages/pandas/tests/extension/test_categorical.pyÚ	make_data   s   ùr   c                   C   s   t ƒ S ©Nr   r   r   r   r   Údtype)   s   r   c                   C   s
   t tƒ ƒS )zˆLength-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   r   Údata.   s   
r   c                   C   s   t tjdgƒS )zLength 2 array with [NA, Valid]ÚA)r   r   Únanr   r   r   r   Údata_missing8   s   r   c                   C   s   t g d¢g d¢dd�S )N)r   ÚBÚC)r   r   r   T©Ú
categoriesÚorderedr   r   r   r   r   Údata_for_sorting>   ó   r"   c                   C   s   t g d¢ddgdd�S )N)r   Nr   r   r   Tr   r   r   r   r   r   Údata_missing_for_sortingC   r#   r$   c                   C   s   t g d¢ƒS )N)Úar%   NNÚbr&   r%   Úcr   r   r   r   r   Údata_for_groupingH   s   r(   c                       s  e Zd Zejjdd�‡ fdd„ƒZdd„ Zdd„ Zejj	d	d�‡ fd
d„ƒZ
ejjdd�‡ fdd„ƒZdd„ Zej dddg¡dd„ ƒZ‡ fdd„Z‡ fdd„Zdejf‡ fdd„Zejjdd�ej ddd g¡‡ fd!d"„ƒƒZejjd#d�ej d$d%d&g¡‡ fd'd(„ƒƒZ‡  ZS ))ÚTestCategoricalzMemory usage doesn't match©Úreasonc                    ó   t ƒ  |¡ d S r   )ÚsuperÚtest_memory_usage©Úselfr   ©Ú	__class__r   r   r.   N   s   z!TestCategorical.test_memory_usagec                 C   s†   |j j}|| ¡   }|d |v sJ ‚|d |v sJ ‚||v s!J ‚||vs'J ‚tjD ]}||u r1q*||vs7J ‚tƒ s@||v s@J ‚q*d S )Nr   )r   Úna_valueÚisnaÚtmÚNULL_OBJECTSr   )r0   r   r   r3   Úna_value_objr   r   r   Útest_containsS   s   
€úzTestCategorical.test_containsc                 C   s:   |  ¡ }|jd|d�}t||ƒsJ ‚|jtg ƒksJ ‚d S )N)é   )r   )Úconstruct_array_typeÚ_emptyÚ
isinstancer   r   )r0   r   ÚclsÚresultr   r   r   Ú
test_emptym   s   zTestCategorical.test_emptyzBackwards compatibilityc                    r,   r   )r-   Útest_getitem_scalarr/   r1   r   r   r@   v   s   z#TestCategorical.test_getitem_scalarzUnobserved categories includedc                    s   t ƒ  ||¡S r   )r-   Útest_value_counts)r0   Úall_dataÚdropnar1   r   r   rA   }   s   z!TestCategorical.test_value_countsc                    s¤   |dƒ\}}t  |¡}t  |¡}| |dd„ ¡}t  dd„ tt|ƒt|ƒƒD ƒ¡}t ||¡ |jd ‰ | ˆ dd„ ¡}t  ‡ fdd„t|ƒD ƒ¡}t ||¡ d S )	Nr   c                 S   ó   | | S r   r   ©Úx1Úx2r   r   r   Ú<lambda>‡   ó    z2TestCategorical.test_combine_add.<locals>.<lambda>c                 S   s   g | ]\}}|| ‘qS r   r   )Ú.0r%   r&   r   r   r   Ú
<listcomp>‰   s    z4TestCategorical.test_combine_add.<locals>.<listcomp>r   c                 S   rD   r   r   rE   r   r   r   rH   Ž   rI   c                    s   g | ]}|ˆ  ‘qS r   r   )rJ   r%   ©Úvalr   r   rK   �   s    )ÚpdÚSeriesÚcombineÚzipr   r5   Úassert_series_equalÚiloc)r0   Údata_repeatedÚ
orig_data1Ú
orig_data2Ús1Ús2r>   Úexpectedr   rL   r   Útest_combine_add�   s   

ÿ
z TestCategorical.test_combine_addÚ	na_actionNÚignorec                 C   s"   |j dd„ |d�}t ||¡ d S )Nc                 S   s   | S r   r   )Úxr   r   r   rH   ”   s    z*TestCategorical.test_map.<locals>.<lambda>)r[   )Úmapr5   Úassert_extension_array_equal)r0   r   r[   r>   r   r   r   Útest_map’   s   zTestCategorical.test_mapc                    ó2   |}|dkr|  tjjdd�¡ tƒ  ||¡ d S ©NÚ__rmod__z/rmod never called when string is first argumentr*   )ÚapplymarkerÚpytestÚmarkÚxfailr-   Útest_arith_frame_with_scalar©r0   r   Úall_arithmetic_operatorsÚrequestÚop_namer1   r   r   rh   —   s   ÿÿz,TestCategorical.test_arith_frame_with_scalarc                    ra   rb   )rd   re   rf   rg   r-   Útest_arith_series_with_scalarri   r1   r   r   rm   ¢   s   ÿÿz-TestCategorical.test_arith_series_with_scalarÚserc                    sj   d|j › d�}|dvr,d}tjt|d�� |||ƒ W d   ƒ d S 1 s%w   Y  d S tƒ  ||||¡S )NÚ__)Ú__eq__Ú__ne__z7Unordered Categoricals can only compare equality or not)Úmatch)Ú__name__re   ÚraisesÚ	TypeErrorr-   Ú_compare_other)r0   rn   r   ÚopÚotherrl   Úmsgr1   r   r   rv   ¬   s   "ÿzTestCategorical._compare_otherzCategorical overrides __repr__r
   ÚbigÚsmallc                    ó   t ƒ  ||¡ d S r   )r-   Útest_array_repr)r0   r   r
   r1   r   r   r}   µ   ó   zTestCategorical.test_array_reprÚTBDÚas_indexTFc                    r|   r   )r-   Útest_groupby_extension_agg)r0   r€   r(   r1   r   r   r�   º   r~   z*TestCategorical.test_groupby_extension_agg)rs   Ú
__module__Ú__qualname__re   rf   rg   r.   r8   r?   Úskipr@   rA   rZ   Úparametrizer`   rh   rm   rN   rO   rv   r}   r�   Ú__classcell__r   r   r1   r   r)   M   s*    	

	r)   c                   @   s   e Zd Zdd„ ZdS )ÚTest2DCompatc                 C   sH   t | dd¡ƒ}| d¡dksJ ‚t | dd¡ƒ}| d¡dks"J ‚d S )Nr   éÿÿÿÿz
Categories)ÚreprÚreshapeÚcount)r0   r   Úresr   r   r   Útest_repr_2dÁ   s   zTest2DCompat.test_repr_2dN)rs   r‚   rƒ   r�   r   r   r   r   r‡   À   s    r‡   )Ú__doc__r   Únumpyr   re   Úpandas._configr   ÚpandasrN   r   Úpandas._testingÚ_testingr5   Úpandas.api.typesr   Úpandas.tests.extensionr   r   Úfixturer   r   r   r"   r$   r(   ÚExtensionTestsr)   ÚNDArrayBacked2DTestsr‡   r   r   r   r   Ú<module>   s2    

	



s