a
    oÝEbñ&  ã                   @   sØ  d Z ddlZddlZddlZddlZddlmZmZ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ejdd„ ƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dej ƒZ!G dd„ dej"ƒZ#G d d!„ d!ej$ƒZ%G d"d#„ d#ej&ƒZ'G d$d%„ d%ej(ƒZ)G d&d'„ d'ej*ƒZ+G d(d)„ d)ej,ƒZ-G d*d+„ d+ej.ƒZ/G d,d-„ d-ej0ƒZ1G d.d/„ d/ej2ƒZ3G d0d1„ d1ej4ƒZ5G d2d3„ d3ej6ƒZ7dS )4aj  
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)ÚCategoricalÚCategoricalIndexÚ	Timestamp©ÚCategoricalDtype)Úbasec                  C   s.   t jjttjƒdd�} | d | d kr q*q | S )Néd   )Úsizer   é   )ÚnpÚrandomÚchoiceÚlistÚstringÚascii_letters)Úvalues© r   úg/home/ja/django-apps/lartica_env/lib/python3.9/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 gbe equal
    )r   r   r   r   r   r   Údata0   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_missing:   s    r   c                   C   s   t g d¢g d¢dd�S )N)r   ÚBÚC)r   r   r   T©Ú
categoriesZordered©r   r   r   r   r   Údata_for_sorting@   s    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_sortingE   s    r!   c                   C   s   t jS r   )r   r   r   r   r   r   Úna_valueJ   s    r"   c                   C   s   t g d¢ƒS )N)Úar#   NNÚbr$   r#   Úcr   r   r   r   r   Údata_for_groupingO   s    r&   c                   @   s   e Zd ZdS )Ú	TestDtypeN©Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r'   T   s   r'   c                       s2   e Zd Zejjdd�‡ fdd„ƒZdd„ Z‡  ZS )ÚTestInterfacezMemory usage doesn't match©Úreasonc                    s   t ƒ  |¡ d S r   )ÚsuperÚtest_memory_usage©Úselfr   ©Ú	__class__r   r   r0   Y   s    zTestInterface.test_memory_usagec                 C   s€   |j j}|| ¡   }|d |v s&J ‚|d |v s6J ‚||v sBJ ‚||vsNJ ‚tjD ]&}||u rbqT||vsnJ ‚||v sTJ ‚qTd S )Nr   )r   r"   ZisnaÚtmZNULL_OBJECTS)r2   r   r   r"   Zna_value_objr   r   r   Útest_contains^   s    
zTestInterface.test_contains)	r)   r*   r+   ÚpytestÚmarkÚskipr0   r6   Ú__classcell__r   r   r3   r   r,   X   s   r,   c                   @   s   e Zd Zdd„ ZdS )ÚTestConstructorsc                 C   s:   |  ¡ }|jd|d�}t||ƒs$J ‚|jtg ƒks6J ‚d S )N)é   ©r   )Zconstruct_array_typeÚ_emptyÚ
isinstancer   r   )r2   r   ÚclsÚresultr   r   r   Ú
test_emptyx   s    zTestConstructors.test_emptyN)r)   r*   r+   rB   r   r   r   r   r;   w   s   r;   c                   @   s   e Zd ZdS )ÚTestReshapingNr(   r   r   r   r   rC   ‚   s   rC   c                       s*   e Zd Zejjdd�‡ fdd„ƒZ‡  ZS )ÚTestGetitemzBackwards compatibilityr-   c                    s   t ƒ  |¡ d S r   )r/   Útest_getitem_scalarr1   r3   r   r   rE   ‡   s    zTestGetitem.test_getitem_scalar)r)   r*   r+   r7   r8   r9   rE   r:   r   r   r3   r   rD   †   s   rD   c                   @   s   e Zd ZdS )ÚTestSetitemNr(   r   r   r   r   rF   �   s   rF   c                   @   s   e Zd ZdS )Ú	TestIndexNr(   r   r   r   r   rG   “   s   rG   c                       sD   e Zd Zejjdd�‡ fdd„ƒZejjdd�‡ fdd„ƒZ‡  ZS )ÚTestMissingzNot implementedr-   c                    s   t ƒ  |¡ d S r   )r/   Útest_fillna_limit_pad©r2   r   r3   r   r   rI   ˜   s    z!TestMissing.test_fillna_limit_padc                    s   t ƒ  |¡ d S r   )r/   Útest_fillna_limit_backfillrJ   r3   r   r   rK   œ   s    z&TestMissing.test_fillna_limit_backfill)	r)   r*   r+   r7   r8   r9   rI   rK   r:   r   r   r3   r   rH   —   s   rH   c                   @   s   e Zd ZdS )Ú
TestReduceNr(   r   r   r   r   rL   ¡   s   rL   c                       sL   e Zd Zejjdd�‡ fdd„ƒZdd„ Zejjdd�‡ fdd	„ƒZ‡  Z	S )
ÚTestMethodszUnobserved categories includedr-   c                    s   t ƒ  ||¡S r   )r/   Útest_value_counts)r2   Zall_dataZdropnar3   r   r   rN   ¦   s    zTestMethods.test_value_countsc                    s¤   |dƒ\}}t  |¡}t  |¡}| |dd„ ¡}t  dd„ tt|ƒt|ƒƒD ƒ¡}|  ||¡ |jd ‰ | ˆ dd„ ¡}t  ‡ fdd„t|ƒD ƒ¡}|  ||¡ d S )	Né   c                 S   s   | | S r   r   ©Úx1Zx2r   r   r   Ú<lambda>°   ó    z.TestMethods.test_combine_add.<locals>.<lambda>c                 S   s   g | ]\}}|| ‘qS r   r   )Ú.0r#   r$   r   r   r   Ú
<listcomp>²   rS   z0TestMethods.test_combine_add.<locals>.<listcomp>r   c                 S   s   | | S r   r   rP   r   r   r   rR   ·   rS   c                    s   g | ]}|ˆ  ‘qS r   r   )rT   r#   ©Úvalr   r   rU   ¸   rS   )ÚpdÚSeriesÚcombineÚzipr   Úassert_series_equalZiloc)r2   Zdata_repeatedZ
orig_data1Z
orig_data2Ús1Ús2rA   Úexpectedr   rV   r   Útest_combine_addª   s    

ÿ
zTestMethods.test_combine_addzNot Applicablec                    s   t ƒ  |¡ d S r   )r/   Útest_fillna_length_mismatchrJ   r3   r   r   ra   »   s    z'TestMethods.test_fillna_length_mismatch)
r)   r*   r+   r7   r8   r9   rN   r`   ra   r:   r   r   r3   r   rM   ¥   s
   rM   c                   @   s  e Zd Zej deeg¡ej ddej	ge
dƒejgg¡dd„ ƒƒZej dejdd	gd
d�ejddgdd�eje d¡e d	¡gdd�eje dd¡e dd¡gdd�ejdej	gdd�g¡dd„ ƒZej ddejdgdd�fde e
ddd�g¡jfg¡dd„ ƒZdS )ÚTestCastingr@   r   r
   Ú2000c                 C   sL   ||ƒ}d}t jttf|d�� | t¡ W d   ƒ n1 s>0    Y  d S )NzCannot (cast|convert)©Úmatch)r7   ÚraisesÚ
ValueErrorÚ	TypeErrorÚastypeÚint)r2   r@   r   ÚsÚmsgr   r   r   Útest_cast_nan_to_intÁ   s    z TestCasting.test_cast_nan_to_intr_   Ú2019Ú2020zdatetime64[ns, UTC]r=   r   ztimedelta64[ns]zperiod[A-DEC]rO   ÚintervalZInt64c                 C   s"   |  d¡  |j¡}t ||¡ d S )NÚcategory)ri   r   r5   r\   )r2   r_   rA   r   r   r   Ú%test_cast_category_to_extension_dtypeË   s    z1TestCasting.test_cast_category_to_extension_dtypezdtype, expectedzdatetime64[ns]z2015-01-01T00:00:00.000000000zdatetime64[ns, MET]z2015-01-01 00:00:00+0100ZMET)Útzc                 C   s    t dgƒ |¡}||ksJ ‚d S )Nz
2015-01-01)r   ri   )r2   r   r_   rA   r   r   r   Útest_consistent_castingÛ   s    z#TestCasting.test_consistent_castingN)r)   r*   r+   r7   r8   Úparametrizer   r   r   r   r   rX   ZNaTrm   rY   ZPeriodZIntervalrr   ÚarrayZDatetimeIndexrt   r   r   r   r   rb   À   s4     ûþ

þÿþûþrb   c                       sH   e Zd Z‡ fdd„Z‡ fdd„Zdd„ Zdd„ Zef‡ fd	d
„	Z‡  Z	S )ÚTestArithmeticOpsc                    s4   |}|dkr"|j  tjjdd�¡ tƒ  ||¡ d S ©NÚ__rmod__z/rmod never called when string is first argumentr-   )ÚnodeÚ
add_markerr7   r8   Úxfailr/   Útest_arith_frame_with_scalar©r2   r   Zall_arithmetic_operatorsÚrequestÚop_namer3   r   r   r}   ñ   s    ÿÿz.TestArithmeticOps.test_arith_frame_with_scalarc                    s4   |}|dkr"|j  tjjdd�¡ tƒ  ||¡ d S rx   )rz   r{   r7   r8   r|   r/   Útest_arith_series_with_scalarr~   r3   r   r   r�   ü   s    ÿÿz/TestArithmeticOps.test_arith_series_with_scalarc                 C   sD   t  |¡}tjtdd�� ||  W d   ƒ n1 s60    Y  d S )Nz"cannot perform|unsupported operandrd   )rX   rY   r7   rf   rh   )r2   r   Zserr   r   r   Ú$test_add_series_with_extension_array  s    
z6TestArithmeticOps.test_add_series_with_extension_arrayc                 C   s   d S r   r   )r2   r   r   r   Útest_divmod_series_array  s    z*TestArithmeticOps.test_divmod_series_arrayc                    s   t ƒ j|||td�S )N)Úexc)r/   Ú_check_divmod_oprh   )r2   rk   ÚopÚotherr„   r3   r   r   r…     s    z"TestArithmeticOps._check_divmod_op)
r)   r*   r+   r}   r�   r‚   rƒ   ÚNotImplementedErrorr…   r:   r   r   r3   r   rw   ð   s
   
rw   c                   @   sD   e Zd Zdd„ Zej dddgddgedƒed	ƒgg¡d
d„ ƒZdS )ÚTestComparisonOpsc           	      C   s¶   d|j › d�}|dkrB|||ƒ}| |dd„ ¡}||k ¡ s²J ‚np|dkrv|||ƒ}| |dd„ ¡}||k ¡ s²J ‚n<d}tjt|d�� |||ƒ W d   ƒ n1 s¨0    Y  d S )	NÚ__Ú__eq__c                 S   s   | |kS r   r   ©ÚxÚyr   r   r   rR     rS   z2TestComparisonOps._compare_other.<locals>.<lambda>Ú__ne__c                 S   s   | |kS r   r   rŒ   r   r   r   rR     rS   z7Unordered Categoricals can only compare equality or notrd   )r)   rZ   Úallr7   rf   rh   )	r2   rk   r   r†   r‡   r€   rA   r_   rl   r   r   r   Ú_compare_other  s    

z TestComparisonOps._compare_otherr   r#   r$   r   r
   rn   ro   c                 C   s<   t jddg|d�}t jddg|d�}||k}| ¡ s8J ‚d S )Néÿÿÿÿr   )r   r
   )r   Z
from_codesr�   )r2   r   Úc1Úc2rA   r   r   r   Útest_not_equal_with_na&  s    z(TestComparisonOps.test_not_equal_with_naN)	r)   r*   r+   r‘   r7   r8   ru   r   r•   r   r   r   r   r‰     s   þr‰   c                   @   s   e Zd ZdS )ÚTestParsingNr(   r   r   r   r   r–   4  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sDJ ‚d S )Nr
   r’   z
Categories)ÚreprZreshapeÚcount)r2   r   Úresr   r   r   Útest_repr_2d9  s    zTest2DCompat.test_repr_2dN)r)   r*   r+   r›   r   r   r   r   r—   8  s   r—   )8Ú__doc__r   Únumpyr   r7   ZpandasrX   r   r   r   Zpandas._testingZ_testingr5   Zpandas.api.typesr   Zpandas.tests.extensionr   r   Zfixturer   r   r   r    r!   r"   r&   ZBaseDtypeTestsr'   ZBaseInterfaceTestsr,   ZBaseConstructorsTestsr;   ZBaseReshapingTestsrC   ZBaseGetitemTestsrD   ZBaseSetitemTestsrF   ZBaseIndexTestsrG   ZBaseMissingTestsrH   ZBaseNoReduceTestsrL   ZBaseMethodsTestsrM   ZBaseCastingTestsrb   ZBaseArithmeticOpsTestsrw   ZBaseComparisonOpsTestsr‰   ZBaseParsingTestsr–   ZNDArrayBacked2DTestsr—   r   r   r   r   Ú<module>   sL   

	




	
0$ 