U
    `»{j%  ã                   @   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   úf/var/www/html/bwave/python/venv/lib/python3.8/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   Ú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 dddgdddgdd�S )Nr   ÚBÚCT©Ú
categoriesÚordered©r   r   r   r   r   Údata_for_sorting@   s    r!   c                   C   s   t dd dgddgdd�S )Nr   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 ddd d ddddgƒS )NÚaÚbÚ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   r1   Y   s    zTestInterface.test_memory_usagec                 C   s€   |j j}|| ¡   }|d |ks&t‚|d |ks6t‚||ksBt‚||ksNt‚tjD ]&}||krbqT||ksnt‚||ksTt‚qTd S )Nr   )r   r#   ZisnaÚAssertionErrorÚtmZNULL_OBJECTS)r3   r   r   r#   Zna_value_objr   r   r   Útest_contains^   s    
zTestInterface.test_contains)	r*   r+   r,   ÚpytestÚmarkÚxfailr1   r8   Ú__classcell__r   r   r4   r   r-   X   s   r-   c                   @   s   e Zd Zdd„ ZdS )ÚTestConstructorsc                 C   s:   |  ¡ }|jd|d�}t||ƒs$t‚|jtg ƒks6t‚d S )N)é   ©r   )Zconstruct_array_typeÚ_emptyÚ
isinstancer6   r   r   )r3   r   ÚclsÚresultr   r   r   Ú
test_emptyx   s    zTestConstructors.test_emptyN)r*   r+   r,   rD   r   r   r   r   r=   w   s   r=   c                   @   s   e Zd ZdS )ÚTestReshapingNr)   r   r   r   r   rE   ‚   s   rE   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   )r0   Útest_getitem_scalarr2   r4   r   r   rG   ‡   s    zTestGetitem.test_getitem_scalar)r*   r+   r,   r9   r:   ÚskiprG   r<   r   r   r4   r   rF   †   s   rF   c                   @   s   e Zd ZdS )ÚTestSetitemNr)   r   r   r   r   rI   �   s   rI   c                   @   s   e Zd ZdS )Ú	TestIndexNr)   r   r   r   r   rJ   “   s   rJ   c                   @   s   e Zd ZdS )ÚTestMissingNr)   r   r   r   r   rK   —   s   rK   c                   @   s   e Zd ZdS )Ú
TestReduceNr)   r   r   r   r   rL   ›   s   rL   c                       s2   e Zd Zejjdd�‡ fdd„ƒZdd„ Z‡  ZS )ÚTestMethodszUnobserved categories includedr.   c                    s   t ƒ  ||¡S r   )r0   Útest_value_counts)r3   Zall_dataZdropnar4   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>¬   s     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   ²   s     )ÚpdÚSeriesÚcombineÚzipr   Úassert_series_equalZiloc)r3   Zdata_repeatedZ
orig_data1Z
orig_data2Ús1Ús2rC   Úexpectedr   rV   r   Útest_combine_add¤   s    

ÿ
zTestMethods.test_combine_add)	r*   r+   r,   r9   r:   r;   rN   r`   r<   r   r   r4   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 )ÚTestCastingrB   r   r
   Ú2000c              	   C   s8   ||ƒ}d}t jttf|d�� | t¡ W 5 Q R X d S )NzCannot (cast|convert)©Úmatch)r9   ÚraisesÚ
ValueErrorÚ	TypeErrorÚastypeÚint)r3   rB   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)rh   r   r7   r\   )r3   r_   rC   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t‚d S )Nz
2015-01-01)r   rh   r6   )r3   r   r_   rC   r   r   r   Útest_consistent_castingÑ   s    z#TestCasting.test_consistent_castingN)r*   r+   r,   r9   r:   Úparametrizer   r   r   r   r   rX   ZNaTrl   rY   ZPeriodZIntervalrq   ÚarrayZDatetimeIndexrs   r   r   r   r   ra   ¶   s4     ûþ

þÿþûþra   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_markerr9   r:   r;   r0   Útest_arith_frame_with_scalar©r3   r   Zall_arithmetic_operatorsÚrequestÚop_namer4   r   r   r{   ç   s    ÿÿz.TestArithmeticOps.test_arith_frame_with_scalarc                    s4   |}|dkr"|j  tjjdd�¡ tƒ  ||¡ d S rw   )ry   rz   r9   r:   r;   r0   Útest_arith_series_with_scalarr|   r4   r   r   r   ò   s    ÿÿz/TestArithmeticOps.test_arith_series_with_scalarc              	   C   s0   t  |¡}tjtdd�� ||  W 5 Q R X d S )Nz"cannot perform|unsupported operandrc   )rX   rY   r9   re   rg   )r3   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   )r3   r   r   r   Útest_divmod_series_array  s    z*TestArithmeticOps.test_divmod_series_arrayc                    s   t ƒ j|||td�S )N)Úexc)r0   Ú_check_divmod_oprg   )r3   rj   ÚopÚotherr‚   r4   r   r   rƒ     s    z"TestArithmeticOps._check_divmod_op)
r*   r+   r,   r{   r   r€   r�   ÚNotImplementedErrorrƒ   r<   r   r   r4   r   rv   æ   s
   
rv   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žt‚n\|dkrv|||ƒ}| |dd„ ¡}||k ¡ sžt‚n(d}tjt|d�� |||ƒ W 5 Q R X 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 notrc   )r*   rZ   Úallr6   r9   re   rg   )	r3   rj   r   r„   r…   r~   rC   r_   rk   r   r   r   Ú_compare_other  s    

z TestComparisonOps._compare_otherr   r$   r%   r   r
   rm   rn   c                 C   s<   t jddg|d�}t jddg|d�}||k}| ¡ s8t‚d S )Néÿÿÿÿr   )r   r
   )r   Z
from_codesrŽ   r6   )r3   r   Úc1Úc2rC   r   r   r   Útest_not_equal_with_na  s    z(TestComparisonOps.test_not_equal_with_naN)	r*   r+   r,   r�   r9   r:   rt   r   r“   r   r   r   r   r‡   
  s   þr‡   c                   @   s   e Zd ZdS )ÚTestParsingNr)   r   r   r   r   r”   *  s   r”   c                   @   s   e Zd Zdd„ ZdS )ÚTest2DCompatc                 C   sH   t | dd¡ƒ}| d¡dks"t‚t | dd¡ƒ}| d¡dksDt‚d S )Nr
   r�   z
Categories)ÚreprZreshapeÚcountr6   )r3   r   Úresr   r   r   Útest_repr_2d/  s    zTest2DCompat.test_repr_2dN)r*   r+   r,   r™   r   r   r   r   r•   .  s   r•   )8Ú__doc__r   Únumpyr   r9   ZpandasrX   r   r   r   Zpandas._testingZ_testingr7   Zpandas.api.typesr   Zpandas.tests.extensionr   r   Zfixturer   r   r   r!   r"   r#   r'   ZBaseDtypeTestsr(   ZBaseInterfaceTestsr-   ZBaseConstructorsTestsr=   ZBaseReshapingTestsrE   ZBaseGetitemTestsrF   ZBaseSetitemTestsrI   ZBaseIndexTestsrJ   ZBaseMissingTestsrK   ZBaseNoReduceTestsrL   ZBaseMethodsTestsrM   ZBaseCastingTestsra   ZBaseArithmeticOpsTestsrv   ZBaseComparisonOpsTestsr‡   ZBaseParsingTestsr”   ZNDArrayBacked2DTestsr•   r   r   r   r   Ú<module>   sL   

	




	0$ 