U
    ¾mœdã%  ã                   @   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ƒZ7G d4d5„ d5ej8ƒZ9dS )6aj  
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   ú`/home/sam/Atlas/atlas_env/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©Ú
categoriesZ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   r0   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)r2   r   r   r"   Zna_value_objr   r   r   Útest_contains^   s    
zTestInterface.test_contains)	r)   r*   r+   ÚpytestÚmarkÚxfailr0   r7   Ú__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$t‚|jtg ƒks6t‚d S )N)é   ©r   )Zconstruct_array_typeÚ_emptyÚ
isinstancer5   r   r   )r2   r   ÚclsÚresultr   r   r   Ú
test_emptyx   s    zTestConstructors.test_emptyN)r)   r*   r+   rC   r   r   r   r   r<   w   s   r<   c                   @   s   e Zd ZdS )ÚTestReshapingNr(   r   r   r   r   rD   ‚   s   rD   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   rF   ‡   s    zTestGetitem.test_getitem_scalar)r)   r*   r+   r8   r9   ÚskiprF   r;   r   r   r3   r   rE   †   s   rE   c                   @   s   e Zd ZdS )ÚTestSetitemNr(   r   r   r   r   rH   �   s   rH   c                   @   s   e Zd ZdS )Ú	TestIndexNr(   r   r   r   r   rI   “   s   rI   c                   @   s   e Zd ZdS )ÚTestMissingNr(   r   r   r   r   rJ   —   s   rJ   c                   @   s   e Zd ZdS )Ú
TestReduceNr(   r   r   r   r   rK   ›   s   rK   c                   @   s&   e Zd Zej dddg¡dd„ ƒZdS )ÚTestAccumulateÚskipnaTFc                 C   s   d S r   r   )r2   r   Zall_numeric_accumulationsrM   r   r   r   Útest_accumulate_series    s    z%TestAccumulate.test_accumulate_seriesN)r)   r*   r+   r8   r9   ÚparametrizerN   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   )r/   Útest_value_counts)r2   Zall_dataZdropnar3   r   r   rQ   ¦   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   rS   r   r   r   rU   ·   rV   c                    s   g | ]}|ˆ  ‘qS r   r   )rW   r#   ©Úvalr   r   rX   ¸   s     )ÚpdÚSeriesÚcombineÚzipr   Úassert_series_equalZiloc)r2   Zdata_repeatedZ
orig_data1Z
orig_data2Ús1Ús2rB   Úexpectedr   rY   r   Útest_combine_addª   s    

ÿ
zTestMethods.test_combine_add)	r)   r*   r+   r8   r9   r:   rQ   rc   r;   r   r   r3   r   rP   ¥   s   rP   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 )ÚTestCastingrA   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)r8   ÚraisesÚ
ValueErrorÚ	TypeErrorÚastypeÚint)r2   rA   r   ÚsÚmsgr   r   r   Útest_cast_nan_to_int½   s    z TestCasting.test_cast_nan_to_intrb   Ú2019Ú2020zdatetime64[ns, UTC]r>   r   ztimedelta64[ns]zperiod[A-DEC]rR   ÚintervalZInt64c                 C   s"   |  d¡  |j¡}t ||¡ d S )NÚcategory)rk   r   r6   r_   )r2   rb   rB   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   rk   r5   )r2   r   rb   rB   r   r   r   Útest_consistent_casting×   s    z#TestCasting.test_consistent_castingN)r)   r*   r+   r8   r9   rO   r   r   r   r   r   r[   ZNaTro   r\   ZPeriodZIntervalrt   ÚarrayZDatetimeIndexrv   r   r   r   r   rd   ¼   s4     ûþ

þÿþûþrd   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_markerr8   r9   r:   r/   Ú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 ry   )r{   r|   r8   r9   r:   r/   Útest_arith_series_with_scalarr~   r3   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 operandrf   )r[   r\   r8   rh   rj   )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_oprj   )r2   rm   Ú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   rx   ì   s
   
rx   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   rU     rV   z2TestComparisonOps._compare_other.<locals>.<lambda>Ú__ne__c                 S   s   | |kS r   r   rŒ   r   r   r   rU     rV   z7Unordered Categoricals can only compare equality or notrf   )r)   r]   Úallr5   r8   rh   rj   )	r2   rm   r   r†   r‡   r€   rB   rb   rn   r   r   r   Ú_compare_other  s    

z TestComparisonOps._compare_otherr   r#   r$   r   r
   rp   rq   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�   r5   )r2   r   Úc1Úc2rB   r   r   r   Útest_not_equal_with_na"  s    z(TestComparisonOps.test_not_equal_with_naN)	r)   r*   r+   r‘   r8   r9   rO   r   r•   r   r   r   r   r‰     s   þr‰   c                   @   s   e Zd ZdS )ÚTestParsingNr(   r   r   r   r   r–   0  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Úcountr5   )r2   r   Úresr   r   r   Útest_repr_2d5  s    zTest2DCompat.test_repr_2dN)r)   r*   r+   r›   r   r   r   r   r—   4  s   r—   ):Ú__doc__r   Únumpyr   r8   Zpandasr[   r   r   r   Zpandas._testingZ_testingr6   Zpandas.api.typesr   Zpandas.tests.extensionr   r   Zfixturer   r   r   r    r!   r"   r&   ZBaseDtypeTestsr'   ZBaseInterfaceTestsr,   ZBaseConstructorsTestsr<   ZBaseReshapingTestsrD   ZBaseGetitemTestsrE   ZBaseSetitemTestsrH   ZBaseIndexTestsrI   ZBaseMissingTestsrJ   ZBaseNoReduceTestsrK   ZBaseAccumulateTestsrL   ZBaseMethodsTestsrP   ZBaseCastingTestsrd   ZBaseArithmeticOpsTestsrx   ZBaseComparisonOpsTestsr‰   ZBaseParsingTestsr–   ZNDArrayBacked2DTestsr—   r   r   r   r   Ú<module>   sN   

	




	0$ 