B
    Y0df%                 @   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Z3dS )0aj  
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   s2   x,t jjttjdd} | d | d krP qW | S )Nd   )sizer      )nprandomchoiceliststringascii_letters)values r   Y/var/www/html/venv/lib/python3.7/site-packages/pandas/tests/extension/test_categorical.py	make_data    s
    r   c               C   s   t  S )N)r   r   r   r   r   dtype+   s    r   c               C   s
   t t S )zLength-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 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   T)r   r   )r   r   r   r   r   data_missing_for_sortingE   s    r   c               C   s   t jS )N)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c)r   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 )N)supertest_memory_usage)selfr   )	__class__r   r   r+   Y   s    zTestInterface.test_memory_usagec             C   s   |j j}||   }|d |ks&t|d |ks6t||ksBt||ksNtx0tjD ]&}||krdqV||kspt||ksVtqVW d S )Nr   )r   r   ZisnaAssertionErrortmZNULL_OBJECTS)r,   r   r   r   Zna_value_objr   r   r   test_contains^   s    zTestInterface.test_contains)	r%   r&   r'   pytestmarkskipr+   r0   __classcell__r   r   )r-   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
isinstancer.   r   r   )r,   r   clsresultr   r   r   
test_emptyx   s    zTestConstructors.test_emptyN)r%   r&   r'   r;   r   r   r   r   r5   w   s   r5   c               @   s   e Zd ZdS )TestReshapingN)r%   r&   r'   r   r   r   r   r<      s   r<   c                   s*   e Zd Zejjdd fddZ  ZS )TestGetitemzBackwards compatibility)r)   c                s   t  | d S )N)r*   test_getitem_scalar)r,   r   )r-   r   r   r>      s    zTestGetitem.test_getitem_scalar)r%   r&   r'   r1   r2   r3   r>   r4   r   r   )r-   r   r=      s   r=   c               @   s   e Zd ZdS )TestSetitemN)r%   r&   r'   r   r   r   r   r?      s   r?   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 implemented)r)   c                s   t  | d S )N)r*   test_fillna_limit_pad)r,   r   )r-   r   r   rA      s    z!TestMissing.test_fillna_limit_padc                s   t  | d S )N)r*   test_fillna_limit_backfill)r,   r   )r-   r   r   rB      s    z&TestMissing.test_fillna_limit_backfill)	r%   r&   r'   r1   r2   r3   rA   rB   r4   r   r   )r-   r   r@      s   r@   c               @   s   e Zd ZdS )
TestReduceN)r%   r&   r'   r   r   r   r   rC      s   rC   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 included)r)   c                s   t  ||S )N)r*   test_value_counts)r,   Zall_dataZdropna)r-   r   r   rE      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 )Nr   )x1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 )Nr   )rG   rH   r   r   r   rI      rJ   c                s   g | ]}|  qS r   r   )rK   r    )valr   r   rL      s    )pdSeriescombinezipr   assert_series_equalZiloc)r,   Zdata_repeatedZ
orig_data1Z
orig_data2s1s2r:   expectedr   )rM   r   test_combine_add   s    


zTestMethods.test_combine_addzNot Applicablec                s   t  | d S )N)r*   test_fillna_length_mismatch)r,   r   )r-   r   r   rW      s    z'TestMethods.test_fillna_length_mismatch)
r%   r&   r'   r1   r2   r3   rE   rV   rW   r4   r   r   )r-   r   rD      s   rD   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 )TestCastingr9   r   r	   2000c          	   C   s8   ||}d}t jttf|d |t W d Q R X d S )NzCannot (cast|convert))match)r1   raises
ValueError	TypeErrorastypeint)r,   r9   r   smsgr   r   r   test_cast_nan_to_int   s    z TestCasting.test_cast_nan_to_intrU   20192020zdatetime64[ns, UTC])r   r   ztimedelta64[ns]zperiod[A-DEC]rF   intervalZInt64c             C   s"   | d |j}t|| d S )Ncategory)r^   r   r/   rR   )r,   rU   r:   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   r^   r.   )r,   r   rU   r:   r   r   r   test_consistent_casting   s    z#TestCasting.test_consistent_castingN)r%   r&   r'   r1   r2   parametrizer   r   r
   r   r   rN   ZNaTrb   rO   ZPeriodZIntervalrg   arrayZDatetimeIndexri   r   r   r   r   rX      s    ,	  	rX   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 argument)r)   )node
add_markerr1   r2   xfailr*   test_arith_frame_with_scalar)r,   r   all_arithmetic_operatorsrequestop_name)r-   r   r   rq      s    
z.TestArithmeticOps.test_arith_frame_with_scalarc                s4   |}|dkr"|j tjjdd t || d S )Nrm   z/rmod never called when string is first argument)r)   )rn   ro   r1   r2   rp   r*   test_arith_series_with_scalar)r,   r   rr   rs   rt   )r-   r   r   ru      s    
z/TestArithmeticOps.test_arith_series_with_scalarc          	   C   s0   t |}tjtdd ||  W d Q R X d S )Nz"cannot perform|unsupported operand)rZ   )rN   rO   r1   r[   r]   )r,   r   Zserr   r   r   $test_add_series_with_extension_array  s    
z6TestArithmeticOps.test_add_series_with_extension_arrayc             C   s   d S )Nr   )r,   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_opr]   )r,   r`   opotherrx   )r-   r   r   ry     s    z"TestArithmeticOps._check_divmod_op)
r%   r&   r'   rq   ru   rv   rw   NotImplementedErrorry   r4   r   r   )r-   r   rl      s
   
rl   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kr>|||}||dd }||k stn\|dkrr|||}||dd }||k stn(d}tjt|d ||| W d Q R X d S )N__eq__c             S   s   | |kS )Nr   )xyr   r   r   rI     rJ   z2TestComparisonOps._compare_other.<locals>.<lambda>__ne__c             S   s   | |kS )Nr   )r   r   r   r   r   rI     rJ   z7Unordered Categoricals can only compare equality or not)rZ   )Zget_op_from_namerP   allr.   r1   r[   r]   )	r,   r`   r   rt   r{   rz   r:   rU   ra   r   r   r   _compare_other  s    


z TestComparisonOps._compare_otherr   r    r!   r   r	   rc   rd   c             C   s<   t jddg|d}t jddg|d}||k}| s8td S )Nr   )r   r	   )r   Z
from_codesr   r.   )r,   r   c1c2r:   r   r   r   test_not_equal_with_na"  s    z(TestComparisonOps.test_not_equal_with_naN)	r%   r&   r'   r   r1   r2   rj   r   r   r   r   r   r   r}     s   r}   c               @   s   e Zd ZdS )TestParsingN)r%   r&   r'   r   r   r   r   r   0  s   r   )4__doc__r   numpyr
   r1   ZpandasrN   r   r   r   Zpandas._testingZ_testingr/   Zpandas.api.typesr   Zpandas.tests.extensionr   r   Zfixturer   r   r   r   r   r   r#   ZBaseDtypeTestsr$   ZBaseInterfaceTestsr(   ZBaseConstructorsTestsr5   ZBaseReshapingTestsr<   ZBaseGetitemTestsr=   ZBaseSetitemTestsr?   ZBaseMissingTestsr@   ZBaseNoReduceTestsrC   ZBaseMethodsTestsrD   ZBaseCastingTestsrX   ZBaseArithmeticOpsTestsrl   ZBaseComparisonOpsTestsr}   ZBaseParsingTestsr   r   r   r   r   <module>   s:   
	
0$ 